dev-master
9999999-devLoad environment variables from `.env` when Composer runs
The Requires
- composer-plugin-api ^1.0
- vlucas/phpdotenv ~2.0
The Development Requires
Load environment variables from `.env` when Composer runs
Whenever Composer is activated in a project with a .env
file, this plugin will use the
vlucas/phpdotenv
library to load this configuration
file into the PHP envrionment., (*1)
This plugin works well with incenteev/composer-parameter-handler
which allows you to map environment variables to parameters. This plugin runs when composer
is activated, and ParameterHandler finds that configuration in the environment after your dependencies
have been installed or updated., (*2)
If your .env
file contains:, (*3)
SECRET_FOR_ME="123456"
And your composer.json
file contains:, (*4)
{ "require": { "incenteev/composer-parameter-handler": "~2.0", "bangpound/composer-dotenv": "~1.0@dev" }, "extra": { "incenteev-parameters": { "file": "app/config/parameters.yml", "env-map": { "secret": "SECRET_FOR_ME" } } }, "scripts": { "post-install-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters" ], "post-update-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters" ] }, }
Then after running composer update or install, your app/config/parameters.yml
will contain:, (*5)
# This file is auto-generated during the composer install parameters: secret: 123456
In the extra
property of the root repository, change these values as necessary:, (*6)
{ "extra": { "dotenv": { "path": ".", "file": ".env" } } }
Load environment variables from `.env` when Composer runs