Quick Overview of the Magento Configuration Management

Quick Overview of the Magento Configuration Management

We continue to post the articles dedicated to the Magento certification exam. Hope you will find them useful.

How Magento loads and manipulates configuration information.

Magento 1 and Magento 2 use XML files and database table to save the configuration. XML files can be read with simplexml of the PHP module. Magento 1 uses the class Mage_Core_Model_Config to save the configuration.

Magento 2 stores data in Magento\Framework\App\ObjectManager\Environment\Developer or Magento\Framework\App\ObjectManager\Environment\Compiled (it depends on the deployment mode). In both Magento versions configuration is loaded after running Application (M1 – run of the class Mage_Core_Mode_App, M2 – createApplication of the class Magento\Framework\App\Bootstrap).

In Magento 1 after running an application, the function “baselnitis” launched and then loadBase, loadModules, loadDb in Mage_Core_Model_Config  is called in turns. Then the configuration from app/etc, module and database files are run. 

In Magento 2 Magento\Framework\App\ObjectManager\ConfigLoader is responsible for configuration load. It starts with objectManager initialization.

Magento\Framework\App\Bootstrap

\Magento\Framework\App\DeploymentConfig instance is created while app/etc/env.php and app/etc/config.php are loaded. app/etc/env.php and app/etc/config.php are the main config files in Magento 2 (app/etc/config.xml and app/etc/modules/*  are analogs in Magento 1).

Magento\Framework\App\Magento\Framework\App\ObjectManagerFactory

Then app/etc/di.xml is loaded, containing dependencies for ObjectManager.

Magento\Framework\App\ObjectManagerFactory

Magento\Framework\Config\Reader

The configuration of modules and database is load when getValue from Magento\Backend\App\Config is called first:

Magento\Framework\App\Config

Magento\Config\App\Config\Type\System

On this stage, the configuration is read in its turn. First, module config.xml is read, then database.

Config.xml is loaded with the use of the class Magento\Framework\App\Config\ConfigSourceAggregated:

Magento\Config\App\Config\Source\ModularConfigSource

Then config files from the list are read and converted from Dom objects into Array:

Magento\Framework\App\Config\Initial\Reader

After config.xml is loaded, the database config is loaded with the help of \Magento\Config\App\Config\Source\RuntimeConfigSource:

Class group configuration and its use in factory methods.

In Magento 1 factory methods were used (such as getModel, helper, getBlock) to create class instances. When creating instances, the class identificator described in the config.xml file was used (for example, catalog/product).

Magento 1:

In Magento 2 composer autoload and class generator are used now (more details you can find here http://alanstorm.com/magento_2_autoloader_and_class_generation/), that allows describing necessary models in the class constructor and using it. Besides, in Magento 2 objectManager is used, that allows loading classes dynamically. ObjectManager is the analog of Mage::getModel() andMage::helper.

Magento 2:

The configuration of class overrides in Magento.

Unlike Magento 1, Magento 2 does not use codepool priority (core, community, local), so all overrides are performed through config files and theme files (app/design/{adminhtml,frontend}/{vendor}/{theme}/).

In Magento 1 codepool priority can be used. Moreover, the override file can be created in higher priority codepool (dirty method) or just the config file can be used.

Class override in Magento 1 is used config files:

In Magento 2 the class can be overridden completely or the functionality can be extended with plugin (before, after, around)

Magento 2 override:

With that Belvg\Catalog\Model\Product should extend the initial class:

Magento 2 plugin:

The function should be called after{functionName}, before{functionName}, around{functionName}.



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *