Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
48ec27d
Enhancements for CLI section (argument and option added)
snowcore Oct 5, 2018
4690e26
Utilize modes and application initialization
simpleadm Oct 7, 2018
e0e8e66
Utilize modes and application initialization
simpleadm Oct 7, 2018
434715c
Update 3. Utilize configuration XML and variables scope.md
simpleadm Oct 15, 2018
e90669f
Merge pull request #13 from snowcore/cli-enhancements
simpleadm Oct 18, 2018
d557344
Corrected parent class name for cron config + minor formatting
snowcore Oct 18, 2018
3fffd25
Merge pull request #14 from snowcore/fix/cron-config-class
simpleadm Oct 19, 2018
34b438d
Update 2. Demonstrate ability to process URLs in Magento.md
simpleadm Oct 19, 2018
e9dc91f
Update 2. Demonstrate ability to process URLs in Magento.md
simpleadm Oct 19, 2018
31b6561
Update 2. Demonstrate ability to process URLs in Magento.md
simpleadm Oct 19, 2018
e52ca32
Update 3. Demonstrate ability to customize request routing.md
simpleadm Oct 19, 2018
2c025f7
Update 3. Demonstrate ability to customize request routing.md
simpleadm Oct 19, 2018
77bb5b4
Fixed typos in "Request Flow Processing" chapter
snowcore Oct 20, 2018
64ef76f
Merge pull request #15 from snowcore/fix/request-flow
simpleadm Oct 21, 2018
e8c296c
Added link to the official routing-related docs
snowcore Oct 31, 2018
c9e4f3b
Merge pull request #16 from snowcore/feature/doc-link
simpleadm Oct 31, 2018
1074f48
Minor typos corrected
snowcore Nov 1, 2018
50a5af8
Additional fixes to UI section
snowcore Nov 5, 2018
d3eea58
Merge pull request #17 from snowcore/fix/layout-init
simpleadm Nov 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
- `address_formats.xml`
- `address_types.xml` - format code and title only
- `cache.xml` - name, instance - e.g. full_page=Page Cache
- `catalog_attributes.xml` - catalog_category, catalog_product, unassignable, used_in_autogeneration, quote_item
- `catalog_attributes.xml` - catalog_category, catalog_product, unassignable, used_in_autogeneration, quote_item [*](https://www.atwix.com/magento-2/how-to-access-custom-catalog-attributes/)
- `communication.xml`
- `config.xml` - defaults
- `crontab.xml` - group[], job instance, method, schedule
- `cron_groups.xml`
- `di.xml` - preference, plugins, virtual type
- `crontab.xml` - group[], job instance, method, schedule [*](https://github.com/magento-notes/magento2-exam-notes/blob/master/1.%20Magento%20Architecture%20and%20Customization%20Techniques/6.%20Configure%20event%20observers%20and%20scheduled%20jobs.md#crontabxml)
- `cron_groups.xml` [*](https://github.com/magento-notes/magento2-exam-notes/blob/master/1.%20Magento%20Architecture%20and%20Customization%20Techniques/6.%20Configure%20event%20observers%20and%20scheduled%20jobs.md#cron-groups)
- `di.xml` - preference, plugins, virtual type [*](https://devdocs.magento.com/guides/v2.2/extension-dev-guide/build/di-xml-file.html)
- `eav_attributes.xml` - locked entity attributes (global, unique etc.)
- `email_templates.xml` - id label file type module -- view/frontend/email/name.html
- `events.xml` - observers, shared, disabled
- `events.xml` - observers, shared, disabled [*](https://github.com/magento-notes/magento2-exam-notes/blob/master/1.%20Magento%20Architecture%20and%20Customization%20Techniques/6.%20Configure%20event%20observers%20and%20scheduled%20jobs.md#demonstrate-how-to-configure-observers)
- `export.xml`
- `extension_attributes.xml` - for, attribute code, attribute type
- `fieldset.xml`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,32 @@ This class must extends from [\Symfony\Component\Console\Command\Command](https:
<?php
namespace Vendor\Module\Console\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class ExampleCommand extends \Symfony\Component\Console\Command\Command
{
protected function configure()
{
$options = [
new \Symfony\Component\Console\Input\InputOption(
'param',
null,
\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED,
'Param description'
),
];
$this->setName('example:hello')
->setDescription('Hello world command')
->setDefinition($options);
->setDescription('Hello world command');

// Positional argument
$this->addArgument(
'myargument',
InputArgument::REQUIRED,
'Positional required argument example'
);

// Not required option
$this->addOption(
'myoption',
null,
InputOption::VALUE_OPTIONAL,
'Option example',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);

parent::configure();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ generate
check for standalone process
```

\Magento\Cron\Model\Config\Data extends \Magento\Cron\Model\Config\Data
`\Magento\Cron\Model\Config\Data` extends `\Magento\Framework\Config\Data`
- merges \Magento\Cron\Model\Config\Reader\Db::get from Database

Sample DB structure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

- configure autoloader - PSR-4 prepend generation\Magento

\Magento\Framework\App\Bootstrap::*createApplication*
[\Magento\Framework\App\Bootstrap](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Bootstrap.php)::*createApplication*

- just call object manager->create

\Magento\Framework\App\Bootstrap::*run*
[\Magento\Framework\App\Bootstrap](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Bootstrap.php)::*run*

- set error handler
- assert maintenance
Expand All @@ -27,7 +27,7 @@

### Application class

bootstrap->createApplication()
[bootstrap->createApplication()](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Bootstrap.php#L230)

- [\Magento\Framework\App\Http](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Http.php) - index.php, pub/index.php
load config area by front name
Expand Down Expand Up @@ -64,19 +64,26 @@ Notes:
[\Magento\Framework\App\Http::launch](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Http.php#L128)
1. detect config area by front name

`\Magento\Framework\App\AreaList` - areas from argument di.xml
```php
<?php
$areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
$this->_state->setAreaCode($areaCode);
$this->_objectManager->configure($this->_configLoader->load($areaCode));
```

`\Magento\Framework\App\AreaList` - areas from argument di.xml ([AreaList](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/AreaList.php))

- frontend = [frontname null, router "standard"] --- *default when nothing matched*
- adminhtml - [frontNameResolver=..., router "admin"]
\Magento\Backend\App\Area\FrontNameResolver::getFrontName(checkhost)
[\Magento\Backend\App\Area\FrontNameResolver::getFrontName(checkhost)](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Backend/App/Area/FrontNameResolver.php#L83)
system config `admin/url/use_custom`, `admin/url/custom`
- crontab = null
- webapi_rest = [frontName `/rest`]
- webapi_soap = [frontname `/soap`]

1. ObjectManagerInterface::configure - selected area code
1. result = FrontControllerInterface->dispatch
1. ResultInterface.renderResult into response object
1. [ObjectManagerInterface->configure()](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php#L82) - selected area code
1. result = FrontControllerInterface->dispatch()
1. [ResultInterface->renderResult()](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Controller/AbstractResult.php#L122) into response object
1. event `controller_front_send_response_before` (request, response)


Expand All @@ -93,9 +100,9 @@ Notes:
- *Default* global preference app/etc/di.xml - Magento\Framework\App\FrontController
- "frontend", "adminhtml", "crontab" area code - no preference, use default *App\FrontController*
- "webapi_rest (frontName `/rest`) - preference module-webapi/etc/webapi_rest/di.xml - *\Magento\Webapi\Controller\Rest*
- "webapi_soap" (frontname `/soap`) - preference module-webapi/etc/webapi_rest/di.xml - *\Magento\Webapi\Controller\Soap*
- "webapi_soap" (frontname `/soap`) - preference module-webapi/etc/webapi_soap/di.xml - *\Magento\Webapi\Controller\Soap*

### [App\FrontController](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/FrontController.php):
### [\Magento\Framework\App\FrontController](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/FrontController.php):

- routerList
- action = router[].match
Expand All @@ -111,17 +118,32 @@ Notes:

- [\Magento\Framework\Controller\ResultInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Controller/ResultInterface.php) - renderResult, setHttpResponseCode, setHeader

Raw, Json, Forward, Layout, Page, Redirect
Implementations:
- [Result\Raw](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Controller/Result/Raw.php) -> Result\AbstractResult
- [Result\Json](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Controller/Result/Json.php) -> Result\AbstractResult
- [Result\Forward](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Controller/Result/Forward.php) -> Result\AbstractResult
- [\Magento\Framework\View\Result\Layout](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/View/Result/Layout.php) -> Result\AbstractResult
- [\Magento\Framework\View\Result\Page](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/View/Result/Page.php) -> \Magento\Framework\View\Result\Layout
- [Result\Redirect](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Controller/Result/Redirect.php) -> Result\AbstractResult

- [\Magento\Framework\App\ResponseInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal//Magento/Framework/App/ResponseInterface.php) - sendResponse

- \Magento\Framework\App\ResponseInterface - sendResponse
Console\Response, Response\FileInterface, PhpEnvironment\Response, Webapi\Response, Rest\Response
Implementations:
- [Console\Response](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Console/Response.php)
- [\Magento\MediaStorage\Model\File\Storage\FileInterface](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/MediaStorage/Model/File/Storage/Response.php) -> \Magento\Framework\App\Response\Http
- [\Magento\Framework\HTTP\PhpEnvironment\Response](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/HTTP/PhpEnvironment/Response.php) -> \Zend\Http\PhpEnvironment\Response
- [\Magento\Framework\Webapi\Response](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Webapi/Response.php) -> \Magento\Framework\HTTP\PhpEnvironment\Response
- [\Magento\Framework\Webapi\Rest\Response](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Webapi/Rest/Response.php) -> \Magento\Framework\Webapi\Response

### [Controller\Rest](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Webapi/Controller/Rest.php):
- process path [/$store]/... - specific store, [/all]/... - admin store, /... - default store
### [\Magento\Webapi\Controller\Rest](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Webapi/Controller/Rest.php) -> \Magento\Framework\App\FrontControllerInterface:

- preference for FrontController set in [etc/webapi_rest/di.xml](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Webapi/etc/webapi_rest/di.xml#L32)
- process path [/$store]/... - specific store, [/all]/... - admin store (0), /... - default store
- a. process schema request /schema
- b. or process api request (resolve route, invoike route -> service class with params)
- b. or process api request (resolve route, invoke route -> service class with params)

### [\Magento\Webapi\Controller\Soap](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Webapi/Controller/Soap.php) -> \Magento\Framework\App\FrontControllerInterface:

### [Controller\Soap](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Webapi/Controller/Soap.php):
- process path (same as REST)
- a. generate WSDL ?wsdl
- b. or generate WSDL service list ?wsdl_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ Module UrlRewrite:

Product:

- event `catalog_product_save_before`
- event `catalog_product_save_before` - generate URL key by product name (if url key wasn't provided)
* [ProductUrlKeyAutogeneratorObserver](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/CatalogUrlRewrite/Observer/ProductUrlKeyAutogeneratorObserver.php)
* [\Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator::getUrlKey](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlPathGenerator.php#L125)

- event `catalog_product_save_after` - generate and replace URL rewrites (when changed url_key, categories, websites or visibility)
* [ProductProcessUrlRewriteSavingObserver](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php)
* \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::generate
* [\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::generate](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteGenerator.php#L128)
* deleteByData, replace

Category:
Expand All @@ -102,6 +106,8 @@ Category:
* child category.url_path

- event `catalog_category_save_after` - when changed (key, anchor, products)
* [CategoryProcessUrlRewriteSavingObserver](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php#L90)
* [\Magento\CatalogUrlRewrite\Observer\UrlRewriteHandler::generateProductUrlRewrites](https://github.com/magento/magento2/blob/2.2-develop/app/code//Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php#L124)
* ... lots of logic


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Describe request routing and flow in Magento.

Frontend routers:
[Frontend routers](https://devdocs.magento.com/guides/v2.2/extension-dev-guide/routing.html):

- robots (10)
- urlrewrite (20)
Expand Down Expand Up @@ -41,13 +41,17 @@ reference route by ID and add own module "before" original module.

### How do you handle custom 404 pages?

1. If front controller catches NotFoundException, it changes action name *"noroute"* and continues loop.
1. If [front controller](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/FrontController.php#L61-L65) catches [\Magento\Framework\Exception\NotFoundException](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Exception/NotFoundException.php), it changes action name *"noroute"* and continues loop.
E.g. catalog/product/view/id/1 throws NotFoundException. catalog/product/noroute is checked.

1. If standard router recognizes front name but can't find controller, it tries to find *"noroute"*
action from last checked module.
E.g. catalog/brand/info controller doesn't exist, so catalog/brand/noroute will be checked.

[\Magento\Framework\App\Router\Base::getNotFoundAction](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Router/Base.php#L237)

1. If all routers didn't match, default controller provides two opportunities:
- set default 404 route in admin config `web/default/no_route`
- register custom handler in noRouteHandlerList
- set default 404 route in admin config `web/default/no_route` (see: [\Magento\Framework\App\Router\NoRouteHandler::process](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Router/NoRouteHandler.php#L34))
- register custom handler in [noRouteHandlerList](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Router/NoRouteHandlerList.php):
* backend (sortOrder: 10) [Magento\Backend\App\Router\NoRouteHandler](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Backend/App/Router/NoRouteHandler.php#L44) -> `adminhtml/noroute/index`
* default (sortOrder: 100) [Magento\Framework\App\Router\NoRouteHandler](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Router/NoRouteHandler.php)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ View\Layout::*build* = View\Layout\Builder::*build* - once

1. generateLayoutXml - joins `_updates` into XML string, loads XML object, initiailzes `_elements` = []

* layout.generaXml
* layout.generateXml
* no events

1. generateLayoutBlocks - layout.generateElements
Expand Down Expand Up @@ -213,11 +213,11 @@ Only containers


### page result.renderResult:
- View\Resuls\PageFactory.create
- View\Result\PageFactory.create
- View\Result\Page::addDefaultHandle - `default`, `$fullActionName`

- View\Page\Config.publicBuild = build
- View\Page\Builder.build - extends View\Layout\Builder, custom readPageLayout on step generatelayoutBlocks
- View\Page\Builder.build - extends View\Layout\Builder, custom readPageLayout on step generateLayoutBlocks

* (inherit) loadLayoutUpdates
* (inherit) generateLayoutXml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ All same as layout, but subDir 'page_layout':
<theme>*_*/page_layout/override/theme/*/*/*.xml
```

View\Layout\ProcessorInterface = View\Model\Layout\Merg
View\Layout\ProcessorInterface = View\Model\Layout\Merge
- $updates - array of all found string XML file contents E.g.
```
updates[] = '<body><block name="someBlock"...'
Expand All @@ -260,8 +260,8 @@ View\Layout\ProcessorInterface = View\Model\Layout\Merg
- create new theme from scratch without parent when design is very different from existing
- inherit new theme to add smaller customizations - move, hide, reorder elements, change block arguments, html attributes
- new theme can be assigned to specific store view, for example for b2b store
- theme can apply dynamically based on browser user agent as exception - enter regexp
Content > Design > Implementation > [Edit] > Design Rule > User Agent Rules
- theme can apply dynamically based on browser user agent as exception - enter regexp in
_Content > Design > Implementation > [Edit] > Design Rule > User Agent Rules_
Full page cache and design exception:
```
plugin magento-store/etc/di.xml:
Expand All @@ -285,9 +285,9 @@ View\Layout\ProcessorInterface = View\Model\Layout\Merg

theme.xml - parent

Determine theme hierarch of existing project:
Determine theme hierarchy of existing project:

- Go to Content > Design > Configuration
- Go to _Content > Design > Configuration_
- Check "Theme Name" column on row with store view under question
- find paths to all available themes in app/etc/design/frontend/* or vendor/*/theme-* (conventionally)
or find programmatically:
Expand Down