Configuration load and merge
This section discusses how configuration files are loaded and merged.
How Commerce loads configuration files
Commerce loads configuration files in the following order (all paths are relative to your Commerce installation directory):
- Primary configuration (app/etc/di.xml). This file is used to bootstrap Commerce.
- Global configurations from modules (
<your component base dir>/<vendorname>/<component-type>-<component-name>/etc/*.xml
). Collects certain configuration files from all modules and merges them together. - Area-specific configuration from modules (
<your component base dir>/<vendorname>/<component-type>-<component-name>/etc/<area>/*.xml
). Collects configuration files from all modules and merges them into the global configuration. Some area-specific configurations can override or extend the global configuration.
where
-
<your component base dir>
is the base directory in which your component is located. Typical values areapp/code
orvendor
relative to the Commerce installation directory. -
<vendorname>
is the component’s vendor name; for example, Commerce’s vendor name ismagento
. -
<component-type>
is one of the following:module-
: An extension or module.theme-
: Theme.language-
: Language package.
<magento_root>/app/design/frontend
or <magento_root>/app/design/adminhtml
.<component-name>
: Name of your component as defined in composer.json.
Configuration file merge
Nodes in configuration files are merged based on their fully qualified XPaths, which has a special attribute defined in $idAttributes
array declared as its identifier. This identifier must be unique for all nodes nested under the same parent node.
Commerce application merge algorithm:
- If node identifiers are equal (or if there is no identifier defined), all underlying content in the node (attributes, child nodes, and scalar content) is overridden.
- If node identifiers are not equal, the node is a new child of the parent node.
- If the original document has multiple nodes with the same identifier, an error is triggered because the identifiers cannot be distinguished.
After configuration files are merged, the resulting document contains all nodes from the original files.
Configuration types, objects, and interfaces
The following sections provide information about configuration types, their corresponding configuration objects, and interfaces that you can use to work with the objects:
Configuration types and objects
The following table shows each configuration type and the Commerce configuration object to which it relates.
Configuration interfaces
You can interact with configuration files using interfaces under Magento\Framework\Config.
You can use these interfaces if you create a configuration type.
Magento\Framework\Config
provides the following interfaces:
- Framework\Config\ConverterInterface, which converts the XML into an in-memory array representation of the configurations.
- Framework\Config\DataInterface, which retrieves the configuration data in a specified scope.
- Framework\Config\FileResolverInterface, which identifies the location of files to be read by Magento\Framework\Config\ReaderInterface.
- Framework\Config\ReaderInterface, which reads the configuration data from storage and selects the storage from which it reads.
That is, the file system, database, other storage merges the configuration files according to the merging rules, and validates the configuration files with the validation schemas.
- Framework\Config\SchemaLocatorInterface, which locates the XSD schema.
- Framework\Config\ScopeListInterface, which returns a list of scopes.
- Framework\Config\ValidationStateInterface, which retrieves the validation state.