Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -104,7 +104,7 @@ Examples [1],[2],[3],[4],[5],[6] taken from [Magento DevDocs - Register your com
Minimization of software dependencies is a cornerstone of Magento architecture. Based on this principle there are several logical limitations:
1. One module is responsible only for one feature.
1. Module dependencies on other modules must be declared explicitly.
1. Excluding or disabling a module should not disabling another module.
1. Excluding or disabling a module should not disable another module.

# How do different modules interact with each other?
Magento 2 is [PSR-4](https://www.php-fig.org/psr/psr-4/) compliant. As a main principle of module interaction Magento 2 declares a dependency injection pattern and service contracts.
Expand Down Expand Up @@ -143,7 +143,7 @@ Specifically:
>The module extends another module’s configuration.
>The module extends another module’s layout.
>
> -- [Magento DevDocs - Module dependency types](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_depend_types.html)
> -- [Magento DevDocs - Module dependency types](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_depend.html)

Magento module install order flow:
>1. The module serving as a dependency for another module
Expand All @@ -154,10 +154,10 @@ Following dependencies should not be created:
>1. Undeclared
>1. Incorrect
>
> -- [Magento DevDocs - Module dependency types](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_depend_types.html)
> -- [Magento DevDocs - Module dependency types](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_depend.html)


>You can build dependencies between classes in the application layer, but these classes must belong to the same module. Dependencies between the modules of the application layer should be built only by the service contract or the service provider interface (SPI). - [Magento DevDocs - Module dependency types](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_depend_types.html)
>You can build dependencies between classes in the application layer, but these classes must belong to the same module. Dependencies between the modules of the application layer should be built only by the service contract or the service provider interface (SPI). - [Magento DevDocs - Module dependency types](http://devdocs.magento.com/guides/v2.2/architecture/archi_perspectives/components/modules/mod_depend.html)

### Magento areas
A Magento area organizes code for optimized request processing by loading components parts which are related only to the specific area. Areas are registered in the `di.xml` file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ In addition, you can choose the component root directory to start development. T
>
> -- [Magento DevDocs - About component file structure](https://devdocs.magento.com/guides/v2.2/extension-dev-guide/prepare/prepare_file-str.html)

Class [Magento\Framework\Module\ModuleList\Loader](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Module/ModuleList/Loader.php#L78) load `etc/module.xml` files and sort modules by sequence.
Class [Magento\Framework\Module\ModuleList\Loader](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Module/ModuleList/Loader.php#L78) load `etc/module.xml` files and sort modules by sequence.
The sequence use for sorting events, plugins, preferences and layouts.


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

# Interfaces for work with configs

#### [\Magento\Framework\Config\Reader\Filesystem](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/Reader/Filesystem.php) -> [\Magento\Framework\Config\ReaderInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/ReaderInterface.php)
#### [\Magento\Framework\Config\Reader\Filesystem](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/Reader/Filesystem.php) -> [\Magento\Framework\Config\ReaderInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/ReaderInterface.php)
Gets .xsd names from schema locator, gets full .xml file list from file resolver, merges all files, validates, runs converter to get resulting array.
- read(scope)
+ `fileResolver->get(_filename)`
Expand All @@ -56,36 +56,36 @@ Gets .xsd names from schema locator, gets full .xml file list from file resolver
- `_idAttributes`, `_fileName`, `_schemaFile` (from schemaLocator), `_perFileSchema` (from schemaLocator), filename (menu.xml)
- schemaFile from schemaLocator

#### [\Magento\Framework\Config\ConverterInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/ConverterInterface.php)
#### [\Magento\Framework\Config\ConverterInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/ConverterInterface.php)
Convert an array to any format
- `convert(\DOMDocument $source)`

#### [\Magento\Framework\Config\SchemaLocatorInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/SchemaLocatorInterface.php) - full path to .xsd
#### [\Magento\Framework\Config\SchemaLocatorInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/SchemaLocatorInterface.php) - full path to .xsd
- `getPerFileSchema` - per file before merge
- `getSchema` - merged file

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

This interface retrieves the validation state.
- `isValidationRequired()`

[\Magento\Framework\App\Arguments\ValidationState](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/App/Arguments/ValidationState.php) is default implementation, that require validation only in developer mode.
[\Magento\Framework\App\Arguments\ValidationState](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/App/Arguments/ValidationState.php) is default implementation, that require validation only in developer mode.

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

This interface the list of all scopes.
- `getAllScopes()`

#### [\Magento\Framework\Config\Data](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/Data.php) -> [\Magento\Framework\Config\DataInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/DataInterface.php)
#### [\Magento\Framework\Config\Data](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/Data.php) -> [\Magento\Framework\Config\DataInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/DataInterface.php)

Helps to get the configuration data in a specified scope.
- `merge(array $config);`
- `get($key, $default = null)`


###### Links and examples:
- Product types configs model to read data from [product_types.xml](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Catalog/etc/product_types.xml): [\Magento\Catalog\Model\ProductTypes](https://github.com/magento/magento2/tree/2.2-develop/app/code/Magento/Catalog/Model/ProductTypes)
- Implementation via virtual types to read data from layout.xml: [Magento/Theme/etc/di.xml](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Theme/etc/di.xml#L48)
- Product types configs model to read data from [product_types.xml](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Catalog/etc/product_types.xml): [\Magento\Catalog\Model\ProductTypes](https://github.com/magento/magento2/tree/2.3/app/code/Magento/Catalog/Model/ProductTypes)
- Implementation via virtual types to read data from layout.xml: [Magento/Theme/etc/di.xml](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Theme/etc/di.xml#L42)
- https://www.atwix.com/magento-2/working-with-custom-configuration-files/


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Magento loads di.xml files and merges them all together from the following stage

### Object manager

Under the hood, the [ObjectManager](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php)
Under the hood, the [ObjectManager](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/ObjectManager/ObjectManager.php)
will use PHP reflection features to look at a class’s __construct type hints/parameters,
automatically instantiate the object for us, and then pass it into the constructor as an argument.

[AbstractFactory](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php) > [\Magento\Framework\ObjectManager\FactoryInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/ObjectManager/FactoryInterface.php)
[AbstractFactory](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php) > [\Magento\Framework\ObjectManager\FactoryInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/ObjectManager/FactoryInterface.php)
and their implementations use to resolve arguments and create new objects.

By default, all objects created via automatic constructor dependency injection are singleton objects,
Expand All @@ -26,7 +26,7 @@ if ($isShared) {
$argument = $this->objectManager->create($argumentType);
}
```
[\Magento\Framework\ObjectManager\Factory::resolveArgument()](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php#L143-L147)
[\Magento\Framework\ObjectManager\Factory::resolveArgument()](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php#L143-L147)

### Arguments

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
There are three types of plugins in magento: around, before and after.

__Important__: Classes, abstract classes and interfaces that are implementations of or inherit from classes that have plugins will also inherit plugins from the parent class.
For example, if you create a plugin for [\Magento\Catalog\Block\Product\AbstractProduct](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Catalog/Block/Product/AbstractProduct.php),
For example, if you create a plugin for [\Magento\Catalog\Block\Product\AbstractProduct](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Catalog/Block/Product/AbstractProduct.php),
plugin methods will be called for all child classes, such as \Magento\Catalog\Block\Product\View, \Magento\Catalog\Block\Product\ProductList\Upsell etc.

### Limitations
Expand Down Expand Up @@ -131,9 +131,9 @@ Magento automatically generates `Interceptor` class for the plugin target and st
}
```

[\Magento\Framework\Interception\Interceptor](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Interception/Interceptor.php):
[\Magento\Framework\Interception\Interceptor](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Interception/Interceptor.php):

- $pluginList = [\Magento\Framework\Interception\PluginListInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Interception/PluginListInterface.php)
- $pluginList = [\Magento\Framework\Interception\PluginListInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Interception/PluginListInterface.php)
- $subjectType = 'MyBeautifulClass'
- `___init` - called in in constructor, pluginList = get from object manager, subjectType = class name
- pluginList->getNext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Example:
```

Observer class should be placed in the <module-root>/Observer directory and implement
[Magento\Framework\Event\ObserverInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Event/ObserverInterface.php)
[Magento\Framework\Event\ObserverInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Event/ObserverInterface.php)
interface.

```php
Expand All @@ -63,8 +63,8 @@ class MyObserver implements \Magento\Framework\Event\ObserverInterface

### Dispatching events

Events dispatch by [Magento\Framework\Event\Manager](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Event/Manager.php) class
that implement [Magento\Framework\Event\ManagerInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Event/ManagerInterface.php) interface:
Events dispatch by [Magento\Framework\Event\Manager](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Event/Manager.php) class
that implement [Magento\Framework\Event\ManagerInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Event/ManagerInterface.php) interface:
> dispatch($eventName, array $data = []);

Example:
Expand Down Expand Up @@ -144,16 +144,16 @@ generate
check for standalone process
```

[\Magento\Cron\Model\Config\Data](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Cron/Model/Config/Data.php) extends [\Magento\Framework\Config\Data](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/Data.php)
- merges [\Magento\Cron\Model\Config\Reader\Db::get](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Cron/Model/Config/Reader/Db.php#L51) from Database
[\Magento\Cron\Model\Config\Data](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Cron/Model/Config/Data.php) extends [\Magento\Framework\Config\Data](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Config/Data.php)
- merges [\Magento\Cron\Model\Config\Reader\Db::get](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Cron/Model/Config/Reader/Db.php#L51) from Database

Sample DB structure:
```
default/crontab/GROUP/jobs/JOB/schedule/cron_expr = '* * * * *'
default/crontab/GROUP/jobs/JOB/schedule/config_path = 'some/config/path' -- try to read schedule from this config, store view scope
default/crontab/GROUP/jobs/JOB/run/model = 'class::method'
```
DB config usage example: [ProductAlert, system.xml](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/ProductAlert/etc/adminhtml/system.xml#L38:L45), [ProductAlert, crontab.xml](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/ProductAlert/etc/crontab.xml), backend model: [Magento\Cron\Model\Config\Backend\Product\Alert](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Cron/Model/Config/Backend/Product/Alert.php)
DB config usage example: [ProductAlert, system.xml](https://github.com/magento/magento2/blob/2.3/app/code/Magento/ProductAlert/etc/adminhtml/system.xml#L38:L45), [ProductAlert, crontab.xml](https://github.com/magento/magento2/blob/2.3/app/code/Magento/ProductAlert/etc/crontab.xml), backend model: [Magento\Cron\Model\Config\Backend\Product\Alert](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Cron/Model/Config/Backend/Product/Alert.php)

`bin/magento cron:install` example:
```
Expand All @@ -180,7 +180,7 @@ TODO: find out

### Identify the function and proper use of automatically available events

Model events [\Magento\Framework\Model\AbstractModel](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Model/AbstractModel.php):
Model events [\Magento\Framework\Model\AbstractModel](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Model/AbstractModel.php):

- `model_load_before`, `{$_eventPrefix}_load_before`
- `model_load_after`, `{$_eventPrefix}_load_after`
Expand All @@ -191,18 +191,18 @@ Model events [\Magento\Framework\Model\AbstractModel](https://github.com/magento
- `model_delete_after`, `{$_eventPrefix}_delete_after`
- `model_delete_commit_after`, `{$_eventPrefix}_delete_commit_after`

Flat collection events [\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php):
Flat collection events [\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php):

- `core_collection_abstract_load_before`, `{_eventPrefix}_load_before`
- `core_collection_abstract_load_after`, `{_eventPrefix}_load_after`

only if `_eventPrefix` and `_eventObject` defined: `{prefix}_load_before`, `{prefix}_load_after`

EAV collection events [\Magento\Eav\Model\Entity\Collection\AbstractCollection](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php):
EAV collection events [\Magento\Eav\Model\Entity\Collection\AbstractCollection](https://github.com/magento/magento2/blob/2.3/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php):

- eav_collection_abstract_load_before

[\Magento\Framework\Model\AbstractModel](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Model/AbstractModel.php):
[\Magento\Framework\Model\AbstractModel](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Model/AbstractModel.php):

- _eventObject = 'object'
- _eventPrefix = 'core_abstract', e.g. 'catalog_category'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class ExampleCommand extends \Symfony\Component\Console\Command\Command
}
```

- Declare your command in [\Magento\Framework\Console\CommandListInterface](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Console/CommandListInterface.php) using dependency injection ({module}/etc/di.xml).
See also CommandListInterface implementation: [\Magento\Framework\Console\CommandList](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Console/CommandList.php)
- Declare your command in [\Magento\Framework\Console\CommandListInterface](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Console/CommandListInterface.php) using dependency injection ({module}/etc/di.xml).
See also CommandListInterface implementation: [\Magento\Framework\Console\CommandList](https://github.com/magento/magento2/blob/2.3/lib/internal/Magento/Framework/Console/CommandList.php)

{module}/etc/di.xml:
```xml
Expand Down
Loading