Magento 2 introduces dependency injection and interceptors, two approaches to creating a more flexible, extendable architecture. These concepts are new to many PHP developers, but they are critical to understanding and taking advantage of the power and flexibility of Magento 2. Let's take a high-level look at these concepts, and then dive into some real examples of how to utilize these techniques in your development work with Magento 2.
65. JoshuaWarren.com #phpworld
Without Dependency Injection
public function getFormattedPrice($sku)
{
$db = new DBHandler;
$row = $db->query('SELECT price FROM products WHERE sku = ?', $sku);
$formatter = new PriceFormatter;
return $formatter->asDollars($row['price']);
}
66. JoshuaWarren.com #phpworld
With Dependency Injection
public function getFormattedPrice($sku, $db, $formatter)
{
$row = $db->query('SELECT price FROM products WHERE sku = ?', $sku);
return $formatter->asDollars($row['price']);
}
83. JoshuaWarren.com #phpworld
Plugin/PluginAround.php
public function aroundBaseMethodUppercase(ChildAround $subject, Closure $proceed,
$interceptedInput)
{
$argument = "(around: before base method) $interceptedInput (/around: before base method)";
$result = $proceed($argument);
return "(around: after base method) $result (/around: after base method)";
}
97. Dev Docs Team
Team of hard-working technical writers (not developers)
Writing documentation for a system that has yet to be used ‘in the
wild’
Very eager for feedback and input - they don’t know what
documentation you need
Very open to pull requests of documentation or just open an issue
on Github with feedback + requests
JoshuaWarren.com #phpworld
102. JoshuaWarren.com
As a freelancer…
Learning Magento 2
Set aside time in your week to learn the design patterns Magento 2 uses
Work through the sample code the Magento 2 team has provided
Begin experimenting with developing with Magento 2
Do not try to learn ‘on the job’ - be careful accepting M2 work before you’re
ready
#phpworld
103. JoshuaWarren.com
As an in-house developer for a merchant…
Learning Magento 2
Determine when your business is likely to migrate to Magento 2
First 2-4 weeks of your Magento 2 migration schedule should be learning Magento 2
Learn the patterns before you start!
#phpworld
104. JoshuaWarren.com
As an agency or industry partner…
Learning Magento 2
Create a tiger team of developers focused on Magento 2
Allow those developers time in the day to learn Magento 2
Those developers should implement your first Magento 2 projects
That team then helps the rest of your team through the learning curve
#phpworld
105. JoshuaWarren.com
When do I need to be Magento 2 ready?
Learning Magento 2
Magento 2 will be released late enough in the year that most merchants
won’t begin using it immediately.
Merchants will also wait until their mission-critical extensions are
available on Magento 2.
Start learning it now - but don’t panic!
#phpworld