gene / module-envphp-modules
Magento 2 module to allow enabling a module in env.php rather than config.php, useful for require-dev dependencies
Package info
github.com/genecommerce/module-envphp-modules
Type:magento2-component
pkg:composer/gene/module-envphp-modules
Requires
- php: ^8.1
- magento/framework: *
- magento/magento-composer-installer: *
README
This module allows you to enable a module in app/etc/env.php rather than app/etc/config.php.
This is useful for require-dev dependencies which by default inject their module status into app/etc/config.php, but are never deployed as actual dependencies.
Benefits
This improves developer experience by preventing conflicts and changes on the app/etc/config.php, composer.json, and composer.lock files. All modules are committed in, but the module is only enabled on developer machines. This allows us to ensure dev teams are working with all the tools necessary to deliver high quality software.
This helps maintains zero downtime deployments by allowing module:config:status and setup:db:status to understand that these developer dependencies are purposefully not present, and not a cause for concern.
Installation
composer require gene/module-envphp-modules php bin/magento setup:upgrade echo "app/etc/gene_envphp_modules/di.xml" >> .gitignore echo "setup/config/autoload/gene-envphp-modules.global.php" >> .gitignore
Usage
You may have a developer dependency like https://github.com/tddwizard/magento2-fixtures, the standard way to install is like so
composer require --dev tddwizard/magento2-fixtures php bin/magento setup:upgrade
This will
- Add the module in as a
require-devdependency withincomposer.json - Set
TddWizard_Fixtures => 1withinapp/etc/config.php
This module should never end upstream but it is very useful for developers and CI pipelines to have for testing, so we can flag it as enabled in env.php like so.
# If you do not need the module active during integration tests, then run without --enable-during-tests
php bin/magento gene:envphp:enable TddWizard_Fixtures --enable-during-tests
This will
- Set
TddWizard_Fixtures => 0withinapp/etc/config.php, so this module is never active anywhere without an override inapp/etc/env.php - Store metadata about the module under
gene_envphp_modules_configphpwithinapp/etc/config.php - Store
TddWizard_Fixtures => 1undergene_envphp_modules_envphpwithinapp/etc/env.php
From here the module will appear enabled locally and within test executions.
Performance
This module is built to have a low footprint on the code. There are 2 main extension points
Performance - Setup Commands
The setup:upgrade, setup:db:status, module:config:status are all customised via the dependency injections in setup/config/autoload/gene-envphp-modules.global.php.
In Gene\EnvphpModules\Model\DeploymentConfigReader and Gene\EnvphpModules\Model\DeploymentConfigWriter we do a series of low impact array lookups and an is_file check per module. These changes only apply to the manually invoked setup commands.
Performance - Module List
We use app/etc/gene_envphp_modules/di.xml to inject the following custom deployment configuration model into the module list
<type name="Magento\Framework\Module\ModuleList"> <arguments> <argument name="config" xsi:type="object">Gene\EnvphpModules\Model\ModuleList\DeploymentConfig</argument> </arguments> </type>
On production/staging environments there will be no development modules defined in env.php, so the only additional overhead is an if condition and a lookup of the already available deployment configuration data.