Download the PHP package cube/composer-dist-installer without Composer
On this page you can find all versions of the php package cube/composer-dist-installer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cube/composer-dist-installer
More information about cube/composer-dist-installer
Files in cube/composer-dist-installer
Package composer-dist-installer
Short Description Install .dist template files automatically on project setup. Compatible with any PHP framework or package.
License MIT
Informations about the package composer-dist-installer
Composer Dist Installer
Type | Status |
---|---|
Build | |
Packagist |
Automatically installs .dist files when you run composer install in your project, and optionally populates them with data using a very simple and intuitive templating syntax.
This project is designed to be framework-agnostic. All you need is to be using Composer to manage your project's dependencies.
Installation
Simply use Composer to install by running:
composer require cube/composer-dist-installer:~1.0@beta
Usage
Add the following into your root composer.json
file:
The file config/autoload/database.config.php
will then be created based on the template provided at
config/autoload/database.config.php.dist
and by asking you for any parameters requested in the .dist
file.
By default, the dist file is assumed to be in the same place than the parameters file, suffixed by .dist
.
This can be changed in the configuration:
The script handler will ask you interactively for parameters which are requested in the .dist
file, using optional
default values.
If composer is run in a non-interactive mode, the default values will be used for missing parameters.
Warning: If a configuration file already exists in the destination, you will be promted whether you want to override it. If you choose to overwrite, a backup file will be created right next to the config file. You're in charge of manually merging the differences between the new and the old file - and then deleting the old file.
Multiple Files
You can specify more than one file to be processed by using the following alternate syntax:
Template Syntax
Before the template files (.dist
files) are copied to the final destination, a processor will look for any parameters
you may have included in the template and ask you for their value.
The syntax for a parameter is {{QUESTION|DEFAULT}}
.
QUESTION
: should contain the entire question, including question marks etc. Optionally include[]
anywhere in the string to specify the location of the default value within the question (otherwise there will be no indication that there IS a default value).DEFAULT
: specify the default value. To use an environment variable as default use the following syntax:=ENV[VARIABLE_NAME]
For example, consider the following template:
When installing the project, composer will ask you for all the information and use defaults where necessary. The prompt would look something like this:
And the final file will look like this:
Environment Variables
It is possible to use environment values in order to set default values for parameters. The syntax for that is
{{Question|=ENV[VARIABLE_NAME]}}
, where VARIABLE_NAME
is the environment value that will provide the default.
In the example above, the following line used the USER
environment variable as a default value:
Multiple defaults for a parameter
It is also possible to have multiple default values (eg {{QUESTION|DEFAULT1|DEFAULT2}}
.
This can be useful if you want to use environment variables as a default and, in case the environment variable is not set, fall back to a hardcoded default value.
Hence, you can write in your dis file for instance:
If the MY_VAR environment variable is set to 'foobar', the question will be:
If the MY_VAR environment variable is not set, the question will be:
Non-interactive mode
When composer is launched with --no-interaction
option, the default value is applied.
This can be a good option for deployment process, in case you use environment variables in your dist file.
LICENSE
See LICENSE.txt
file in this same package.
Credits
Copyright (c) 2015 by Cu.be Solutions
Authors:
- Gabriel Somoza ([email protected])