Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Whats new in Magento 2
Search
James Cowie
September 17, 2015
Technology
0
110
Whats new in Magento 2
An overview of what has changed since Magento 1 and what to expect as a developer
James Cowie
September 17, 2015
Tweet
Share
More Decks by James Cowie
See All by James Cowie
Learn to love testing an agile journey into Behat, PHPSpec and Magento
jamescowie
0
340
Outside in BDD
jamescowie
1
75
Behaviour Driven Development
jamescowie
1
970
Other Decks in Technology
See All in Technology
OpenTelemetryセマンティック規約の恩恵とMackerel APMにおける活用例 / SRE NEXT 2025
mackerelio
2
1.3k
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
2
7.8k
ポストコロナ時代の SaaS におけるコスト削減の意義
izzii
1
190
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
54
22k
対話型音声AIアプリケーションの信頼性向上の取り組み
ivry_presentationmaterials
1
600
PO初心者が考えた ”POらしさ”
nb_rady
0
220
Lakebaseを使ったAIエージェントを実装してみる
kameitomohiro
0
170
クラウド開発の舞台裏とSRE文化の醸成 / SRE NEXT 2025 Lunch Session
kazeburo
1
410
CDKTFについてざっくり理解する!!~CloudFormationからCDKTFへ変換するツールも作ってみた~
masakiokuda
1
190
公開初日に Gemini CLI を試した話や FFmpeg と組み合わせてみた話など / Gemini CLI 初学者勉強会(#AI道場)
you
PRO
0
880
【あのMCPって、どんな処理してるの?】 AWS CDKでの開発で便利なAWS MCP Servers特集
yoshimi0227
6
600
全部AI、全員Cursor、ドキュメント駆動開発 〜DevinやGeminiも添えて〜
rinchsan
2
500
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
524
40k
The Cult of Friendly URLs
andyhume
79
6.5k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Become a Pro
speakerdeck
PRO
29
5.4k
Designing for Performance
lara
610
69k
Why Our Code Smells
bkeepers
PRO
336
57k
Git: the NoSQL Database
bkeepers
PRO
430
65k
A better future with KSS
kneath
238
17k
Scaling GitHub
holman
460
140k
How to Ace a Technical Interview
jacobian
278
23k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
A Modern Web Designer's Workflow
chriscoyier
695
190k
Transcript
1 Whats New in magento 2
2 James Cowie Software Engineer Session Digital @Jcowie
3 What to expect as a developer
4 Whats changed Since Magento 1
5
6 2012 2009 2012 2009 2013 Composer namespaces. traits generators.
type hinting
7 The world of engineering has changed
8 • Server Architecture • TDD • BDD • DDD
Cloud Docker VPS PHPSpec - 2011 Behat - 2011
9 installing Magento break time
None
11
12 composer create-project --stability=beta --no-install magento/project-community-edition M2Test
{ "name": "magento/project-community-edition", "type": "project", "require": { "magento/product-community-edition": "0.74.0-beta12" },
"require-dev": { } }
14 composer can do much more
15 • Packagist + packages.magento.com • Package versioning • Dependency
Management
composer require "league/period"
1 /** 2 * @var League\Period\Period; 3 */ 4 protected
$_datePeriod; 5 6 /** 7 * @param \League\Period\Period; $datePeriod 8 */ 9 public function __construct(\League\Period\Period $datePeriod) 10 { 11 $this->_datePeriod = $datePeriod; 12 }
18 Versioning In Composer
19 Exact version: “1.4.2″, “v1.4.2″. "magento/product-community-edition": “1.0.1”
20 Ranges: >=1.0, <2.0, "magento/product-community-edition": “>=1.0, <2”
21 Wildcard: “1.0.*”, “1.*” "magento/product-community-edition": “1.*” "magento/product-community-edition": “1.0.*”
22 Next Significant Release: “~1.2″ is equivalent to “>=1.2,<2.0″. "magento/product-community-edition":
“~1.2”
None
24 Decoupling modules
None
26 •Clean Code •Reusable packages •Testable •Easier to read •Easier
to maintain
27 • No Dependency Injection container. • Mage god class
• Hard to test • Hard to decouple logic
28 Dependency Injection in Magento 2
None
public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry
$coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry
$coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator Code Smell
32 • replaces Mage:: god class • Dependency Injection can
be overused. • enables composition.
1 <?php 2 class Sample 3 { 4 protected $logger;
5 6 public function doSomething() 7 { 8 $this->logger = new \Logger(); 9 $logger->doSomething(); 10 } 11 }
1 <?php 2 class Sample 3 { 4 protected $logger;
5 6 public function doSomething() 7 { 8 $this->logger = new \Logger(); 9 $logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
38 • Responsibility • swap concrete implementation • Mock the
dependency
39 Back to Magento 2
/** * @param \Magento\Framework\View\Element\Context $conte */ public function __construct( \Magento\Framework\View\Element\Context
$context ) { parent::__construct($context, $data); }
41 Its not only Objects that can be injected.
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
protected $_extensions; public function __construct( array $extensions = [] )
{ $this->_extensions = $extensions; }
$allowed = $this->_extensions["{$type}_allowed"];
48 • Separating instantiation of objects from the object •
Easier to test • Aids with Separation of concerns
49 Testing
None
None
function it_should_create_a_new_cached_image($filesystem) { $filesystem->beADoubleOf( \Magento\Framework\Filesystem $fileSystem); $this->createCachedFile($filesystem) ->shouldReturnTrue(); }
53 • Composer can help create reusable packages • Dependency
Injection is a must, • Yet be careful on how many dependencies are injected • Testing has become easier • Decoupling of modules is now easier • Magento 2 service contracts / Design by contract ( Interfaces )
54 special thanks
55