Code generation in Magento 2 automatically generates code to handle dependency injection, interception, and the service layer. Key types of generated code include factories for object instantiation, proxies for optional dependencies, interceptors for plugins, repositories for the service layer, extension attributes, and loggers. This code generation improves abstraction, avoids boilerplate code, and enables features like dependency injection, aspect-oriented programming and generic programming in Magento 2.
This presentation is about real examples of Design Patterns usage in Magento 2. There are 2 major architectural goals set for Magento 2 project:
1. Enable streamline customisations.
2. Simplify external integrations.
There are much more Design Patterns used in Magento 2, some of them are discussed in the deck.
Magento 2 Dependency Injection, Interceptors, and You - php[world] 2015Joshua Warren
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.
Finding Your Way: Understanding Magento CodeBen Marks
With millions of lines of code, an unconventional approach to MVC framework architecture, and unique concepts such as layout XML, Magento can be intimidating for the new developer and even difficult for experienced Magento developers. This talk aims to help developers find answers in the codebase by breaking down the technologies, design patterns, and module structure into intuitive chunks. Starting with a high level view of Magento's MVC implementation, a pre-developed module is dissected in order to demonstrate various areas of the framework as well as the application-level settings and features which can thwart (or aide!) developers.
Topics covered include the following:
* MVC theory as implemented by Magento, especially the thin-controller, fat-view concept
* Overall module architecture * Finding method definitions when grep won't work, aka "when __call() strikes"
* Identifying poor-performing code using native code profiling tools
* An infallible (well, nearly-infallible) flowchart for finding problematic code
* Essential developer preparations
This presentation is about real examples of Design Patterns usage in Magento 2. There are 2 major architectural goals set for Magento 2 project:
1. Enable streamline customisations.
2. Simplify external integrations.
There are much more Design Patterns used in Magento 2, some of them are discussed in the deck.
Magento 2 Dependency Injection, Interceptors, and You - php[world] 2015Joshua Warren
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.
Finding Your Way: Understanding Magento CodeBen Marks
With millions of lines of code, an unconventional approach to MVC framework architecture, and unique concepts such as layout XML, Magento can be intimidating for the new developer and even difficult for experienced Magento developers. This talk aims to help developers find answers in the codebase by breaking down the technologies, design patterns, and module structure into intuitive chunks. Starting with a high level view of Magento's MVC implementation, a pre-developed module is dissected in order to demonstrate various areas of the framework as well as the application-level settings and features which can thwart (or aide!) developers.
Topics covered include the following:
* MVC theory as implemented by Magento, especially the thin-controller, fat-view concept
* Overall module architecture * Finding method definitions when grep won't work, aka "when __call() strikes"
* Identifying poor-performing code using native code profiling tools
* An infallible (well, nearly-infallible) flowchart for finding problematic code
* Essential developer preparations
Slides of the Magento Fireside Chat March 20th, 2014 with
Fabrizio Branca (@fbrnc)
Bastian Ike (@b_ike)
Daniel Fahlke (@flyingmana)
Rolando Granadino (@beeplogic)
Ben Marks (@benmarks)
Sander Mak - Keeping Up With Java - Codemotion Rome 2019Codemotion
It seems like keeping up with Java nowadays is an enormous task. Gone is the era of big, delayed Java releases. We’re now getting a new major release every 6 months. What’s up with that? You’re probably still developing on Java 8, even though Java 12 is already available. Join this session to get an overview of what’s new in Java since Java 8. We’ll give an overview of the module system and other new features in Java 9, the local-variable type inference feature (`var` in Java 10), and the new HttpClient API (Java 11). It’s time to embrace the newfound agility of the Java platform!
Yii - Next level PHP Framework von Florian FackerMayflower GmbH
Einblicke in ein Aussenseiter-PHP-Framework, das mit etlichen Features den Grossen eine Nasenlänge voraus ist. Anhand von praktischen Beispielen wird gezeigt, wie schnell sich mit Yii ein Projekt realisieren lässt. Dem ganzen folgt noch eine Cookbook-Blog-Reihe.
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...Meet Magento Italy
Ogni specialista Magento si è trovato almeno una volta di fronte alla richiesta di realizzare un configuratore prodotto. Spesso avrà soddisfatto l’esigenza costruendo una soluzione completamente personalizzata, adatta esclusivamente a quell’esigenza, rigida a qualsiasi modifica e difficile da manutenere.
Lo speech è incentrato sull’approccio e sulle tecniche applicabili per evitare queste problematiche e tratterà quindi di:
corretta modellazione prodotto;
estensione delle custom option;
ottimizzazione performance;
standard di integrazione dati Magento / azienda;
tecniche di realizzazione frontend.
Una serie di accorgimenti, soluzioni e best practices calate all’interno di alcuni case history reali.
Get things done with Yii - quickly build webapplicationsGiuliano Iacobelli
Lesson teached at Università di Roma Tre - Software Engineering course.
Web is plenty of amazing tools used daily by millions of people. A good idea can turn to be a highly profitable business if well executed. Yii framework is an ideal tool to build in short time an MVP of your product to start as soon as possible to find your market fit. Here follows some infos about the framework and steps on how to build a simple blog over Yii.
Magento 2 Performance: Every Second CountsJoshua Warren
On the web, every second counts. Studies have shown that a 1 second delay in load time can cost a mid-sized eCommerce company $2.5 million per year in lost revenue. Let’s look at what Magento 2 has done to improve performance and how we can take things a step further to ensure the Magento 2 sites we build and maintain are well designed, well written and very, very fast.
Presented at php[world] 2016.
A high level overview of how a web application like Magento 2 CE/EE can be split up into a set of manageable MicroServices using Docker Containers. The resultant application will be fast, platform independent, portable, repeatable/scale-able and manageable, resulting in an immensely simplified DevOps.
Slides of the Magento Fireside Chat March 20th, 2014 with
Fabrizio Branca (@fbrnc)
Bastian Ike (@b_ike)
Daniel Fahlke (@flyingmana)
Rolando Granadino (@beeplogic)
Ben Marks (@benmarks)
Sander Mak - Keeping Up With Java - Codemotion Rome 2019Codemotion
It seems like keeping up with Java nowadays is an enormous task. Gone is the era of big, delayed Java releases. We’re now getting a new major release every 6 months. What’s up with that? You’re probably still developing on Java 8, even though Java 12 is already available. Join this session to get an overview of what’s new in Java since Java 8. We’ll give an overview of the module system and other new features in Java 9, the local-variable type inference feature (`var` in Java 10), and the new HttpClient API (Java 11). It’s time to embrace the newfound agility of the Java platform!
Yii - Next level PHP Framework von Florian FackerMayflower GmbH
Einblicke in ein Aussenseiter-PHP-Framework, das mit etlichen Features den Grossen eine Nasenlänge voraus ist. Anhand von praktischen Beispielen wird gezeigt, wie schnell sich mit Yii ein Projekt realisieren lässt. Dem ganzen folgt noch eine Cookbook-Blog-Reihe.
Francesco Zoccarato - Configuratori prodotto: soluzioni e tecniche per un'imp...Meet Magento Italy
Ogni specialista Magento si è trovato almeno una volta di fronte alla richiesta di realizzare un configuratore prodotto. Spesso avrà soddisfatto l’esigenza costruendo una soluzione completamente personalizzata, adatta esclusivamente a quell’esigenza, rigida a qualsiasi modifica e difficile da manutenere.
Lo speech è incentrato sull’approccio e sulle tecniche applicabili per evitare queste problematiche e tratterà quindi di:
corretta modellazione prodotto;
estensione delle custom option;
ottimizzazione performance;
standard di integrazione dati Magento / azienda;
tecniche di realizzazione frontend.
Una serie di accorgimenti, soluzioni e best practices calate all’interno di alcuni case history reali.
Get things done with Yii - quickly build webapplicationsGiuliano Iacobelli
Lesson teached at Università di Roma Tre - Software Engineering course.
Web is plenty of amazing tools used daily by millions of people. A good idea can turn to be a highly profitable business if well executed. Yii framework is an ideal tool to build in short time an MVP of your product to start as soon as possible to find your market fit. Here follows some infos about the framework and steps on how to build a simple blog over Yii.
Magento 2 Performance: Every Second CountsJoshua Warren
On the web, every second counts. Studies have shown that a 1 second delay in load time can cost a mid-sized eCommerce company $2.5 million per year in lost revenue. Let’s look at what Magento 2 has done to improve performance and how we can take things a step further to ensure the Magento 2 sites we build and maintain are well designed, well written and very, very fast.
Presented at php[world] 2016.
A high level overview of how a web application like Magento 2 CE/EE can be split up into a set of manageable MicroServices using Docker Containers. The resultant application will be fast, platform independent, portable, repeatable/scale-able and manageable, resulting in an immensely simplified DevOps.
Ups and Downs of Real Projects Based on Magento 2Max Pronko
During 2016 our “The Irish Store” team has been focused on our eCommerce website relaunch based on the Magento 2 project. There were different decisions made for development of new functionality and porting existing ones and hitting target release date. In this presentation you will hear a lot about how we achieved the milestone. I will also share lessons learned for future Magento 2 projects.
Magento 2 Theme Trainning for Beginners | MagenestMagenest
Whoever you are an extension or theme developer, you should spend time reading this slide post because you’ll understand more about theme and template structure in Magento 2.
Magento 2 Development for PHP DevelopersJoshua Warren
As one of the most popular eCommerce platforms in the world, the demand for Magento developer is at an all-time high. In this tutorial, I’ll introduce you to developing for Magento 2 and help you get up to speed quickly so that you’re ready to support and extend existing Magento 2 sites.
Presented as a 3.5 hour tutorial at php[world] 2016.
Key Insights into Development Design Patterns for Magento 2 - Magento Live UKMax Pronko
I have had a chance to speak at Magento Live UK 2016 with topic "Key Insights into Development Design Patterns for Magento 2". Feel free to share, comment, provide feedback.
In the deck i highlight Development Design Patterns used in Magento 2. I also speak about Aspect Oriented Programming and how it affected Magento 2 implementation.
More about Magento 2 read at my blog: https://www.maxpronko.com/
I pro e i contro dei due differenti approcci all’e-commerce. Evento organizzato da Giovani Imprenditori ConfCommercio Umbria con il supporto di Assintel Umbria
In the talk we has discussed how integration tests are structured in Magento 2, main elements of integration tests framework, will see an example of an integration test.
We has talked about an impact of integration tests to a project quality and timeline.
We has also compared integration and unit tests, discussed pros and cons of each type of testing.
Magento 2 has brought the Magento community up to date with modern best practices and technology, which consequently means a learning curve, even for people who are very experienced with Magento 1. In this talk I will walk through some of my experiences so far in working with Magento 2, specifically focussed on the debugging side and how I use the pomodoro technique to avoid getting stuck down the rabbit hole.
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceIvan Chepurnyi
It is a pity, but I have to admit, that Magento 2 has issues in layout generation process. You'll learn during the talk about the benefits of compiling XML structures into PHP code, and even use the compilation of PHP code into PHP code to speed up your modules complex logic.
Andrea Zwirner - Magento security and hardening strategiesMeet Magento Italy
Starting from a fresh installation of Magento on Linux, we have conducted the common steps of a cyber-attack, through both ways of running automatic tools and performing manual penetration tests, in order to analyze the security features of the platform on it’s default configuration in a standard environment.
Addressing the security features of the platform with the simulation of both automated and targeted attacks, the study has the goal of discover it’s average level of security, in order to better understand which are the security patterns offered “by design” and where to intervene with specific hardening configuration and strategies when comes the time of customizing, deploying and maintain a Magento production environment.
Real use cases of performance optimization in magento 2Max Pronko
Is performance in Magento 2 the same as or slower than Magento 1? There are lots of discussions and debates about Magento 2’s performance. All debates are around sample data and Vanilla platform comparison. In this topic Max will share optimisations techniques to have solid page load times for Magento 2.
Also visit my blog: www.maxpronko.com
Oleh Kobchenko - Configure Magento 2 to get maximum performanceMeet Magento Italy
Magento 2 is qualitatively new product in world of e-commerce. Providing new opportunities for extensibility, configurability and scalability of your store M2 also brings list of performance improvements.
This presentation is devoted to main performance features available in product, their activation and usage.
Speaker dives into details on how to setup environment and Magento itself to get the best result in terms of page response and throughput.
A Successful Magento Project From Design to DeploymentJoshua Warren
Magento is a complex open source eCommerce platform. It’s open source nature and welcoming community means anyone can pick it up, learn it and launch it. After working on over 300 different Magento sites in the past 6 years, however, I’ve learned that many of the misconceptions about Magento - it’s slow, hard to work with, buggy or unstable come from projects that were built by first-timers who weren’t aware of Magento best practices. In this tutorial, I walk you through the entire process of creating, testing and deploying a high-performing, fast Magento-based eCommerce website.
Building Large Scale PHP Web Applications with Laravel 4Darwin Biler
Learn how Laravel 4 can be leveraged to its fullest by making use of its powerful design patterns, specifically IoC Container and Dependency Injection.
Refactoring Large Web Applications with Backbone.jsStacy London
Have you ever starting working on a large, existing web application and jQuery spaghetti-code is all over the place? Your mind swirls as you try to figure out what code belongs to what component on what page. There are no JavaScript unit tests and you're terrified of making a change and breaking everything? I'm going to talk through the real life story of how Backbone.js helped to bring organization/structure, modularity, and testability to a large multi-page web application.
This workshop is a hands-on training where a real Zend Framework application is used as an example to start improving QA using tools to test, document and perform software metric calculations to indicate where the software can be improved. I also explain the reports produced by a CI system.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
Online aptitude test management system project report.pdfKamal Acharya
The purpose of on-line aptitude test system is to take online test in an efficient manner and no time wasting for checking the paper. The main objective of on-line aptitude test system is to efficiently evaluate the candidate thoroughly through a fully automated system that not only saves lot of time but also gives fast results. For students they give papers according to their convenience and time and there is no need of using extra thing like paper, pen etc. This can be used in educational institutions as well as in corporate world. Can be used anywhere any time as it is a web based application (user Location doesn’t matter). No restriction that examiner has to be present when the candidate takes the test.
Every time when lecturers/professors need to conduct examinations they have to sit down think about the questions and then create a whole new set of questions for each and every exam. In some cases the professor may want to give an open book online exam that is the student can take the exam any time anywhere, but the student might have to answer the questions in a limited time period. The professor may want to change the sequence of questions for every student. The problem that a student has is whenever a date for the exam is declared the student has to take it and there is no way he can take it at some other time. This project will create an interface for the examiner to create and store questions in a repository. It will also create an interface for the student to take examinations at his convenience and the questions and/or exams may be timed. Thereby creating an application which can be used by examiners and examinee’s simultaneously.
Examination System is very useful for Teachers/Professors. As in the teaching profession, you are responsible for writing question papers. In the conventional method, you write the question paper on paper, keep question papers separate from answers and all this information you have to keep in a locker to avoid unauthorized access. Using the Examination System you can create a question paper and everything will be written to a single exam file in encrypted format. You can set the General and Administrator password to avoid unauthorized access to your question paper. Every time you start the examination, the program shuffles all the questions and selects them randomly from the database, which reduces the chances of memorizing the questions.
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Water billing management system project report.pdfKamal Acharya
Our project entitled “Water Billing Management System” aims is to generate Water bill with all the charges and penalty. Manual system that is employed is extremely laborious and quite inadequate. It only makes the process more difficult and hard.
The aim of our project is to develop a system that is meant to partially computerize the work performed in the Water Board like generating monthly Water bill, record of consuming unit of water, store record of the customer and previous unpaid record.
We used HTML/PHP as front end and MYSQL as back end for developing our project. HTML is primarily a visual design environment. We can create a android application by designing the form and that make up the user interface. Adding android application code to the form and the objects such as buttons and text boxes on them and adding any required support code in additional modular.
MySQL is free open source database that facilitates the effective management of the databases by connecting them to the software. It is a stable ,reliable and the powerful solution with the advanced features and advantages which are as follows: Data Security.MySQL is free open source database that facilitates the effective management of the databases by connecting them to the software.
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesChristina Lin
Traditionally, dealing with real-time data pipelines has involved significant overhead, even for straightforward tasks like data transformation or masking. However, in this talk, we’ll venture into the dynamic realm of WebAssembly (WASM) and discover how it can revolutionize the creation of stateless streaming pipelines within a Kafka (Redpanda) broker. These pipelines are adept at managing low-latency, high-data-volume scenarios.
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
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
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
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++
Magento 2 employs code generation for a number of core mechanisms
Application modes: default, developer, production
In addition to what “compiler.php” does “singletenant_compiler.php” also generates caches
GoF creation pattern
Code has been simplified
Code has been simplified
APO – Aspect-Oriented Programming
Code has been simplified
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
Method create($entity) adds entity to repository
Explicit, safe, type-safe attribute access
Replacement for free-format Varien_Object