yannoff / composer-dotenv-handler
Composer script to generate .env file against .env.dist template
Installs: 2 174
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^5.6|>=7.0.8
- symfony/dotenv: >=3.4
Requires (Dev)
- composer/composer: ^1.10.23 || ^2.1.9
- symfony/filesystem: ^2.3 || ^3 || ^4
README
Composer script to handle .env
file maintenance, based upon the concept of the popular incenteev/composer-parameter-handler package.
Usage
First you must require the package:
$ composer require yannoff/composer-dotenv-handler
Then, set up your composer.json
accordingly, as in the following example:
... "scripts": { "post-install-cmd": "Yannoff\\DotenvHandler\\ScriptHandler::updateEnvFile" } ...
Advanced options
Options may be passed via the extra
section of the composer.json :
"extra": { "yannoff-dotenv-handler": { // options here } }
Available options
Symfony Flex Behavior
As of November 2018, the guys at Symfony decided to change radically how dotenv
files are handled in symfony applications.
A local temporary workaround could be to modify the composer.json
extra section as follow:
"extra": { "yannoff-dotenv-handler": { "file": ".env.local", "dist-file": ".env" } }
Anyway this is not an acceptable solution, indeed the dotenv file name may vary from one deploy environment to another (test, staging, prod...): the composer.json
can't be committed as is.
So here comes the behavior option:
"extra": { "yannoff-dotenv-handler": { "behavior": "flex" } }
When in flex behavior mode, the script will build the dotenv file name automatically, based upon either the APP_ENV
or ENV
(in this order of preference) environment variable (will use local as default value, if not set) at runtime.
For example, issuing the following command in a terminal:
$ /usr/bin/env ENV=staging composer install
would result in having the following config values:
dist-file
:.env
file
:.env.staging
Licence
Licensed under the MIT Licence.