Get Free Audit

Magento 2 Configuration Tips

Mar 22, 2018

856 Andrey Litvin

Magento 2 Configuration Tips

We keep diving into Magento 2. Today we are going to make a detailed examination of one of the basic elements of any CMS structure — its configuration. Things a developer can do, ways to save data and increase basic capacities.

Here is a list of questions, reviewed in this article:

  • How does the framework discover active extensions and their configuration?
  • By what process do the factory methods and autoloader enable class instantiation?
  • What are the common methods with which the framework accesses its configuration values and areas?
  • How are per-store configuration values established in the XML DOM?
  • Which class types and files have explicit paths?

So let’s jump right in and answer these questions one by one.

Methods the framework uses to discover active modules and their configuration

To register module in the system create a file registration.php in the root directory of the module, which contains the following content (by the example of Magento_Catalog module):

This code allows Magento to locate the module and to register it after the usage of bin/magento setup:upgrade.

Modules in Magento 2 can be installed into the directory app/code or using composer. When installing via composer, all the data from registration.php is automatically written in vendor/composer/autoload_files.php. When installing via the directory of app/code all modules registration files are read through the script /app/etc/NonComposerComponentRegistration.php (it’s also loaded in vendor/composer/autoload_files.php), then the information about switched on/off modules is written in app/etc/config.php.

In order to load module version files and its dependencies (module.xml) use the following class: Magento\Framework\Module\ModuleList\Loader and its method load().

All the other configuration files are read using Magento\Framework\Config\Reader\Filesystem and its method read($scope).

Process by which the factory methods and autoloader tenable class instantiation

In Magento 2 autoloader is implemented in vendor/composer/autoload_real.php and uses spl_autoload_register for class instantiation.

Common methods with which the framework accesses its configuration values and areas

The following classes are used for working with the configuration in Magento 2: \Magento\Framework\App\Config\Storage\WriterInterface using the following methods:

Magento\Framework\App\Config\ScopeConfigInterface using method:

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

A way to establish per-store configuration values in the XML DOM

Per-store configuration is indicated in file etc/config.xml in module directory as follows (example from module Magento_Backend):

Class types and files which have explicit paths

The following class types and files have explicit paths:

  • Helpers
  • Models
  • Resource Models
  • Blocks
  • Controllers
  • Plugin
  • Widgets

That is all we have to share with you for now. We do hope these tips were helpful and you will easily implement them into your work. Follow our new publications to learn more about Magento development.

You can also check out our previous articles about Magento 2 Development.

Still using Magento 1? Click here to learn about smooth migration to Magento 2.

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

Post a new comment

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