Magento 2 registration.php file in extension folder

- Magento 2

Magento 2 Development

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.

The component of registration.php looks as follows:

In case of composer packages, there is an additional requirement: each component’s composer.json must invoke the file in the autoload section:

Since Magento 2 relies on a PSR-4 standard, you can place your module anywhere but with correct registration.php settings.

Sources: Magento StackexchangeMarius; Max Yekaterynenko.

More tips from the cookbook.