Slides from my talk at the GTA-PHP Meetup Group about getting mixed HTML / PHP code into objects using SOLID principles.
Meetup page: http://www.meetup.com/GTA-PHP-User-Group-Toronto/events/230656470/
Code is on github: https://github.com/zymsys/solid
Slides from the GTA-PHP meetup about the new features in PHP 7. Slides had corresponding RFC pages linked to them in the speaker notes, but they don't seem to correspond to pages here so I've made the original keynote file available at http://gtaphp.org/presentations/NewInPHP7.zip and a PowerPoint version at http://gtaphp.org/presentations/NewInPHP7.pptx.
Go beyond the documentation and explore some of what's possible if you stretch symfony to its limits. We will look at a number of aspects of symfony 1.4 and Doctrine 1.2 and tease out some powerful functionality you may not have expected to find, but will doubtless be able to use. Topics covered will include routing, forms, the config cache and record listeners. If you're comfortable in symfony and wondering what's next, this session is for you.
November Camp - Spec BDD with PHPSpec 2Kacper Gunia
My slides on PHPSpec 2 from Symfony November Camp Stockholm.
www.symfony.se/november-camp/
More Domain-Driven Design related content at: https://domaincentric.net/
All projects start with a lot of enthusiasm. As many projects grow the technical debt gets bigger and the enthusiasm gets less. Almost any developer can develop a great project, but the key is maintaining an ever evolving application with minimal technical debt without loosing enthusiasm.
During this talk you will be taken on the journey of application design. The starting point is an application that looks fine but contains lots of potential pitfalls. We will address the problems and solve them with beautiful design. We end up with testable, nicely separated software with a clear intention.
Slides from the GTA-PHP meetup about the new features in PHP 7. Slides had corresponding RFC pages linked to them in the speaker notes, but they don't seem to correspond to pages here so I've made the original keynote file available at http://gtaphp.org/presentations/NewInPHP7.zip and a PowerPoint version at http://gtaphp.org/presentations/NewInPHP7.pptx.
Go beyond the documentation and explore some of what's possible if you stretch symfony to its limits. We will look at a number of aspects of symfony 1.4 and Doctrine 1.2 and tease out some powerful functionality you may not have expected to find, but will doubtless be able to use. Topics covered will include routing, forms, the config cache and record listeners. If you're comfortable in symfony and wondering what's next, this session is for you.
November Camp - Spec BDD with PHPSpec 2Kacper Gunia
My slides on PHPSpec 2 from Symfony November Camp Stockholm.
www.symfony.se/november-camp/
More Domain-Driven Design related content at: https://domaincentric.net/
All projects start with a lot of enthusiasm. As many projects grow the technical debt gets bigger and the enthusiasm gets less. Almost any developer can develop a great project, but the key is maintaining an ever evolving application with minimal technical debt without loosing enthusiasm.
During this talk you will be taken on the journey of application design. The starting point is an application that looks fine but contains lots of potential pitfalls. We will address the problems and solve them with beautiful design. We end up with testable, nicely separated software with a clear intention.
Rich Model And Layered Architecture in SF2 ApplicationKirill Chebunin
Presentation for Symfony Camp UA 2012.
* What are Rich Model, Service Layer & Layered Architecture
* Layered architecture in Sf2 Application
* Integration with 3rd party bundles
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
Slides from my talk presented during Dutch PHP Conference in Amsterdam - 25 June 2016
More Domain-Driven Design related content at: https://domaincentric.net/
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
Have you ever used PHP's built in reflection, only to find you can't do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren't loaded, so that you can modify them directly?
Better Reflection is an awesome new library that uses magical time-warp techniques* (*actual magic or time-warp not guaranteed) to improve on PHP's built-in reflection by providing additional functionality. In this talk we'll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.
How do you create applications with an incredible level of extendability without losing readability in the process? What if there's a way to separate concerns not only on the code, but on the service definition level? This talk will explore structural and behavioural patterns and ways to enrich them through tricks of powerful dependency injection containers such as Symfony2 DIC component.
New Symfony Tips & Tricks (SymfonyCon Paris 2015)Javier Eguiluz
This talk included tens of tips and tricks, new features and rarely used options for Symfony and its ecosystem. Besides the full-stack Symfony framework, other related technologies were mentioned, like Doctrine, Composer, Twig, PHPUnit and Monolog.
What should you test with your unit tests? Some people will say that unit behaviour is best tested through it's outcomes. But what if communication between units itself is more important than the results of it? This session will introduce you to two different ways of unit-testing and show you a way to assert your object behaviours through their communications.
Replacing dependents with doubles is a central part of testing that every developer has to master. This talk goes over the different types of doubles and explains their place in testing, how to implement them in a mainstream mocking framework, and which strategies or doubles to use in different message exchange scenarios between objects. After this talk you will have moved a step forward in your understanding of testing in the context of object oriented programming.
A lot of people using PHPunit for testing their source code. While I was observing my team I recognized most of them are only using the standard assertions like 'assertEquals()' and are complaining about how hard it is to test the code even when the tests are written first. This talk is about all the stuff not used on a daily basis and it digs deep into uncommon features of PHPUnit.
Un gioco in cui vincono tutti o due piccioni con una fava ;)
Lavorare rivolti alla creazione di valore per il cliente e da questo ottenere una libreria quasi pronta per essere pubblicata
Slides from the talk at http://www.meetup.com/GTA-PHP-User-Group-Toronto/events/151672182/
Source code for the demo at https://github.com/zymsys/Slim-RedBeanPHP-KnockoutJS
An Elephant of a Different Colour: HackVic Metcalfe
Slides from my GTA-PHP Meetup talk about Hack which is the Facebook version of the PHP programming language which runs under their HHVM runtime environment for PHP. The focus of my talk was the language improvements that the Facebook team has added to PHP.
There's a lot of information in the presenter's notes, so if you're interested in Hack scroll down to see the extras.
Rich Model And Layered Architecture in SF2 ApplicationKirill Chebunin
Presentation for Symfony Camp UA 2012.
* What are Rich Model, Service Layer & Layered Architecture
* Layered architecture in Sf2 Application
* Integration with 3rd party bundles
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
Slides from my talk presented during Dutch PHP Conference in Amsterdam - 25 June 2016
More Domain-Driven Design related content at: https://domaincentric.net/
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
Have you ever used PHP's built in reflection, only to find you can't do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren't loaded, so that you can modify them directly?
Better Reflection is an awesome new library that uses magical time-warp techniques* (*actual magic or time-warp not guaranteed) to improve on PHP's built-in reflection by providing additional functionality. In this talk we'll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.
How do you create applications with an incredible level of extendability without losing readability in the process? What if there's a way to separate concerns not only on the code, but on the service definition level? This talk will explore structural and behavioural patterns and ways to enrich them through tricks of powerful dependency injection containers such as Symfony2 DIC component.
New Symfony Tips & Tricks (SymfonyCon Paris 2015)Javier Eguiluz
This talk included tens of tips and tricks, new features and rarely used options for Symfony and its ecosystem. Besides the full-stack Symfony framework, other related technologies were mentioned, like Doctrine, Composer, Twig, PHPUnit and Monolog.
What should you test with your unit tests? Some people will say that unit behaviour is best tested through it's outcomes. But what if communication between units itself is more important than the results of it? This session will introduce you to two different ways of unit-testing and show you a way to assert your object behaviours through their communications.
Replacing dependents with doubles is a central part of testing that every developer has to master. This talk goes over the different types of doubles and explains their place in testing, how to implement them in a mainstream mocking framework, and which strategies or doubles to use in different message exchange scenarios between objects. After this talk you will have moved a step forward in your understanding of testing in the context of object oriented programming.
A lot of people using PHPunit for testing their source code. While I was observing my team I recognized most of them are only using the standard assertions like 'assertEquals()' and are complaining about how hard it is to test the code even when the tests are written first. This talk is about all the stuff not used on a daily basis and it digs deep into uncommon features of PHPUnit.
Un gioco in cui vincono tutti o due piccioni con una fava ;)
Lavorare rivolti alla creazione di valore per il cliente e da questo ottenere una libreria quasi pronta per essere pubblicata
Slides from the talk at http://www.meetup.com/GTA-PHP-User-Group-Toronto/events/151672182/
Source code for the demo at https://github.com/zymsys/Slim-RedBeanPHP-KnockoutJS
An Elephant of a Different Colour: HackVic Metcalfe
Slides from my GTA-PHP Meetup talk about Hack which is the Facebook version of the PHP programming language which runs under their HHVM runtime environment for PHP. The focus of my talk was the language improvements that the Facebook team has added to PHP.
There's a lot of information in the presenter's notes, so if you're interested in Hack scroll down to see the extras.
Organizing Your PHP Projects (2010 ConFoo)Paul Jones
By using a few simple organizational principles, developers can make their project structure predictable, extensible, and modular. These techniques make it easy to de-conflict and share code between multiple projects. They also make it easy to automate project-support tasks such as testing, documentation, and distribution. This talk will discuss these principles, how they can be discovered from researching publicly available PHP projects, and how they are used (or not used) in popular applications and frameworks.
On December 3, 2015 PHP 7.0.0 was released, starting a new milestone for PHP web application development and also announcing the final years for PHP 5, the version developers have loved for over a decade. A decent knowledge of PHP 5 syntax and behavior is required to understand changes that were made in PHP7.
Writing readable code is one of the most important aspects of web development. A developer should write code which another human is able to understand without the help of too many comments.
This talk will show you how to tidy up your code and write readable PHP.
https://speakerdeck.com/willroth/50-laravel-tricks-in-50-minutes - origin
Laravel 5.1 raised the bar for framework documentation, but there's much, much more lurking beneath the surface. In this 50-minute session, we'll explore 50 (yes, 50!) high-leverage implementation tips & tricks that you just won't find in the docs: the IoC Container, Blade, Eloquent, Middleware, Routing, Commands, Queues, Events, Caching — we'll cover them all! Join us as we drink from the fire hose & learn to take advantage of everything that Laravel has to offer to build better software faster!
In modern application development process, testing is not only an addition. Methodologies like TDD or BDD requires time for tests architecture preparation, to make the automatic testing process as fast and extendable as possible.
One of the best examples of proper testing suite revolution is Behat system from open-source eCommerce project Sylius (https://github.com/Sylius/Sylius), which has been entirely rebuilt in the recent past.
In my talk, I will present the most significant problems which we had defined in previous UI tests and conclusions we’ve deduced from them. I will also show a way, how we’ve rewritten the tests system, using powerful, often not widely known, mechanisms and patterns. I will explain the whole architecture of the new Behat system in Sylius, which helps us to build new, adequately tested functionalities, in the most efficient way.
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...Mateusz Zalewski
Czysty kod. Jakościowe oprogramowanie. Dobre praktyki. Święte Graale pracy programisty, o których każdy z nas wie, a mimo to wciąż zachowujemy się tak, jakby ich nie było. Bo przecież ten kod to tylko na chwilę. A tego to w ogóle nie będziemy używać. A tę klasę się zrefaktoruje później. Wszyscy od czasu do czasu zaciągamy dług u samych z siebie z przyszłości - dług, którego potem (nie bez powodu) bardzo nie chcemy spłacać.
Zagłębmy się więc w ten fascynujący świat słabego oprogramowania. Przejdźmy przez las nieużytych wzorców projektowych, przebrnijmy przez bagna zagnieżdżonych pętli. Wejdźmy na kolejny ośmiotysięcznik, a może z jego szczytu uda nam się dojrzeć zatokę pięknego kodu - w której, miejmy nadzieję, tym razem pozostaniemy na dłużej.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
Keynote at DIGIT West Expo, Glasgow on 29 May 2024.
Cheryl Hung, ochery.com
Sr Director, Infrastructure Ecosystem, Arm.
The key trends across hardware, cloud and open-source; exploring how these areas are likely to mature and develop over the short and long-term, and then considering how organisations can position themselves to adapt and thrive.
DevOps and Testing slides at DASA ConnectKari Kakkonen
My and Rik Marselis slides at 30.5.2024 DASA Connect conference. We discuss about what is testing, then what is agile testing and finally what is Testing in DevOps. Finally we had lovely workshop with the participants trying to find out different ways to think about quality and testing in different parts of the DevOps infinity loop.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
In this insightful webinar, Inflectra explores how artificial intelligence (AI) is transforming software development and testing. Discover how AI-powered tools are revolutionizing every stage of the software development lifecycle (SDLC), from design and prototyping to testing, deployment, and monitoring.
Learn about:
• The Future of Testing: How AI is shifting testing towards verification, analysis, and higher-level skills, while reducing repetitive tasks.
• Test Automation: How AI-powered test case generation, optimization, and self-healing tests are making testing more efficient and effective.
• Visual Testing: Explore the emerging capabilities of AI in visual testing and how it's set to revolutionize UI verification.
• Inflectra's AI Solutions: See demonstrations of Inflectra's cutting-edge AI tools like the ChatGPT plugin and Azure Open AI platform, designed to streamline your testing process.
Whether you're a developer, tester, or QA professional, this webinar will give you valuable insights into how AI is shaping the future of software delivery.
25. function initialize()
function handleAdd()
function handleUpdate()
function loadCartItems()
function loadProducts()
function loadProvinces()
function calculateCartSubtotal($cartItems, $products)
function calculateCartTaxes($cartItems, $products, $taxrate)
function buildViewData()
How might we group these functions?
26. function initialize()
function handleAdd()
function handleUpdate()
function loadCartItems()
function loadProducts()
function loadProvinces()
function calculateCartSubtotal($cartItems, $products)
function calculateCartTaxes($cartItems, $products, $taxrate)
function buildViewData()
Invisible stuff
that happens on
page load
Loads stuff into
our HTML (view)
28. function initialize()
function handleAdd()
function handleUpdate()
function loadCartItems()
function loadProducts()
function loadProvinces()
function calculateCartSubtotal($cartItems, $products)
function calculateCartTaxes($cartItems, $products, $taxrate)
function buildViewData()
Invisible stuff
that happens on
page load
Loads stuff into
our HTML (view)
29. function initialize()
function handleAdd()
function handleUpdate()
function loadCartItems()
function loadProducts()
function loadProvinces()
function calculateCartSubtotal($cartItems, $products)
function calculateCartTaxes($cartItems, $products, $taxrate)
function buildViewData()
private
private
public
private
private
public
private
private
private
30. class Initializer
{
private $connection;
public function __construct(PDO $connection)
{
$this->connection = $connection;
}
public function initialize()
{
session_start();
if (!isset($_SESSION['cart'])) {
$this->connection->exec("INSERT INTO cart () VALUES ()");
$_SESSION['cart'] = $this->connection->lastInsertId();
}
$this->handleAdd();
$this->handleUpdate();
}
private function handleAdd() { … }
private function handleUpdate() { … }
}
https://github.com/zymsys/solid/blob/02/cart.php
31. class ViewData {
private $connection;
public function __construct(PDO $connection)
{
$this->connection = $connection;
}
private function loadCartItems() { … }
private function loadProducts(){ … }
private function loadProvinces(){ … }
private function calculateCartSubtotal($cartItems, $products) { … }
private function calculateCartTaxes($cartItems, $products, $taxrate) { … }
public function buildViewData() { … }
}
https://github.com/zymsys/solid/blob/02/cart.php
37. function initialize()
function handleAdd()
function handleUpdate()
function loadCartItems()
function loadProducts()
function loadProvinces()
function calculateCartSubtotal($cartItems, $products)
function calculateCartTaxes($cartItems, $products, $taxrate)
function buildViewData()
Invisible stuff
that happens on
page load
Loads stuff into
our HTML (view)
38. function initialize()
function handleAdd()
function handleUpdate()
function loadCartItems()
function loadProducts()
function loadProvinces()
function calculateCartSubtotal($cartItems, $products)
function calculateCartTaxes($cartItems, $products, $taxrate)
function buildViewData()
Sales
Accounting
Inventory
Application / IT
39. class Application
{
private $connection;
public function __construct()
{
$this->connection = new PDO('mysql:host=localhost;dbname=solid', 'root', '');
$this->inventory = new Inventory($this->connection);
$this->sales = new Sales($this->connection);
$this->accounting = new Accounting($this->connection);
}
public function initialize()
{
session_start();
if (!isset($_SESSION['cart'])) {
$this->connection->exec("INSERT INTO cart VALUES ()");
$_SESSION['cart'] = $this->connection->lastInsertId();
}
$this->handlePost();
}
https://github.com/zymsys/solid/blob/03/cart.php
54. class AccountingStrategy {
private $description;
public function __construct($description)
{
$this->description = $description;
}
public function getAdjustment($cartItems)
{
return false;
}
public function getDescription()
{
return $this->description;
}
}
https://github.com/zymsys/solid/blob/04/cart.php
55. class TaxAccountingStrategy extends AccountingStrategy {
private $products;
private $taxRate;
public function __construct($products, $province)
{
parent::__construct($province['name'] . ' taxes at ' .
$province['taxrate'] . '%:');
$this->products = $products;
$this->taxRate = $province['taxrate'];
}
public function getAdjustment($cartItems)
{
$taxable = 0;
foreach ($cartItems as $cartItem) {
$product = $this->products[$cartItem['product']];
$taxable += $product['taxes'] ?
$cartItem['quantity'] * $product['price'] : 0;
}
return $taxable * $this->taxRate / 100;
}
}
https://github.com/zymsys/solid/blob/04/cart.php
57. public function initialize()
{
session_start();
if (!isset($_SESSION['cart'])) {
$this->connection->exec("INSERT INTO cart VALUES ()");
$_SESSION['cart'] = $this->connection->lastInsertId();
}
$this->handlePost();
$this->products = $this->inventory->loadProducts();
$provinceRepository = new ProvinceRepository($this->connection,
isset($_GET['province']) ? $_GET['province'] : 'ON');
$this->provinces = $provinceRepository->loadProvinces();
$this->selectedProvince = $provinceRepository->getSelectedProvince();
$this->accounting->addStrategy(
new TaxAccountingStrategy(
$this->products,
$provinceRepository->getSelectedProvince()
)
);
}
public function initialize()
{
session_start();
if (!isset($_SESSION['cart'])) {
$this->connection->exec("INSERT INTO cart VALUES ()");
$_SESSION['cart'] = $this->connection->lastInsertId();
}
$this->handlePost();
}
https://github.com/zymsys/solid/blob/04/cart.php
58. public function buildViewData()
{
$viewData = [
'cartItems' => $this->sales->loadCartItems(),
'products' => $this->inventory->loadProducts(),
'provinces' => $this->accounting->loadProvinces(),
'provinceCode' => isset($_GET['province']) ?
$_GET['province'] : 'ON', //Default to GTA-PHP's home
];
public function buildViewData()
{
$cartItems = $this->sales->loadCartItems();
$viewData = [
'cartItems' => $cartItems,
'products' => $this->products,
'provinces' => $this->provinces,
'adjustments' => $this->accounting->applyAdjustments($cartItems),
'provinceCode' => $this->selectedProvince['code'],
];
Done in
initialize() now
Used Twice
New!
Start of buildViewData()
https://github.com/zymsys/solid/blob/04/cart.php
59. End of buildViewData()
$viewData['subtotal'] = $this->accounting->
calculateCartSubtotal($viewData['cartItems'], $viewData['products']);
$viewData['taxes'] = $this->accounting->
calculateCartTaxes($viewData['cartItems'],
$viewData['products'], $viewData['province']['taxrate']);
$viewData['total'] = $viewData['subtotal'] + $viewData['taxes'];
return $viewData;
}
$viewData['subtotal'] = $this->accounting->
calculateCartSubtotal($viewData['cartItems'], $viewData['products']);
$viewData['total'] = $viewData['subtotal'] +
$this->accounting->getAppliedAdjustmentsTotal();
return $viewData;
}
Taxes are handled by adjustments
and removed as a specific item in
the view’s data.
https://github.com/zymsys/solid/blob/04/cart.php
60. // loadProvinces used to live in the Accounting class
class ProvinceRepository
{
private $connection;
private $provinces = null;
private $selectedProvince;
private $selectedProvinceCode;
public function __construct(PDO $connection, $selectedProvinceCode)
{
$this->connection = $connection;
$this->selectedProvinceCode = $selectedProvinceCode;
}
public function loadProvinces() { … } // Now sets $selectedProvince
public function getProvinces()
{
return is_null($this->provinces) ? $this->loadProvinces() : $this->provinces;
}
public function getSelectedProvince()
{
return $this->selectedProvince;
}
}
https://github.com/zymsys/solid/blob/04/cart.php
61. Remove calculateCartTaxes and add
AccountingStrategy
class Accounting {
private $connection;
private $strategies = [];
private $appliedAdjustments = 0;
public function __construct(PDO $connection)
{
$this->connection = $connection;
}
public function calculateCartSubtotal($cartItems, $products) { … } // No change
public function addStrategy(AccountingStrategy $strategy)
{
$this->strategies[] = $strategy;
}
https://github.com/zymsys/solid/blob/04/cart.php
62. public function applyAdjustments($cartItems)
{
$adjustments = [];
foreach ($this->strategies as $strategy) {
$adjustment = $strategy->getAdjustment($cartItems);
if ($adjustment) {
$this->appliedAdjustments += $adjustment;
$adjustments[] = [
'description' => $strategy->getDescription(),
'adjustment' => $adjustment,
];
}
}
return $adjustments;
}
public function getAppliedAdjustmentsTotal()
{
return $this->appliedAdjustments;
}
}
//Class Accounting Continued…
https://github.com/zymsys/solid/blob/04/cart.php
71. Ways to break LSP
• Throw a new exception
• Add requirements to parameters
• requiring a more specific type
• Return an unexpected type
• returning a less specific type
• Do anything that would be unexpected if used as a
stand-in for an ancestor
77. We can scrap the
AccountingStrategy class and add…
interface AccountingStrategyInterface
{
public function getDescription();
public function getAdjustment($cartItems);
}
https://github.com/zymsys/solid/blob/06/cart.php
78. Because Application creates concrete
classes there’s little to be gained by
adding other interfaces
public function __construct()
{
$this->connection = new PDO('mysql:host=localhost;dbname=solid', 'root', '');
$this->inventory = new Inventory($this->connection);
$this->sales = new Sales($this->connection);
$this->accounting = new Accounting($this->connection);
}
Dependency Injection Containers would
solve this, but are a topic for another talk.
https://github.com/zymsys/solid/blob/06/cart.php
82. Imagine an interface to our
Sales class
interface SalesInterface
{
public function addProductToCart($cartId, $productId, $quantity);
public function modifyProductQuantityInCart($cartId, $productId, $quantity);
public function loadCartItems();
}
83. Imagine an interface to our
Sales class
interface SalesWriterInterface
{
public function addProductToCart($cartId, $productId, $quantity);
public function modifyProductQuantityInCart($cartId, $productId, $quantity);
public function loadCartItems();
}
interface SalesReaderInterface
{
}
Why would I build handcuffs into my code that let me do less with it? Talk about the contract we have with code outside our class and how private methods make refactoring easier.
Loads more into ivars instead of directly into view
Strategies are also added at initialize.
Avoid these terms, but if they come up:
Parameters should be contravariant
Return types should be covariant
Most ISP definitions go so far as to say that no class should be forced to depend on methods they do not use. Personally I think this goes too far.