SlideShare a Scribd company logo
Code Generation
in Magento 2
Sergii Shymko
Senior Software Engineer
Magento, an eBay Inc. company
Legal Disclaimer
Copyright © 2015 Magento, Inc. All Rights Reserved.
Magento®, eBay Enterprise™ and their respective logos are trademarks, service marks,
registered trademarks, or registered service marks of eBay, Inc. or its subsidiaries. Other
trademarks or service marks contained in this presentation are the property of the
respective companies with which they are associated.
This presentation is for informational and discussion purposes only and should not be
construed as a commitment of Magento, Inc. or eBay Enterprise (“eBay Enterprise”) or of
any of their subsidiaries or affiliates. While we attempt to ensure the accuracy,
completeness and adequacy of this presentation, neither Magento, Inc., eBay Enterprise
nor any of their subsidiaries or affiliates are responsible for any errors or will be liable for
the use of, or reliance upon, this presentation or any of the information contained in it.
Unauthorized use, disclosure or dissemination of this information is expressly prohibited.
Introduction to Code Generation
• Automatic programming – generation of computer program
• Source code generation
– Generation based on template
• Allows to write code at higher abstraction level
• Enables aspect-oriented programming (AOP)
• Enables generic programming – parameterization over types
• Avoids writing boilerplate code
Code Generation in Magento 1.x
Code Generation in Magento 2
Code Generation in Magento 2
• Code is generated:
– On the fly (development)
• Autoload non-existing class that follows naming pattern
– Beforehand (production)
• Run CLI tools
php dev/tools/Magento/Tools/Di/compiler.php
• Location of generated code:
var/generation/
Factories
• Factory creates objects
• Single method – create()
• Used for non-injectables, i.e. entities
• Isolation from Object Manager
• Type safety
• IDE auto-completion
• Class name pattern:
NamespaceClassFactory
Factory Usage
namespace MagentoCatalogModelProduct;
class Copier
{
public function __construct(
MagentoCatalogModelProductFactory $productFactory
) {
$this->productFactory = $productFactory;
}
public function copy(MagentoCatalogModelProduct $product) {
$duplicate = $this->productFactory->create();
// ...
}
}
app/code/Magento/Catalog/Model/Product/Copier.php
Generated Factory (Simplified)
namespace MagentoCatalogModel;
class ProductFactory
{
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager
) {
$this->objectManager = $objectManager;
}
public function create(array $data = array()) {
return $this->objectManager->create(
'MagentoCatalogModelProduct',
$data
);
}
}
var/generation/Magento/Catalog/Model/ProductFactory.php
Proxies
• Implementation of GoF pattern
• Follows interface of subject
• Delays creation of subject
– Delays creation of dependencies
• Forwards calls to subject
• Used for optional dependencies of DI
• Class name pattern:
NamespaceClassProxy
Proxy Usage in DI Config
<config>
<type name="MagentoCatalogModelResourceProductCollection">
<arguments>
<argument name="customerSession" xsi:type="object">
MagentoCustomerModelSessionProxy
</argument>
</arguments>
</type>
</config>
app/code/Magento/Catalog/etc/di.xml
Generated Proxy (Simplified)
namespace MagentoCustomerModelSession;
class Proxy extends MagentoCustomerModelSession
{
protected function getSubject() {
if (!$this->subject) {
$this->subject = $this->objectManager->get(
'MagentoCustomerModelSession'
);
}
return $this->subject;
}
public function getCustomerId() {
return $this->getSubject()->getCustomerId();
}
// ...
}
var/generation/Magento/Customer/Model/Session/Proxy.php
Interception
• Primary customization approach
• AOP-like mechanism
• Used for plugins
• Attach behavior to public methods
– Before
– After
– Around
• Plugins declared in DI config
Plugin Implementation
namespace MagentoStoreAppActionPlugin;
class StoreCheck
{
public function aroundDispatch(
MagentoFrameworkAppActionAction $subject,
Closure $proceed,
MagentoFrameworkAppRequestInterface $request
) {
if (!$this->storeManager->getStore()->getIsActive()) {
throw new MagentoFrameworkAppInitException(
'Current store is not active.'
);
}
return $proceed($request);
}
}
app/code/Magento/Store/App/Action/Plugin/StoreCheck.php
Plugin Declaration in DI Config
<config>
<type name="MagentoFrameworkAppActionAction">
<plugin name="storeCheck"
type="MagentoStoreAppActionPluginStoreCheck"
sortOrder="10"/>
</type>
</config>
app/code/Magento/Store/etc/di.xml
Generated Interceptor (Simplified)
namespace MagentoFrameworkAppActionAction;
class Interceptor extends MagentoFrameworkAppActionAction
{
public function dispatch(
MagentoFrameworkAppRequestInterface $request
) {
$pluginInfo = $this->pluginList->getNext(
'MagentoFrameworkAppActionAction', 'dispatch'
);
if (!$pluginInfo) {
return parent::dispatch($request);
} else {
return $this->___callPlugins(
'dispatch', func_get_args(), $pluginInfo
);
}
}
}
var/generation/Magento/Framework/App/Action/Action/Interceptor.php
Code Generation for Service Layer
• Service layer – ultimate public API
• Services implement stateless operations
• Generated code:
– Repository*
– Persistor*
– Search Results
– Extension Attributes
* – may be removed in future releases
Generated Repository (Simplified)
namespace MagentoSalesApiDataOrder;
class Repository implements MagentoSalesApiOrderRepositoryInterface
{
public function __construct(
MagentoSalesApiDataOrderInterfacePersistor $orderPersistor,
MagentoSalesApiDataOrderSearchResultInterfaceFactory $searchResultFactory
) {
$this->orderPersistor = $orderPersistor;
$this->searchResultFactory = $searchResultFactory;
}
public function get($id);
public function create(MagentoSalesApiDataOrderInterface $entity);
public function getList(MagentoFrameworkApiSearchCriteria $criteria);
public function remove(MagentoSalesApiDataOrderInterface $entity);
public function flush();
}
var/generation/Magento/Sales/Api/Data/Order/Repository.php
Extension Attributes
• Extension to data interfaces from 3rd party modules
• Attributes declared in configuration
• Attribute getters/setters generated
• Type-safe attribute access
• IDE auto-completion
• Class name pattern:
NamespaceClassExtensionInterface
NamespaceClassExtension
Declaration of Extension Attributes
<config>
<custom_attributes for="MagentoCatalogApiDataProductInterface">
<attribute code="price_type" type="integer" />
</custom_attributes>
</config>
app/code/Magento/Bundle/etc/data_object.xml
Entity with Extension Attributes
namespace MagentoCatalogApiData;
interface ProductInterface
extends MagentoFrameworkApiCustomAttributesDataInterface
{
/**
* @return MagentoCatalogApiDataProductExtensionInterface|null
*/
public function getExtensionAttributes();
public function setExtensionAttributes(
MagentoCatalogApiDataProductExtensionInterface $attributes
);
// ...
}
app/code/Magento/Catalog/Api/Data/ProductInterface.php
Generated Interface of Extension Attributes
namespace MagentoCatalogApiData;
interface ProductExtensionInterface
extends MagentoFrameworkApiExtensionAttributesInterface
{
/**
* @return integer
*/
public function getPriceType();
/**
* @param integer $priceType
* @return $this
*/
public function setPriceType($priceType);
// ...
}
var/generation/Magento/Catalog/Api/Data/ProductExtensionInterface.php
Generated Implementation of Extension Attributes
namespace MagentoCatalogApiData;
class ProductExtension
extends MagentoFrameworkApiAbstractSimpleObject
implements MagentoCatalogApiDataProductExtensionInterface
{
/**
* @return integer
*/
public function getPriceType() {
return $this->_get('price_type');
}
/**
* @param integer $priceType
* @return $this
*/
public function setPriceType($priceType) {
return $this->setData('price_type', $priceType);
}
// ...
}
var/generation/Magento/Catalog/Api/Data/ProductExtension.php
Loggers
• Implementation of GoF pattern Decorator
• Activated with the profiler
– Object Manager wraps instances with loggers
• Tracks method call stack
• Forwards calls to original methods
• Class name pattern:
NamespaceClassLogger
Summary of Code Generation
• DI
– Factory
– Proxy
• Interception
• Service Layer
– Repository
– Persistor
– Search Results
– Extension Attributes
• Logger
Thank You!
Q & A
Sergii Shymko
sshymko@ebay.com
Resources
• github.com
– magento/magento2 – Magento 2 Community Edition
– magento/magento2-community-edition – Composer project for
Magento 2 CE
• devdocs.magento.com
– Factories
– Proxies
– Plugins
– Definition compilation tool

More Related Content

What's hot

Yii php framework_honey
Yii php framework_honeyYii php framework_honey
Yii php framework_honey
Honeyson Joseph
 
Magento Fireside Chat: "Wiring Mageno Projects"
Magento Fireside Chat: "Wiring Mageno Projects"Magento Fireside Chat: "Wiring Mageno Projects"
Magento Fireside Chat: "Wiring Mageno Projects"
AOE
 
Yii framework
Yii frameworkYii framework
Yii framework
Pratik Gondaliya
 
Meet Magento Belarus - Sergey Ivashchenko
Meet Magento Belarus - Sergey IvashchenkoMeet Magento Belarus - Sergey Ivashchenko
Meet Magento Belarus - Sergey Ivashchenko
Amasty
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
Marcus Hellberg
 
Sander Mak - Keeping Up With Java - Codemotion Rome 2019
Sander Mak - Keeping Up With Java - Codemotion Rome 2019Sander Mak - Keeping Up With Java - Codemotion Rome 2019
Sander Mak - Keeping Up With Java - Codemotion Rome 2019
Codemotion
 
Introduction to Alfresco Surf Platform
Introduction to Alfresco Surf PlatformIntroduction to Alfresco Surf Platform
Introduction to Alfresco Surf Platform
Alfresco Software
 
Yii - Next level PHP Framework von Florian Facker
Yii - Next level PHP Framework von Florian FackerYii - Next level PHP Framework von Florian Facker
Yii - Next level PHP Framework von Florian Facker
Mayflower GmbH
 
Codestrong 2012 breakout session introduction to mobile web and best practices
Codestrong 2012 breakout session   introduction to mobile web and best practicesCodestrong 2012 breakout session   introduction to mobile web and best practices
Codestrong 2012 breakout session introduction to mobile web and best practicesAxway Appcelerator
 
Integrate Shindig with Joomla
Integrate Shindig with JoomlaIntegrate Shindig with Joomla
Integrate Shindig with Joomla
Anand Sharma
 
Introduction to building joomla! components using FOF
Introduction to building joomla! components using FOFIntroduction to building joomla! components using FOF
Introduction to building joomla! components using FOFTim Plummer
 
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarksMagento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Yireo
 
Tech talk live alfresco web editor [compatibility mode]
Tech talk live   alfresco web editor [compatibility mode]Tech talk live   alfresco web editor [compatibility mode]
Tech talk live alfresco web editor [compatibility mode]Alfresco Software
 
Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3quyong2000
 
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Meet Magento Italy
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
Giuliano Iacobelli
 
Yii Framework
Yii FrameworkYii Framework
Yii Framework
Jason Ragsdale
 
Magento 2.1 ee content staging
Magento 2.1 ee content stagingMagento 2.1 ee content staging
Magento 2.1 ee content staging
Anton Kaplya
 
Selenium Webdriver pop up handling
Selenium Webdriver pop up handlingSelenium Webdriver pop up handling
Selenium Webdriver pop up handling
DestinationQA
 
Magento 2 Performance: Every Second Counts
Magento 2 Performance: Every Second CountsMagento 2 Performance: Every Second Counts
Magento 2 Performance: Every Second Counts
Joshua Warren
 

What's hot (20)

Yii php framework_honey
Yii php framework_honeyYii php framework_honey
Yii php framework_honey
 
Magento Fireside Chat: "Wiring Mageno Projects"
Magento Fireside Chat: "Wiring Mageno Projects"Magento Fireside Chat: "Wiring Mageno Projects"
Magento Fireside Chat: "Wiring Mageno Projects"
 
Yii framework
Yii frameworkYii framework
Yii framework
 
Meet Magento Belarus - Sergey Ivashchenko
Meet Magento Belarus - Sergey IvashchenkoMeet Magento Belarus - Sergey Ivashchenko
Meet Magento Belarus - Sergey Ivashchenko
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
Sander Mak - Keeping Up With Java - Codemotion Rome 2019
Sander Mak - Keeping Up With Java - Codemotion Rome 2019Sander Mak - Keeping Up With Java - Codemotion Rome 2019
Sander Mak - Keeping Up With Java - Codemotion Rome 2019
 
Introduction to Alfresco Surf Platform
Introduction to Alfresco Surf PlatformIntroduction to Alfresco Surf Platform
Introduction to Alfresco Surf Platform
 
Yii - Next level PHP Framework von Florian Facker
Yii - Next level PHP Framework von Florian FackerYii - Next level PHP Framework von Florian Facker
Yii - Next level PHP Framework von Florian Facker
 
Codestrong 2012 breakout session introduction to mobile web and best practices
Codestrong 2012 breakout session   introduction to mobile web and best practicesCodestrong 2012 breakout session   introduction to mobile web and best practices
Codestrong 2012 breakout session introduction to mobile web and best practices
 
Integrate Shindig with Joomla
Integrate Shindig with JoomlaIntegrate Shindig with Joomla
Integrate Shindig with Joomla
 
Introduction to building joomla! components using FOF
Introduction to building joomla! components using FOFIntroduction to building joomla! components using FOF
Introduction to building joomla! components using FOF
 
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarksMagento 2 Seminar - Daniel Genis - Magento 2 benchmarks
Magento 2 Seminar - Daniel Genis - Magento 2 benchmarks
 
Tech talk live alfresco web editor [compatibility mode]
Tech talk live   alfresco web editor [compatibility mode]Tech talk live   alfresco web editor [compatibility mode]
Tech talk live alfresco web editor [compatibility mode]
 
Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3
 
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
Yii Framework
Yii FrameworkYii Framework
Yii Framework
 
Magento 2.1 ee content staging
Magento 2.1 ee content stagingMagento 2.1 ee content staging
Magento 2.1 ee content staging
 
Selenium Webdriver pop up handling
Selenium Webdriver pop up handlingSelenium Webdriver pop up handling
Selenium Webdriver pop up handling
 
Magento 2 Performance: Every Second Counts
Magento 2 Performance: Every Second CountsMagento 2 Performance: Every Second Counts
Magento 2 Performance: Every Second Counts
 

Viewers also liked

Magento 2 Changes Overview
Magento 2 Changes OverviewMagento 2 Changes Overview
Magento 2 Changes Overview
Sergii Shymko
 
Microservices Using Docker Containers for Magento 2
Microservices Using Docker Containers for Magento 2Microservices Using Docker Containers for Magento 2
Microservices Using Docker Containers for Magento 2
Schogini Systems Pvt Ltd
 
Ups and Downs of Real Projects Based on Magento 2
Ups and Downs of Real Projects Based on Magento 2Ups and Downs of Real Projects Based on Magento 2
Ups and Downs of Real Projects Based on Magento 2
Max Pronko
 
The journey of mastering Magento 2 for Magento 1 developers
The journey of mastering Magento 2 for Magento 1 developersThe journey of mastering Magento 2 for Magento 1 developers
The journey of mastering Magento 2 for Magento 1 developers
Gabriel Guarino
 
Magento 2 Theme Trainning for Beginners | Magenest
Magento 2 Theme Trainning for Beginners | MagenestMagento 2 Theme Trainning for Beginners | Magenest
Magento 2 Theme Trainning for Beginners | Magenest
Magenest
 
Methods and Best Practices for High Performance eCommerce
Methods and Best Practices for High Performance eCommerceMethods and Best Practices for High Performance eCommerce
Methods and Best Practices for High Performance eCommerce
dmitriysoroka
 
Magento 2 Development for PHP Developers
Magento 2 Development for PHP DevelopersMagento 2 Development for PHP Developers
Magento 2 Development for PHP Developers
Joshua Warren
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
Hanoi MagentoMeetup
 
#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization
#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization
#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization
Hanoi MagentoMeetup
 
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKKey Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Max Pronko
 
Sito ecommerce vs marketplace
Sito ecommerce vs marketplaceSito ecommerce vs marketplace
Sito ecommerce vs marketplace
MageSpecialist
 
Vitalyi Golomoziy - Integration tests in Magento 2
Vitalyi Golomoziy - Integration tests in Magento 2Vitalyi Golomoziy - Integration tests in Magento 2
Vitalyi Golomoziy - Integration tests in Magento 2
Meet Magento Italy
 
Magento 2 and avoiding the rabbit hole
Magento 2 and avoiding the rabbit holeMagento 2 and avoiding the rabbit hole
Magento 2 and avoiding the rabbit hole
Tony Brown
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ivan Chepurnyi
 
Phpworld.2015 scaling magento
Phpworld.2015 scaling magentoPhpworld.2015 scaling magento
Phpworld.2015 scaling magento
Mathew Beane
 
Andrea Zwirner - Magento security and hardening strategies
Andrea Zwirner - Magento security and hardening strategiesAndrea Zwirner - Magento security and hardening strategies
Andrea Zwirner - Magento security and hardening strategies
Meet Magento Italy
 
Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2
Max Pronko
 
Oleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performanceOleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performance
Meet Magento Italy
 
A Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to DeploymentA Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to Deployment
Joshua Warren
 
Super-scaling Magento with Docker, micro-services and micro-costs
Super-scaling Magento with Docker, micro-services and micro-costsSuper-scaling Magento with Docker, micro-services and micro-costs
Super-scaling Magento with Docker, micro-services and micro-costs
Mikhail Zakharenko
 

Viewers also liked (20)

Magento 2 Changes Overview
Magento 2 Changes OverviewMagento 2 Changes Overview
Magento 2 Changes Overview
 
Microservices Using Docker Containers for Magento 2
Microservices Using Docker Containers for Magento 2Microservices Using Docker Containers for Magento 2
Microservices Using Docker Containers for Magento 2
 
Ups and Downs of Real Projects Based on Magento 2
Ups and Downs of Real Projects Based on Magento 2Ups and Downs of Real Projects Based on Magento 2
Ups and Downs of Real Projects Based on Magento 2
 
The journey of mastering Magento 2 for Magento 1 developers
The journey of mastering Magento 2 for Magento 1 developersThe journey of mastering Magento 2 for Magento 1 developers
The journey of mastering Magento 2 for Magento 1 developers
 
Magento 2 Theme Trainning for Beginners | Magenest
Magento 2 Theme Trainning for Beginners | MagenestMagento 2 Theme Trainning for Beginners | Magenest
Magento 2 Theme Trainning for Beginners | Magenest
 
Methods and Best Practices for High Performance eCommerce
Methods and Best Practices for High Performance eCommerceMethods and Best Practices for High Performance eCommerce
Methods and Best Practices for High Performance eCommerce
 
Magento 2 Development for PHP Developers
Magento 2 Development for PHP DevelopersMagento 2 Development for PHP Developers
Magento 2 Development for PHP Developers
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
 
#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization
#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization
#3 Hanoi Magento Meetup - Part 3: Magento Website Optimization
 
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKKey Insights into Development Design Patterns for Magento 2 - Magento Live UK
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
 
Sito ecommerce vs marketplace
Sito ecommerce vs marketplaceSito ecommerce vs marketplace
Sito ecommerce vs marketplace
 
Vitalyi Golomoziy - Integration tests in Magento 2
Vitalyi Golomoziy - Integration tests in Magento 2Vitalyi Golomoziy - Integration tests in Magento 2
Vitalyi Golomoziy - Integration tests in Magento 2
 
Magento 2 and avoiding the rabbit hole
Magento 2 and avoiding the rabbit holeMagento 2 and avoiding the rabbit hole
Magento 2 and avoiding the rabbit hole
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Phpworld.2015 scaling magento
Phpworld.2015 scaling magentoPhpworld.2015 scaling magento
Phpworld.2015 scaling magento
 
Andrea Zwirner - Magento security and hardening strategies
Andrea Zwirner - Magento security and hardening strategiesAndrea Zwirner - Magento security and hardening strategies
Andrea Zwirner - Magento security and hardening strategies
 
Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2
 
Oleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performanceOleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performance
 
A Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to DeploymentA Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to Deployment
 
Super-scaling Magento with Docker, micro-services and micro-costs
Super-scaling Magento with Docker, micro-services and micro-costsSuper-scaling Magento with Docker, micro-services and micro-costs
Super-scaling Magento with Docker, micro-services and micro-costs
 

Similar to Code Generation in Magento 2

Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2
Sergii Shymko
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalMax Pronko
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
Darwin Biler
 
Refactor Large apps with Backbone
Refactor Large apps with BackboneRefactor Large apps with Backbone
Refactor Large apps with Backbone
devObjective
 
Refactor Large applications with Backbone
Refactor Large applications with BackboneRefactor Large applications with Backbone
Refactor Large applications with Backbone
ColdFusionConference
 
Refactoring Large Web Applications with Backbone.js
Refactoring Large Web Applications with Backbone.jsRefactoring Large Web Applications with Backbone.js
Refactoring Large Web Applications with Backbone.js
Stacy London
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBo-Yi Wu
 
Folio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP YiiFolio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP Yii
Folio3 Software
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
Francois Zaninotto
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
Sergii Shymko
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
Javier Eguiluz
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Phpfunkatron
 
Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!
Jess Chadwick
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic
 

Similar to Code Generation in Magento 2 (20)

Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_Final
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
 
Refactor Large apps with Backbone
Refactor Large apps with BackboneRefactor Large apps with Backbone
Refactor Large apps with Backbone
 
Refactor Large applications with Backbone
Refactor Large applications with BackboneRefactor Large applications with Backbone
Refactor Large applications with Backbone
 
Refactoring Large Web Applications with Backbone.js
Refactoring Large Web Applications with Backbone.jsRefactoring Large Web Applications with Backbone.js
Refactoring Large Web Applications with Backbone.js
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Folio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP YiiFolio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP Yii
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!Leveraging Continuous Integration For Fun And Profit!
Leveraging Continuous Integration For Fun And Profit!
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 

More from Sergii Shymko

Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
Sergii Shymko
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Sergii Shymko
 
Composer in Magento
Composer in MagentoComposer in Magento
Composer in Magento
Sergii Shymko
 
Magento 2 Code Migration Tool
Magento 2 Code Migration ToolMagento 2 Code Migration Tool
Magento 2 Code Migration Tool
Sergii Shymko
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
Sergii Shymko
 
Magento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin LocalizationMagento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin Localization
Sergii Shymko
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Sergii Shymko
 
Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer Evolution
Sergii Shymko
 
Magento 2 Theme Localization
Magento 2 Theme LocalizationMagento 2 Theme Localization
Magento 2 Theme Localization
Sergii Shymko
 
Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2
Sergii Shymko
 
Magento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration ToolsMagento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration Tools
Sergii Shymko
 

More from Sergii Shymko (11)

Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
 
Composer in Magento
Composer in MagentoComposer in Magento
Composer in Magento
 
Magento 2 Code Migration Tool
Magento 2 Code Migration ToolMagento 2 Code Migration Tool
Magento 2 Code Migration Tool
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
 
Magento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin LocalizationMagento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin Localization
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
 
Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer Evolution
 
Magento 2 Theme Localization
Magento 2 Theme LocalizationMagento 2 Theme Localization
Magento 2 Theme Localization
 
Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2
 
Magento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration ToolsMagento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration Tools
 

Recently uploaded

Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 

Recently uploaded (20)

Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 

Code Generation in Magento 2

  • 1.
  • 2. Code Generation in Magento 2 Sergii Shymko Senior Software Engineer Magento, an eBay Inc. company
  • 3. Legal Disclaimer Copyright © 2015 Magento, Inc. All Rights Reserved. Magento®, eBay Enterprise™ and their respective logos are trademarks, service marks, registered trademarks, or registered service marks of eBay, Inc. or its subsidiaries. Other trademarks or service marks contained in this presentation are the property of the respective companies with which they are associated. This presentation is for informational and discussion purposes only and should not be construed as a commitment of Magento, Inc. or eBay Enterprise (“eBay Enterprise”) or of any of their subsidiaries or affiliates. While we attempt to ensure the accuracy, completeness and adequacy of this presentation, neither Magento, Inc., eBay Enterprise nor any of their subsidiaries or affiliates are responsible for any errors or will be liable for the use of, or reliance upon, this presentation or any of the information contained in it. Unauthorized use, disclosure or dissemination of this information is expressly prohibited.
  • 4. Introduction to Code Generation • Automatic programming – generation of computer program • Source code generation – Generation based on template • Allows to write code at higher abstraction level • Enables aspect-oriented programming (AOP) • Enables generic programming – parameterization over types • Avoids writing boilerplate code
  • 5. Code Generation in Magento 1.x
  • 6. Code Generation in Magento 2
  • 7. Code Generation in Magento 2 • Code is generated: – On the fly (development) • Autoload non-existing class that follows naming pattern – Beforehand (production) • Run CLI tools php dev/tools/Magento/Tools/Di/compiler.php • Location of generated code: var/generation/
  • 8. Factories • Factory creates objects • Single method – create() • Used for non-injectables, i.e. entities • Isolation from Object Manager • Type safety • IDE auto-completion • Class name pattern: NamespaceClassFactory
  • 9. Factory Usage namespace MagentoCatalogModelProduct; class Copier { public function __construct( MagentoCatalogModelProductFactory $productFactory ) { $this->productFactory = $productFactory; } public function copy(MagentoCatalogModelProduct $product) { $duplicate = $this->productFactory->create(); // ... } } app/code/Magento/Catalog/Model/Product/Copier.php
  • 10. Generated Factory (Simplified) namespace MagentoCatalogModel; class ProductFactory { public function __construct( MagentoFrameworkObjectManagerInterface $objectManager ) { $this->objectManager = $objectManager; } public function create(array $data = array()) { return $this->objectManager->create( 'MagentoCatalogModelProduct', $data ); } } var/generation/Magento/Catalog/Model/ProductFactory.php
  • 11. Proxies • Implementation of GoF pattern • Follows interface of subject • Delays creation of subject – Delays creation of dependencies • Forwards calls to subject • Used for optional dependencies of DI • Class name pattern: NamespaceClassProxy
  • 12. Proxy Usage in DI Config <config> <type name="MagentoCatalogModelResourceProductCollection"> <arguments> <argument name="customerSession" xsi:type="object"> MagentoCustomerModelSessionProxy </argument> </arguments> </type> </config> app/code/Magento/Catalog/etc/di.xml
  • 13. Generated Proxy (Simplified) namespace MagentoCustomerModelSession; class Proxy extends MagentoCustomerModelSession { protected function getSubject() { if (!$this->subject) { $this->subject = $this->objectManager->get( 'MagentoCustomerModelSession' ); } return $this->subject; } public function getCustomerId() { return $this->getSubject()->getCustomerId(); } // ... } var/generation/Magento/Customer/Model/Session/Proxy.php
  • 14. Interception • Primary customization approach • AOP-like mechanism • Used for plugins • Attach behavior to public methods – Before – After – Around • Plugins declared in DI config
  • 15. Plugin Implementation namespace MagentoStoreAppActionPlugin; class StoreCheck { public function aroundDispatch( MagentoFrameworkAppActionAction $subject, Closure $proceed, MagentoFrameworkAppRequestInterface $request ) { if (!$this->storeManager->getStore()->getIsActive()) { throw new MagentoFrameworkAppInitException( 'Current store is not active.' ); } return $proceed($request); } } app/code/Magento/Store/App/Action/Plugin/StoreCheck.php
  • 16. Plugin Declaration in DI Config <config> <type name="MagentoFrameworkAppActionAction"> <plugin name="storeCheck" type="MagentoStoreAppActionPluginStoreCheck" sortOrder="10"/> </type> </config> app/code/Magento/Store/etc/di.xml
  • 17. Generated Interceptor (Simplified) namespace MagentoFrameworkAppActionAction; class Interceptor extends MagentoFrameworkAppActionAction { public function dispatch( MagentoFrameworkAppRequestInterface $request ) { $pluginInfo = $this->pluginList->getNext( 'MagentoFrameworkAppActionAction', 'dispatch' ); if (!$pluginInfo) { return parent::dispatch($request); } else { return $this->___callPlugins( 'dispatch', func_get_args(), $pluginInfo ); } } } var/generation/Magento/Framework/App/Action/Action/Interceptor.php
  • 18. Code Generation for Service Layer • Service layer – ultimate public API • Services implement stateless operations • Generated code: – Repository* – Persistor* – Search Results – Extension Attributes * – may be removed in future releases
  • 19. Generated Repository (Simplified) namespace MagentoSalesApiDataOrder; class Repository implements MagentoSalesApiOrderRepositoryInterface { public function __construct( MagentoSalesApiDataOrderInterfacePersistor $orderPersistor, MagentoSalesApiDataOrderSearchResultInterfaceFactory $searchResultFactory ) { $this->orderPersistor = $orderPersistor; $this->searchResultFactory = $searchResultFactory; } public function get($id); public function create(MagentoSalesApiDataOrderInterface $entity); public function getList(MagentoFrameworkApiSearchCriteria $criteria); public function remove(MagentoSalesApiDataOrderInterface $entity); public function flush(); } var/generation/Magento/Sales/Api/Data/Order/Repository.php
  • 20. Extension Attributes • Extension to data interfaces from 3rd party modules • Attributes declared in configuration • Attribute getters/setters generated • Type-safe attribute access • IDE auto-completion • Class name pattern: NamespaceClassExtensionInterface NamespaceClassExtension
  • 21. Declaration of Extension Attributes <config> <custom_attributes for="MagentoCatalogApiDataProductInterface"> <attribute code="price_type" type="integer" /> </custom_attributes> </config> app/code/Magento/Bundle/etc/data_object.xml
  • 22. Entity with Extension Attributes namespace MagentoCatalogApiData; interface ProductInterface extends MagentoFrameworkApiCustomAttributesDataInterface { /** * @return MagentoCatalogApiDataProductExtensionInterface|null */ public function getExtensionAttributes(); public function setExtensionAttributes( MagentoCatalogApiDataProductExtensionInterface $attributes ); // ... } app/code/Magento/Catalog/Api/Data/ProductInterface.php
  • 23. Generated Interface of Extension Attributes namespace MagentoCatalogApiData; interface ProductExtensionInterface extends MagentoFrameworkApiExtensionAttributesInterface { /** * @return integer */ public function getPriceType(); /** * @param integer $priceType * @return $this */ public function setPriceType($priceType); // ... } var/generation/Magento/Catalog/Api/Data/ProductExtensionInterface.php
  • 24. Generated Implementation of Extension Attributes namespace MagentoCatalogApiData; class ProductExtension extends MagentoFrameworkApiAbstractSimpleObject implements MagentoCatalogApiDataProductExtensionInterface { /** * @return integer */ public function getPriceType() { return $this->_get('price_type'); } /** * @param integer $priceType * @return $this */ public function setPriceType($priceType) { return $this->setData('price_type', $priceType); } // ... } var/generation/Magento/Catalog/Api/Data/ProductExtension.php
  • 25. Loggers • Implementation of GoF pattern Decorator • Activated with the profiler – Object Manager wraps instances with loggers • Tracks method call stack • Forwards calls to original methods • Class name pattern: NamespaceClassLogger
  • 26. Summary of Code Generation • DI – Factory – Proxy • Interception • Service Layer – Repository – Persistor – Search Results – Extension Attributes • Logger
  • 27. Thank You! Q & A Sergii Shymko sshymko@ebay.com
  • 28. Resources • github.com – magento/magento2 – Magento 2 Community Edition – magento/magento2-community-edition – Composer project for Magento 2 CE • devdocs.magento.com – Factories – Proxies – Plugins – Definition compilation tool

Editor's Notes

  1. Automatic programming – some mechanism generates a computer program AOP – separation of cross-cutting concerns Generic programming – style of computer programming in which algorithms are written in terms of types to-be-specified-later Generics in Java, C#, Delphi, Ada Templates in C++
  2. Magento 2 employs code generation for a number of core mechanisms
  3. Application modes: default, developer, production In addition to what “compiler.php” does “singletenant_compiler.php” also generates caches
  4. GoF creation pattern
  5. Code has been simplified
  6. Code has been simplified
  7. APO – Aspect-Oriented Programming
  8. Code has been simplified
  9. Repository – pattern of Domain-Driven Design Repository – imitates in-memory entity collection Persistor – persists entities in Repository Search Results – subset of entities in Repository Extension Attributes – extension to data interfaces
  10. Method create($entity) adds entity to repository
  11. Explicit, safe, type-safe attribute access Replacement for free-format Varien_Object