A Magento 2 module that reads from file additional configuration
Installs: 3 956
Open Issues: 0
- php: ~5.6.0|~7.0.0|~7.1.0
- magento/framework: ^100.0.0|^101.0.0
- magento/module-backend: ^100.0.0
- magento/module-config: ^100.1.1|^101.0.0
- symfony/yaml: ^2.0|^3.0
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.5
This module it is now useless, you can:
composer require symfony/dotenv, take a look to these exaplanations to see the hierarchy;
- Create the file
<?php declare(strict_types=1); use Symfony\Component\Dotenv\Dotenv; (new Dotenv())->loadEnv(__DIR__ . "/../../.env");
- Load it throught composer modifing the
"files": [ + "app/etc/EnvironmentVariablesLoader.php", "app/etc/NonComposerComponentRegistration.php" ],
- Create the env files configuring variables as written on the magento docu.
A Magento 2 module that overrides default configuration from file which can be added to version control, inspired by this Magento 1.x extension: https://github.com/webgriffe/config-extension.
Add this extension as dependency using Composer:
composer require webgriffe/module-config-override php bin/magento setup:upgrade
Magento configuration is driven by database. This, sometimes, is overkill and forces us to maintain upgrade script to keep Magento envorinment aligned with features development. So, this extension enables additional config source that loads several YAML files and overrides database configuration.
Loaded YAML files are (in this order):
app/etc/default.yml.dist: this intended to be under version control to distribute configuration for all environments.
app/etc/default.yml: this is intendet to be ignored by version control system to provide configuration related to local needs.
Also, if the
MAGE_ENVIRONMENT environment variable is defined, then two additiontal files are loaded. For example, if the
MAGE_ENVIRONMENT variable value is
dev, the following two files are loaded:
default.yml.dist, this is intended to be under version control to distribute configuration but only for the
default.yml, this is intended to be ignored by version control to provide configuration related to local needs but only for the
Configuration in YAML files must be specified with the same structure of Magento system configuration, for example:
web: secure: base_url: "http://my-project-url.dev/" unsecure: base_url: "http://my-project-url.dev/"
default configuration scope is overridden.
Please note that if you use the
MAGE_ENVIRONMENT variable then it should be always set when Magento is running. So is not enough to set it through your webserver (for example with a
SetEnv "dev" in Apache) but it should also be set into your command line shell. Otherwise, if you have the Magento's configuration cache enabled and you clear the cache from the command line, the
MAGE_ENVIRONMENT will not be applied and you'll get unexpected behaviours.
Remember to "export" you env variable when you run a command via shell:
export MAGE_ENVIRONMENT=dev && <your command>
alternative you can add the
MAGE_ENVIRONMENT=dev in your shell configuration (ex. for bash):
.... .... MAGE_ENVIRONMENT=dev
Overridden config values are shown in backend
Overridden config values are shown in Magento's backend. Every config setting it's shown on its section. For example, if you have the following
design: head: default_title: Webgriffe Store title_suffix: - Webgriffe Store
When you'll go to
Stores -> Configuration -> General -> Design you'll find the overridden config value shown and not editable.
This feature improves a lot the usability of this extension.
- Improve system config admin interface to support complex fields
- Developed by Webgriffe®