SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Magento 2 Request
Flow
Magento 2 Architect
Eugene Tulika
Entry Point
Everything starts here
Entry Point
• Index.php or pub/index.php – web application
• Static.php – retrieve dynamically generated static files
• Get.php – retrieve media from database
• Cron.php – run commands by Cron
• bin/magento – command line tool
Entry Point
require __DIR__ . '/app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication(MagentoFrameworkAppHttp::class);
$bootstrap->run($app);
/index.php
Bootstrap::createApplication
public function createApplication($type, $arguments = [])
{
$this->initObjectManager();
$application = $this->objectManager->create($type, $arguments);
// … type check
return $application;
}
/lib/internal/Magento/Framework/App/Bootstrap.php
Bootstrap::initObjectManager
• We hate init* methods. M1 was full of them
• Loads initial configuration (config.php, env.php, di.xml)
• Loads etc/di.xml files from all modules (global configuration)
• Last point where we have valid init* methods
Bootstrap::createApplication
public function createApplication($type, $arguments = [])
{
$this->initObjectManager();
$application = $this->objectManager->create($type, $arguments);
// … type check
return $application;
}
/lib/internal/Magento/Framework/App/Bootstrap.php
Entry Point
require __DIR__ . '/app/bootstrap.php';
$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication(MagentoFrameworkAppHttp::class);
$bootstrap->run($app);
/index.php
ApplicationHttp
public function launch()
{
$frontName = $this->_request->getFrontName();
$areaCode = $this->areaList->getCodeByFrontName($frontName);
$this->state->setAreaCode($areaCode);
$this->objectManager->configure($this->_configLoader->load($areaCode));
$frontController = $this->objectManager->get(FrontControllerInterface::class);
$result = $frontController->dispatch($this->_request);
$result->renderResult($this->_response);
return $this->_response;
}
/lib/internal/Magento/Framework/App/Http.php
Application Areas
• Configuration scopes
• etc/<areaCode>/* in module folder
• Loaded on top of global configuration
• Admin, Frontend, Webapi_Rest, Webapi_Soap, Cron
Middleware
Going down the rabbit hole of the onion rings
Middleware
function (request) : response
• Function applied to request in order to generate response
• PSR-7
ApplicationHttp
public function launch()
{
$frontName = $this->_request->getFrontName();
$areaCode = $this->areaList->getCodeByFrontName($frontName);
$this->state->setAreaCode($areaCode);
$this->objectManager->configure($this->_configLoader->load($areaCode));
$frontController = $this->objectManager->get(FrontControllerInterface::class);
$result = $frontController->dispatch($this->_request);
$result->renderResult($this->_response);
return $this->_response;
}
/lib/internal/Magento/Framework/App/Http.php
Middleware
Dispatch
Authentication
CSRF Checks
Page Cache
HTTP Request
HTTP Response
Middleware
• Add your plugin on front controller if you want some logic executed
on all controllers
• Keep POST & GET in mind
Routing
Front Controller
public function dispatch(RequestInterface $request){
// …
foreach ($this->routerList as $router) {
$actionInstance = $router->match($request);
if ($actionInstance) {
$result = $actionInstance->execute();
break;
}
}
// …
return $result;
}
/lib/internal/Magento/Framework/App/FrontController.php
Routing
• Every area has own set of routers
• Important routers: standard for frontend & admin for admin
• Both configured in /etc/<areaCode>/routes.xml
• Cover 95% of cases (?)
Routing
<config>
<router id="standard">
<route id=”blog" frontName=”blog">
<module name=”My_Blog" />
</route>
</router>
</config>
/My/Module/etc/frontend/routes.xml
Actions
Front Controller
public function dispatch(RequestInterface $request){
// …
foreach ($this->routerList as $router) {
$actionInstance = $router->match($request);
if ($actionInstance) {
$result = $actionInstance->execute();
break;
}
}
// …
return $result;
}
/lib/internal/Magento/Framework/App/FrontController.php
Action Controllers
• Path handlers
• Single method execute
• By convention located in Controller folder of a module
• Different rules for GET and POST
• Request object should not be passed further. Extract arguments and
pass them separately.
Action Controllers
class View extends MagentoFrameworkAppActionAction
{
// constructor and properties
public function execute()
{
// do something
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$result->setPath('*/*/*');
// or
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $result;
}
}
My/Module/Controller/Blog/Post/View.php
POST
POST Action Controllers
• Do not render pages. Layout is forbidden
• Only place for application workflow management (redirect,
messages, session)
• All business logic should be delegated to Service Contracts
• Request object should not be passed further. Extract arguments and
pass them separately.
POST Action Controller
class Save extends MagentoFrameworkAppActionAction
{
public function execute()
{
$post = $this->postFactory->create();
$post->setTitle($this->request->getParam('title'));
$post->setText($this->request->getParam('text'));
$post = $this->postRepository->save($post);
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$result->setPath(’blogs/post/view’, [’post_id' => $post->getId()]);
}
}
My/Module/Controller/Blog/Post/Save.php
Service Contracts
• Represent public API of a module
• Covered by Backwards Compatibility Policy
• Located Api folder of a module and marked with @api
• Expose procedural API (Service Interfaces) that communicate with
Data Transfer Objects (Data Interfaces)
Service Contracts
My/Module/Api/PostRepository.php
class PostRepository implements MyModuleApiPostRepositoryInterface
{
// ..
public function save(PostInterface $post)
{
$this->postResourceModel->save($post);
return $post;
}
}
Persistence
• Use Resource Models to Load/Save/Delete data
• Use Collections to load lists of data
• load, save, and delete on model are deprecated
POST Action Controller
class Save extends MagentoFrameworkAppActionAction
{
public function execute()
{
$post = $this->postFactory->create();
$post->setTitle($this->request->getParam('title'));
$post->setText($this->request->getParam('text'));
$post = $this->postRepository->save($post);
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$result->setPath(’blogs/post/view’, [’post_id' => $post->getId()]);
return $result;
}
}
My/Module/Controller/Blog/Post/Save.php
GET
GET Action Controller
class View extends MagentoFrameworkAppActionAction
{
// constructor and properties
public function execute()
{
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $result;
}
}
/app/code/My/Module/Controller/Blog/Post/View.php
GET Action Controllers
• Do not reference blocks directly. They may not exist on the page
• Do not pre-load models and put them to registry. Load what you
need from blocks.
• DO NOTHING in Action Controllers that respond to GET requests
and render pages (only return PageResult)
Layout
/My/Module/view/frontend/layout/blog_post_view.xml
<page>
<body>
<referenceBlock name="container">
<block class="MyModuleBlockBlogPostView”
name=”blog.post.view”
template=”My_Module::blog/post/view.phtml"/>
</referenceBlock>
</body>
</page>
Blocks
/My/Module/view/frontend/templates/blog/post/view.phtml
<?php $post = $block->getBlogPost(); ?>
<article>
<header>
<h1><?php echo $block->escapeHtml($post->getTitle());?></h1>
<span class="date">
<?php echo $block->formatDate($post->getPublicationDate());?>
</span>
<a href="<?php echo $block->getBlogLink($post); ?>" class="blog">
<?php echo $block->escapeHtml(__('To Blog'));?>
</a>
</header>
<?php echo $post->getText(); ?>
</article>
Blocks
namespace MyModuleBlockBlogPost;
class View
{
public function getBlogPost()
{
return $this->postRepository->get($this->request->getParam('post_id'));
}
public function getBlogLink(Post $post)
{
$this->urlBuilder->getUrl('blogs', ['blog_id' => $post->getBlogId()]);
}
}
/My/Module/Block/Blog/Post/View.php
Blocks
/My/Module/view/frontend/templates/blog/post/view.phtml
<?php $post = $block->getBlogPost(); ?>
<article>
<header>
<h1><?php echo $block->escapeHtml($post->getTitle());?></h1>
<span class="date">
<?php echo $block->formatDate($post->getPublicationDate());?>
</span>
<a href="<?php echo $block->getBlogLink($post); ?>" class="blog">
<?php echo $block->escapeHtml(__('To Blog'));?>
</a>
</header>
<?php echo $post->getText(); ?>
</article>
Blocks
• Do not reference other sibling and parent blocks
• Do not perform state-modifications
• Retrieve data from public services
• Do not pass Request object further, extract arguments, and pass
them
Response
Action Results
namespace MagentoFrameworkController;
class ResultFactory
{
const TYPE_JSON = 'json';
const TYPE_RAW = 'raw';
const TYPE_REDIRECT = 'redirect';
const TYPE_FORWARD = 'forward';
const TYPE_LAYOUT = 'layout';
const TYPE_PAGE = 'page';
public function create($type, array $arguments = [])
{
// ...
return $resultInstance;
}
}
/lib/internal/Magento/Framework/Controller/ResultFactory.php
GET Action Controller
class View extends MagentoFrameworkAppActionAction
{
// constructor and properties
public function execute()
{
$result = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $result;
}
}
/app/code/My/Module/Controller/Blog/Post/View.php
ApplicationHttp
public function launch()
{
$frontName = $this->_request->getFrontName();
$areaCode = $this->areaList->getCodeByFrontName($frontName);
$this->state->setAreaCode($areaCode);
$this->objectManager->configure($this->_configLoader->load($areaCode));
$frontController = $this->objectManager->get(FrontControllerInterface::class);
$result = $frontController->dispatch($this->_request);
$result->renderResult($this->_response);
return $this->_response;
}
/lib/internal/Magento/Framework/App/Http.php
Q & A

Weitere ähnliche Inhalte

Was ist angesagt?

Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationBrent Shaffer
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
Curso Symfony - Clase 3
Curso Symfony - Clase 3Curso Symfony - Clase 3
Curso Symfony - Clase 3Javier Eguiluz
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriCodeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriAbdul Malik Ikhsan
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkJeremy Kendall
 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in EmberMatthew Beale
 
How routing works in angular js
How routing works in angular jsHow routing works in angular js
How routing works in angular jscodeandyou forums
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And NavigationEyal Vardi
 
Ember and containers
Ember and containersEmber and containers
Ember and containersMatthew Beale
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonKris Wallsmith
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 
sfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin BundlesfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin Bundleth0masr
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.jscodeofficer
 

Was ist angesagt? (20)

Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes Presentation
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Jquery Fundamentals
Jquery FundamentalsJquery Fundamentals
Jquery Fundamentals
 
Matters of State
Matters of StateMatters of State
Matters of State
 
Curso Symfony - Clase 3
Curso Symfony - Clase 3Curso Symfony - Clase 3
Curso Symfony - Clase 3
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
Codeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate UriCodeigniter : Custom Routing - Manipulate Uri
Codeigniter : Custom Routing - Manipulate Uri
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Complex Architectures in Ember
Complex Architectures in EmberComplex Architectures in Ember
Complex Architectures in Ember
 
How routing works in angular js
How routing works in angular jsHow routing works in angular js
How routing works in angular js
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Ember and containers
Ember and containersEmber and containers
Ember and containers
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 
sfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin BundlesfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin Bundle
 
An introduction to Ember.js
An introduction to Ember.jsAn introduction to Ember.js
An introduction to Ember.js
 

Ähnlich wie Magento Live Australia 2016: Request Flow

symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHendy Irawan
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance ToolkitSergii Shymko
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extensionHendy Irawan
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency InjectionAnton Kril
 
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 UKMax Pronko
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 

Ähnlich wie Magento Live Australia 2016: Request Flow (20)

symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento Extension
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extension
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 
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
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 

Mehr von Vrann Tulika

Magento Web API Ecosystem. Imagine 2018
Magento Web API Ecosystem. Imagine 2018Magento Web API Ecosystem. Imagine 2018
Magento Web API Ecosystem. Imagine 2018Vrann Tulika
 
Career of the Software Engineer in Modern Open-Source e-Commerce Company
Career of the Software Engineer in Modern Open-Source e-Commerce CompanyCareer of the Software Engineer in Modern Open-Source e-Commerce Company
Career of the Software Engineer in Modern Open-Source e-Commerce CompanyVrann Tulika
 
Magento Live Australia 2016 Facebook Chatbot for Magento
Magento Live Australia 2016 Facebook Chatbot for MagentoMagento Live Australia 2016 Facebook Chatbot for Magento
Magento Live Australia 2016 Facebook Chatbot for MagentoVrann Tulika
 
Mage Titans USA 2016 Magento/Facebook/RabbitMQ
Mage Titans USA 2016 Magento/Facebook/RabbitMQMage Titans USA 2016 Magento/Facebook/RabbitMQ
Mage Titans USA 2016 Magento/Facebook/RabbitMQVrann Tulika
 
Enterprise Patterns in Magento
Enterprise Patterns in MagentoEnterprise Patterns in Magento
Enterprise Patterns in MagentoVrann Tulika
 
Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...
Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...
Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...Vrann Tulika
 
PHP and Asynchronous Systems
PHP and Asynchronous SystemsPHP and Asynchronous Systems
PHP and Asynchronous SystemsVrann Tulika
 

Mehr von Vrann Tulika (7)

Magento Web API Ecosystem. Imagine 2018
Magento Web API Ecosystem. Imagine 2018Magento Web API Ecosystem. Imagine 2018
Magento Web API Ecosystem. Imagine 2018
 
Career of the Software Engineer in Modern Open-Source e-Commerce Company
Career of the Software Engineer in Modern Open-Source e-Commerce CompanyCareer of the Software Engineer in Modern Open-Source e-Commerce Company
Career of the Software Engineer in Modern Open-Source e-Commerce Company
 
Magento Live Australia 2016 Facebook Chatbot for Magento
Magento Live Australia 2016 Facebook Chatbot for MagentoMagento Live Australia 2016 Facebook Chatbot for Magento
Magento Live Australia 2016 Facebook Chatbot for Magento
 
Mage Titans USA 2016 Magento/Facebook/RabbitMQ
Mage Titans USA 2016 Magento/Facebook/RabbitMQMage Titans USA 2016 Magento/Facebook/RabbitMQ
Mage Titans USA 2016 Magento/Facebook/RabbitMQ
 
Enterprise Patterns in Magento
Enterprise Patterns in MagentoEnterprise Patterns in Magento
Enterprise Patterns in Magento
 
Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...
Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...
Розпаралелювання Програм на Фортрані з Використанням Техніки Переписувальних ...
 
PHP and Asynchronous Systems
PHP and Asynchronous SystemsPHP and Asynchronous Systems
PHP and Asynchronous Systems
 

Kürzlich hochgeladen

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Magento Live Australia 2016: Request Flow

  • 1.
  • 5. Entry Point • Index.php or pub/index.php – web application • Static.php – retrieve dynamically generated static files • Get.php – retrieve media from database • Cron.php – run commands by Cron • bin/magento – command line tool
  • 6. Entry Point require __DIR__ . '/app/bootstrap.php'; $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER); $app = $bootstrap->createApplication(MagentoFrameworkAppHttp::class); $bootstrap->run($app); /index.php
  • 7. Bootstrap::createApplication public function createApplication($type, $arguments = []) { $this->initObjectManager(); $application = $this->objectManager->create($type, $arguments); // … type check return $application; } /lib/internal/Magento/Framework/App/Bootstrap.php
  • 8. Bootstrap::initObjectManager • We hate init* methods. M1 was full of them • Loads initial configuration (config.php, env.php, di.xml) • Loads etc/di.xml files from all modules (global configuration) • Last point where we have valid init* methods
  • 9. Bootstrap::createApplication public function createApplication($type, $arguments = []) { $this->initObjectManager(); $application = $this->objectManager->create($type, $arguments); // … type check return $application; } /lib/internal/Magento/Framework/App/Bootstrap.php
  • 10. Entry Point require __DIR__ . '/app/bootstrap.php'; $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER); $app = $bootstrap->createApplication(MagentoFrameworkAppHttp::class); $bootstrap->run($app); /index.php
  • 11. ApplicationHttp public function launch() { $frontName = $this->_request->getFrontName(); $areaCode = $this->areaList->getCodeByFrontName($frontName); $this->state->setAreaCode($areaCode); $this->objectManager->configure($this->_configLoader->load($areaCode)); $frontController = $this->objectManager->get(FrontControllerInterface::class); $result = $frontController->dispatch($this->_request); $result->renderResult($this->_response); return $this->_response; } /lib/internal/Magento/Framework/App/Http.php
  • 12. Application Areas • Configuration scopes • etc/<areaCode>/* in module folder • Loaded on top of global configuration • Admin, Frontend, Webapi_Rest, Webapi_Soap, Cron
  • 13. Middleware Going down the rabbit hole of the onion rings
  • 14. Middleware function (request) : response • Function applied to request in order to generate response • PSR-7
  • 15. ApplicationHttp public function launch() { $frontName = $this->_request->getFrontName(); $areaCode = $this->areaList->getCodeByFrontName($frontName); $this->state->setAreaCode($areaCode); $this->objectManager->configure($this->_configLoader->load($areaCode)); $frontController = $this->objectManager->get(FrontControllerInterface::class); $result = $frontController->dispatch($this->_request); $result->renderResult($this->_response); return $this->_response; } /lib/internal/Magento/Framework/App/Http.php
  • 17. Middleware • Add your plugin on front controller if you want some logic executed on all controllers • Keep POST & GET in mind
  • 19. Front Controller public function dispatch(RequestInterface $request){ // … foreach ($this->routerList as $router) { $actionInstance = $router->match($request); if ($actionInstance) { $result = $actionInstance->execute(); break; } } // … return $result; } /lib/internal/Magento/Framework/App/FrontController.php
  • 20. Routing • Every area has own set of routers • Important routers: standard for frontend & admin for admin • Both configured in /etc/<areaCode>/routes.xml • Cover 95% of cases (?)
  • 21. Routing <config> <router id="standard"> <route id=”blog" frontName=”blog"> <module name=”My_Blog" /> </route> </router> </config> /My/Module/etc/frontend/routes.xml
  • 23. Front Controller public function dispatch(RequestInterface $request){ // … foreach ($this->routerList as $router) { $actionInstance = $router->match($request); if ($actionInstance) { $result = $actionInstance->execute(); break; } } // … return $result; } /lib/internal/Magento/Framework/App/FrontController.php
  • 24. Action Controllers • Path handlers • Single method execute • By convention located in Controller folder of a module • Different rules for GET and POST • Request object should not be passed further. Extract arguments and pass them separately.
  • 25. Action Controllers class View extends MagentoFrameworkAppActionAction { // constructor and properties public function execute() { // do something $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $result->setPath('*/*/*'); // or $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); return $result; } } My/Module/Controller/Blog/Post/View.php
  • 26. POST
  • 27. POST Action Controllers • Do not render pages. Layout is forbidden • Only place for application workflow management (redirect, messages, session) • All business logic should be delegated to Service Contracts • Request object should not be passed further. Extract arguments and pass them separately.
  • 28. POST Action Controller class Save extends MagentoFrameworkAppActionAction { public function execute() { $post = $this->postFactory->create(); $post->setTitle($this->request->getParam('title')); $post->setText($this->request->getParam('text')); $post = $this->postRepository->save($post); $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $result->setPath(’blogs/post/view’, [’post_id' => $post->getId()]); } } My/Module/Controller/Blog/Post/Save.php
  • 29. Service Contracts • Represent public API of a module • Covered by Backwards Compatibility Policy • Located Api folder of a module and marked with @api • Expose procedural API (Service Interfaces) that communicate with Data Transfer Objects (Data Interfaces)
  • 30. Service Contracts My/Module/Api/PostRepository.php class PostRepository implements MyModuleApiPostRepositoryInterface { // .. public function save(PostInterface $post) { $this->postResourceModel->save($post); return $post; } }
  • 31. Persistence • Use Resource Models to Load/Save/Delete data • Use Collections to load lists of data • load, save, and delete on model are deprecated
  • 32. POST Action Controller class Save extends MagentoFrameworkAppActionAction { public function execute() { $post = $this->postFactory->create(); $post->setTitle($this->request->getParam('title')); $post->setText($this->request->getParam('text')); $post = $this->postRepository->save($post); $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $result->setPath(’blogs/post/view’, [’post_id' => $post->getId()]); return $result; } } My/Module/Controller/Blog/Post/Save.php
  • 33. GET
  • 34. GET Action Controller class View extends MagentoFrameworkAppActionAction { // constructor and properties public function execute() { $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); return $result; } } /app/code/My/Module/Controller/Blog/Post/View.php
  • 35. GET Action Controllers • Do not reference blocks directly. They may not exist on the page • Do not pre-load models and put them to registry. Load what you need from blocks. • DO NOTHING in Action Controllers that respond to GET requests and render pages (only return PageResult)
  • 37. Blocks /My/Module/view/frontend/templates/blog/post/view.phtml <?php $post = $block->getBlogPost(); ?> <article> <header> <h1><?php echo $block->escapeHtml($post->getTitle());?></h1> <span class="date"> <?php echo $block->formatDate($post->getPublicationDate());?> </span> <a href="<?php echo $block->getBlogLink($post); ?>" class="blog"> <?php echo $block->escapeHtml(__('To Blog'));?> </a> </header> <?php echo $post->getText(); ?> </article>
  • 38. Blocks namespace MyModuleBlockBlogPost; class View { public function getBlogPost() { return $this->postRepository->get($this->request->getParam('post_id')); } public function getBlogLink(Post $post) { $this->urlBuilder->getUrl('blogs', ['blog_id' => $post->getBlogId()]); } } /My/Module/Block/Blog/Post/View.php
  • 39. Blocks /My/Module/view/frontend/templates/blog/post/view.phtml <?php $post = $block->getBlogPost(); ?> <article> <header> <h1><?php echo $block->escapeHtml($post->getTitle());?></h1> <span class="date"> <?php echo $block->formatDate($post->getPublicationDate());?> </span> <a href="<?php echo $block->getBlogLink($post); ?>" class="blog"> <?php echo $block->escapeHtml(__('To Blog'));?> </a> </header> <?php echo $post->getText(); ?> </article>
  • 40. Blocks • Do not reference other sibling and parent blocks • Do not perform state-modifications • Retrieve data from public services • Do not pass Request object further, extract arguments, and pass them
  • 42. Action Results namespace MagentoFrameworkController; class ResultFactory { const TYPE_JSON = 'json'; const TYPE_RAW = 'raw'; const TYPE_REDIRECT = 'redirect'; const TYPE_FORWARD = 'forward'; const TYPE_LAYOUT = 'layout'; const TYPE_PAGE = 'page'; public function create($type, array $arguments = []) { // ... return $resultInstance; } } /lib/internal/Magento/Framework/Controller/ResultFactory.php
  • 43. GET Action Controller class View extends MagentoFrameworkAppActionAction { // constructor and properties public function execute() { $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); return $result; } } /app/code/My/Module/Controller/Blog/Post/View.php
  • 44. ApplicationHttp public function launch() { $frontName = $this->_request->getFrontName(); $areaCode = $this->areaList->getCodeByFrontName($frontName); $this->state->setAreaCode($areaCode); $this->objectManager->configure($this->_configLoader->load($areaCode)); $frontController = $this->objectManager->get(FrontControllerInterface::class); $result = $frontController->dispatch($this->_request); $result->renderResult($this->_response); return $this->_response; } /lib/internal/Magento/Framework/App/Http.php
  • 45. Q & A

Hinweis der Redaktion

  1. Request flow process governs the application
  2. Changed to bin/mageno Magento has multiple entrypoints Depends on the client
  3. Creates the instance of application
  4. What is type check? Initializes Object Manager
  5. Init is not a good pattern, it encourages temporal coupling What does it mean “Last point where we have valid init* methods?”
  6. Creates application object using object manager DI is already initialized; all the plugins and preferences will be picked up
  7. Runs application
  8. Load areas
  9. Area defines scopes of configuration Allows to configure frontend and backend differently Area distinguishes different parts of application
  10. Anything special about this screenshot? - In order to separate the concerns, all custom logic applicable to all controllers should be added as plugins to the front controller - This follows AOP approach - Some logic might be applicable to POST only, like CSRF
  11. Front controller invokes routing logic
  12. Custom routes can be created Most likely standard ones will only be needed Admin routes takes into account “admin” part of the url
  13. Configuration of the route which tells that blog part of url will invoke action controllers in My_Blog module
  14. Request routing searches for action controller based on the request url Once request is routed it means that action controller is found Front controller invokes action controller
  15. What is “Path handlers”?
  16. Action Controller creates Response based on Request We will talk more on types of responses later
  17. This is ideal GET action controller
  18. Layout defines which blocks are on the page requested by GET Block are referenced by Layout object based on this declaration
  19. Template is the place where most of the request processing logic happens on GET
  20. Block should have just methods needed by the template to render Block should not have generic methods to render itself. It should be injected with the helper classes instead We are moving to direction where block is a generic class and all the functions are injected as dependencies Block should not implement this logic by itself, it should delegate calls to more appropriate classes
  21. Template renders information which block provides
  22. Result is representation of HTTP response Different Results can be created by Action controller
  23. Action controller returns result
  24. Application get result from the middleware and renders it