PHPackages                             cube/composer-dist-installer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cube/composer-dist-installer

AbandonedLibrary[Utility &amp; Helpers](/categories/utility)

cube/composer-dist-installer
============================

Install .dist template files automatically on project setup. Compatible with any PHP framework or package.

1.0-beta5(10y ago)313.8k2[1 issues](https://github.com/Cube-Solutions/composer-dist-installer/issues)[1 PRs](https://github.com/Cube-Solutions/composer-dist-installer/pulls)MITPHPPHP &gt;=5.4

Since Jan 31Pushed 10y ago9 watchersCompare

[ Source](https://github.com/Cube-Solutions/composer-dist-installer)[ Packagist](https://packagist.org/packages/cube/composer-dist-installer)[ RSS](/packages/cube-composer-dist-installer/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Composer Dist Installer
=======================

[](#composer-dist-installer)

TypeStatusBuild[![Build Status](https://camo.githubusercontent.com/2fb468c59154645d820335bbdc0df54aed2cd783398dae4abe91cceefda939a7/68747470733a2f2f7472617669732d63692e6f72672f437562652d536f6c7574696f6e732f636f6d706f7365722d646973742d696e7374616c6c65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Cube-Solutions/composer-dist-installer) [![Code Coverage](https://camo.githubusercontent.com/6abc164ad0ba6da48c8f2ba5d366b560138e43a200cc9f216d83977cf10f6899/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f437562652d536f6c7574696f6e732f636f6d706f7365722d646973742d696e7374616c6c65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Cube-Solutions/composer-dist-installer/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/ae7fc0afcac2670d6c265bb674d7b2eb77d79a6d8f59970248aef470f4c8d0af/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f437562652d536f6c7574696f6e732f636f6d706f7365722d646973742d696e7374616c6c65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Cube-Solutions/composer-dist-installer/?branch=master)Packagist[![Latest Stable Version](https://camo.githubusercontent.com/9b7066a70269cb9ee49381a7773619e58b8e9c70e264e3a5f991021dab801832/68747470733a2f2f706f7365722e707567782e6f72672f637562652f636f6d706f7365722d646973742d696e7374616c6c65722f762f737461626c652e737667)](https://packagist.org/packages/cube/composer-dist-installer) [![Total Downloads](https://camo.githubusercontent.com/988fd6ce17e55193a8ca530e58fe9f020d4839202974004e1f2fc900205c0b68/68747470733a2f2f706f7365722e707567782e6f72672f637562652f636f6d706f7365722d646973742d696e7374616c6c65722f646f776e6c6f6164732e737667)](https://packagist.org/packages/cube/composer-dist-installer) [![Latest Unstable Version](https://camo.githubusercontent.com/ce84c9f130b52dd51247a5e4e0586a7bde644dc0662195867a561128d7f4d2ff/68747470733a2f2f706f7365722e707567782e6f72672f637562652f636f6d706f7365722d646973742d696e7374616c6c65722f762f756e737461626c652e737667)](https://packagist.org/packages/cube/composer-dist-installer) [![License](https://camo.githubusercontent.com/1261c24f4526acf50c4b18c7da7f5d4737c8d41828701b4c18225e6172dc697c/68747470733a2f2f706f7365722e707567782e6f72672f637562652f636f6d706f7365722d646973742d696e7374616c6c65722f6c6963656e73652e737667)](https://packagist.org/packages/cube/composer-dist-installer)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
------------

[](#installation)

Simply use Composer to install by running:

```
composer require cube/composer-dist-installer:~1.0@beta

```

Usage
-----

[](#usage)

Add the following into your root `composer.json` file:

```
{
    "scripts": {
        "post-install-cmd": [
            "Cube\\ComposerDistInstaller\\Bootstrap::install"
        ]
    },
    "extra": {
        "dist-installer-params": {
            "file": "config/autoload/database.config.php.dist"
        }
    }
}
```

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:

```
{
    "extra": {
        "dist-installer-params": {
            "file": "config/autoload/database.config.php",
            "dist-file": "some/other/folder/file/database.dist"
        }
    }
}
```

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

[](#multiple-files)

You can specify more than one file to be processed by using the following alternate syntax:

```
{
    "extra": {
        "dist-installer-params": [
            {
                "file": "config/autoload/database.config.php",
                "dist-file": "some/other/folder/file/database.dist"
            },
            {
                "file": "config/autoload/session.config.php",
                "dist-file": "some/other/folder/file/session.dist"
            }
        ]
    }
}
```

Template 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:

```
