Magento 2 registration.php file in extension folder
The registration.php file is a kind of the entry point of every Magento 2 module. Being the equivalent of app/etc/modules/[Namespace]_[Module].xml introduced in Magento 1, registration.php plays similar functions, but it is a part of the module itself.
The new functionality provides developers with the ability to to create modules in both the app/code folder and the vendor folder. It doesn’t matter where you place it, since the file will be noticed by Magento and your custom extension will be considered.
Now, each Magento 2 component (module, language, library, theme, etc) should have a registration.php file in its root directory. Please note that each component has a unique type. All types are defined in Magento\Framework\Component\ComponentRegistrar.
1 2 3 4 5 6 7 8 |
// Module registration ComponentRegistrar::register(ComponentRegistrar::MODULE, '_', __DIR__); // Theme ComponentRegistrar::register(ComponentRegistrar::THEME, '//', __DIR__); // Language ComponentRegistrar::register(ComponentRegistrar::LANGUAGE, '_', __DIR__); // Libraries ComponentRegistrar::register(ComponentRegistrar::LIBRARY, '', __DIR__); |
The component of registration.php looks as follows:
1 2 3 4 5 6 7 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Maxyek_ExtendedConfig', __DIR__ ); |
In case of composer packages, there is an additional requirement: each component’s composer.json must invoke the file in the autoload section:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
{ "name": "maxyek/module-extendedconfig", "description": "N/A", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/module-config": "1.0.0-beta", "magento/framework": "1.0.0-beta" }, "type": "magento2-module", "version": "0.0.1", "autoload": { "files": [ "registration.php" ], "psr-4": { "Maxyek\\ExtendedConfig\\": "" } } } |
Since Magento 2 relies on a PSR-4 standard, you can place your module anywhere but with correct registration.php settings.
Sources: