Composer script handling your ignored parameter file

Overview

Managing your ignored parameters with Composer

This tool allows you to manage your ignored parameters when running a composer install or update. It works when storing the parameters in a Yaml file under a single top-level key (named parameters by default). Other keys are copied without change.

CI Latest Stable Version Latest Unstable Version

Usage

Add the following in your root composer.json file:

{
    "require": {
        "incenteev/composer-parameter-handler": "~2.0"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters"
        ]
    },
    "extra": {
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

The app/config/parameters.yml will then be created or updated by the composer script, to match the structure of the dist file app/config/parameters.yml.dist by asking you the missing parameters.

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": {
        "incenteev-parameters": {
            "file": "app/config/parameters.yml",
            "dist-file": "some/other/folder/to/other/parameters/file/parameters.yml.dist"
        }
    }
}

The script handler will ask you interactively for parameters which are missing in the parameters file, using the value of the dist file as default value. All prompted values are parsed as inline Yaml, to allow you to define true, false, null or numbers easily. If composer is run in a non-interactive mode, the values of the dist file will be used for missing parameters.

Warning: This parameters handler will overwrite any comments or spaces into your parameters.yml file so handle with care. If you want to give format and comments to your parameter's file you should do it on your dist version.

Keeping outdated parameters

Warning: This script removes outdated params from parameters.yml which are not in parameters.yml.dist If you need to keep outdated params you can use keep-outdated param in the configuration:

{
    "extra": {
        "incenteev-parameters": {
            "keep-outdated": true
        }
    }
}

Using a different top-level key

The script handler looks for a parameters key in your dist file. You can change this by using the parameter-key param in the configuration:

{
    "extra": {
        "incenteev-parameters": {
            "parameter-key": "config"
        }
    }
}

Using environment variables to set the parameters

For your prod environment, using an interactive prompt may not be possible when deploying. In this case, you can rely on environment variables to provide the parameters. This is achieved by providing a map between environment variables and the parameters they should fill:

{
    "extra": {
        "incenteev-parameters": {
            "env-map": {
                "my_first_param": "MY_FIRST_PARAM",
                "my_second_param": "MY_SECOND_PARAM"
            }
        }
    }
}

If an environment variable is set, its value will always replace the value set in the existing parameters file.

As environment variables can only be strings, they are also parsed as inline Yaml values to allows specifying null, false, true or numbers easily.

Renaming parameters

If you are renaming a parameter, the new key will be set according to the usual routine (prompt if possible, use environment variables, use default). To have the parameters handler use the value of an (obsolete) parameter, specify a rename-map:

{
    "extra": {
        "incenteev-parameters": {
            "rename-map": {
                "new_param_1": "old_param_1",
                "new_param_2": "old_param_2"
            }
        }
    }
}

This will create the new parameters new_param_1 and new_param_2 while using the values from old_param_1 and old_param_2, respectively. It will not remove the old parameters unless you've also removed them from the dist version.

If the old parameter is no longer present (maybe because it has been renamed and removed already), no parameters are overwritten. You don't need to remove obsolete parameters from the rename map once they have been renamed.

Managing multiple ignored files

The parameter handler can manage multiple ignored files. To use this feature, the incenteev-parameters extra should contain a JSON array with multiple configurations inside it instead of a configuration object:

{
    "extra": {
        "incenteev-parameters": [
            {
                "file": "app/config/parameters.yml",
                "env-map": {}
            },
            {
                "file": "app/config/databases.yml",
                "dist-file": "app/config/databases.dist.yml",
                "parameter-key": "config"
            }
        ]
    }
}
Comments
  • add support <env>.<dist-file>

    add support .

    | Q | A | | --- | --- | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Tests pass? | yes |

    We have a large PHP project with different environments (stage [pre-prod], dev, test, etc). Each of them has a lot of individual parameters.

    The solution is as follows:

    • create environment specific parameter files
      • parameters.yml - basis
      • test.parameters.yml
      • stage.parameters.yml
    • run APP_ENV=stage composer install, where name of environment variable (in this example is APP_ENV) is customizable
    opened by kamilsk 13
  • Can't use array for generating output parameters file with map-env

    Can't use array for generating output parameters file with map-env

    Hello, I have settings from parameters.yml.dist mapped like this: ...

    "incenteev-parameters": {
                "file": "app/config/parameters.yml",
    
                "env-map": {
                    "database_driver":                  "DATABASE_DRIVER",
                     ......
                    "pawq_param":                       "PAWQ_PARAM"
                }
            },
    

    Now when during generation of parameters.yml I use

    $ export PAWQ_PARAM=testvalue
     composer install --optimize-autoloader --no-progress --no-interaction;cat app/config/parameters.yml
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
    Nothing to install or update
    Generating optimized autoload files
    > Incenteev\ParameterHandler\ScriptHandler::buildParameters
    Creating the "app/config/parameters.yml" file
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
    Clearing the cache for the dev environment with debug true
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
    Trying to install assets as symbolic links.
    Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
    The assets were installed using symbolic links.
    Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
    The assets were installed using symbolic links.
    Installing assets for Nelmio\ApiDocBundle into web/bundles/nelmioapidoc
    The assets were installed using symbolic links.
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
    
    # This file is auto-generated during the composer install
    parameters:
    .....
    pawq_param: testvalue
    ....
    

    but it does not work with arrays (default value from parameters.yml.dist is used):

    $ export PAWQ_PARAM=("testval1", "testval2")
    $ export | grep PAWQ
    declare -ax PAWQ_PARAM='([0]="testval1," [1]="testval2")'
    $ composer install --optimize-autoloader --no-progress --no-interaction;cat app/config/parameters.yml
    ......
    # This file is auto-generated during the composer install
    parameters:
    .....
        pawq_param:
            - val1
            - val2
    

    The output in parameters.yml should be:

     pawq_param:
           - testval1
           - testval2
    
    opened by crashev 10
  • Extracting the ScriptHandler's logic for usage outside of composer

    Extracting the ScriptHandler's logic for usage outside of composer

    I was wondering if there would be a way to extract the logic of the composer's ScriptHandler into another class (or maybe a Symfony2 command ?), so that it can be used outside of composer.

    I am deploying my application to a server having complete network restriction (so it's impossible to use composer install during the deployment), so we have deploy branches containing the vendors. However, we do not have the parameters.yml file in it as its configuration differ on the server, and we often find ourselves deploying the application with new parameters and having issues because the parameters are not updated beforehand.

    If this logic could be extracted, we would be able to execute it before executing any command on the newly deployed application, and therefore avoiding errors.

    What do you think?

    enhancement 
    opened by gnutix 10
  • Support of multiple kernels

    Support of multiple kernels

    We are having something like multiple kernels: actually kernel only one, but it loads specific parameters.yml for different hostnames and store cache/logs in separate folders for hostnames.

    How it possible use ParameterHandler for this case?

    enhancement 
    opened by Koc 10
  • Add support to php file format

    Add support to php file format

    Bug fix: no Feature addition: yes Backwards compatibility break: no Tests pass: yes

    Added support to php file format. Useful when using outside Symfony project (eg. Silex)

        "extra": {
            "incenteev-parameters": {
                "file": "cfg/parameters.php",
                "file-extension": "php"
            }
        }
    
    opened by diegomarangoni 9
  • Support multiple dist files and write in one result file

    Support multiple dist files and write in one result file

    Addresses issue #21 :

    • Multiple dist files supported (parameters priority managed with array_merge)
    • BC OK
    • Writes the result in only one file, we don't want to charge the target framework
    opened by David-Guillot 9
  • [RFC] Be able to run only parameterHandler

    [RFC] Be able to run only parameterHandler

    Hello.

    I would be nice to run only this composer hook. I don't know how to do that.

    Our deploy process look like this:

    1. composer install
    2. compute a code revision with a SF command: export PHAR_FILENAME=$(./app/console insight:phar:filename --env=prod)
    3. run composer run-script to re-use your lib SYMFONY_ENV=prod php /opt/composer.phar run-script post-install-cmd --no-interaction
    4. again step 2 and 3, but with different var
    5. A least, warm cache

    So, I can, if you accept, to made the Composer\IO a soft dependency of the Processor class

    opened by lyrixx 8
  • Provide some sort of hint or explanation as to what parameters mean

    Provide some sort of hint or explanation as to what parameters mean

    It would be nice in my opinion if a parameter in the .dist file is prepended by a comment, that that comment would also be shown when asking for the parameters.

    i.e.:

    parameters:
        # A secret key that's used to generate certain security-related tokens
        secret:            test
    

    would result in:

    Some parameters are missing. Please provide them.
    A secret key that's used to generate certain security-related tokens: secret (test):
    

    It is sometimes hard to convey in a variable name what you want users to input upon install.

    opened by Intrepidity 7
  • Release version which is compatible with symfony 6

    Release version which is compatible with symfony 6

    Since https://github.com/Incenteev/ParameterHandler/pull/137 master is compatible with symfony 6.

    However, the latest release is nearly two years old (https://packagist.org/packages/incenteev/composer-parameter-handler#v2.1.4).

    Are there any plans to tag a new release?

    opened by W0rma 5
  • Added setter for dot notation when working with env vars

    Added setter for dot notation when working with env vars

    Mapping environment variables is a huge boost in deployment productivity. But when you're dealing with nested parameters, it's a huge pain to map variables properly, since you have to store a JSON object inside the environment variable. This PR ads a new feature that allows you to use dot notation to reach nested values.

    Example:

    "env-map": {
        "database.default.dbname": "DEFAULT_DB_NAME",
    }
    
    opened by klaussilveira 5
  • Get parameters from vendors

    Get parameters from vendors

    This pull request handles two problems - getting parameters automatically not only from app/config/parameters.yml.dist but also from vendors, and problem with exporting inline arrays to parameters.yml .

    Now you can add a file with default configuration in %BUNDLE%/Resources/config/app/parameters.yml.dist and composer with catch for those parameters while first installation like they have been placed in app/config/parameters.yml.dist.

    It will improves copying required parameters to app/config/parameters.yml.dist will be unnecessary during installation new bundle.

    There was another problem. If there was an array in parameters.yml.dist installer asked for definition of this array as a string (ex. [param1 = param1value, param2 = param2value]). Now installer is asking for all single parameters step by step and putting it to parameters.yml in not inline array.

    You can define when system should define inline arrays in extra parameters in composer.json as yml-depth and default value is 99 as in master.

    opened by piotrpasich 5
  • Ignore control characters

    Ignore control characters

    Hello,

    when entering an input, it can sometimes happen that the user inserts a control character. For example, in the Mac Terminal, just pressing the ESC key will insert the \e character into the string, which is extremely dangerous for further processing.

    I think entering values should be treated against entering control characters.

    For example, I enter ESC to the mailer_transport constant, which deletes the following character in the XML:

    Snímek obrazovky 2021-11-24 v 14 26 12 Snímek obrazovky 2021-11-24 v 14 24 52

    Thanks.

    opened by janbarasek 1
  • Add an option to disable parameter handler in composer production mode

    Add an option to disable parameter handler in composer production mode

    When you use the composer post-install scripts to build your app in production, you don't always want your parameters to be handled by the parameter handler. We have the option to run composer with the --no-scripts flag, and create an other script to call after the composer install specifically in production, but it seems less comfortable than just add an option to disable the parameter handler when the --no-dev flag is given to composer.

    opened by MartinLG 0
  • Manage other configuration file format

    Manage other configuration file format

    Could managing another config file format like xml or php be considered?

    It may be useful like for Prestashop automation. This projects use parameters.php file.

    opened by soullivaneuh 1
  • Handle constants from .dist

    Handle constants from .dist

    I have a use case where the mcrypt cipher and mode are stored into the .dist file.

    parameters:
        cipher: !php/const:MCRYPT_RIJNDAEL_128
        mode: !php/const:MCRYPT_MODE_CBC
    

    After the build of the parameters.yml file, these two keys are set to null.

    I can submit a PR to correct that case but I just wanted to know your opinion about this issue.

    Regards,

    opened by fullmoonissue 8
  • Option to throw exception on missing parameters in non-interactive mode?

    Option to throw exception on missing parameters in non-interactive mode?

    Would it be possible to add an option so that, in non-interactive mode when a parameter is missing, an exception is thrown rather than the default copied from the .dist file?

    Use-case: The parameter handler is great for our developers when they are working. But our deployments are automated. Usually the defaults given in .dist are not suitable for CI, QA or production environments. I want our build process to fail when keys are missing from our parameters file, and not copy the defaults.

    opened by sandermarechal 0
Releases(v2.1.5)
  • v2.1.5(May 25, 2022)

  • v2.1.3(Feb 13, 2018)

  • v2.1.2(Nov 10, 2015)

    • Mark symfony/yaml 3 as supported to be compatible with Symfony 3
    • Dropped support for symfony/yaml 2.2 and older (which are long unmaintained)
    • Added testing on PHP 7
    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Jun 3, 2015)

  • v2.1.0(Dec 7, 2013)

    • Move most of the logic to a Processor class which does not depend on the composer event and package. Ref #30
    • Add the support of existing empty file for Capifony compatibility
    • Add the support of multiple managed files
    • Preserve other top-level keys than the configured one in the file
    • Add a rename map used to rename parameters when updating the parameters file
    • Add the possibility to use another top-level key than parameters
    Source code(tar.gz)
    Source code(zip)
Owner
Incenteev
Incenteev
A PHP library that can be used manually as well as a CLI script that you can just run on your file

Run phpcs on files and only report new warnings/errors compared to the previous version. This is both a PHP library that can be used manually as well

Payton Swick 20 Aug 4, 2022
Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Imposter Plugin Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins. Built with ♥ by Typ

Typist Tech 127 Dec 17, 2022
This shell script and PHP file create a browseable HTML site from the Zig standard library source.

Browseable Zig standard library This shell script and PHP file create a browseable HTML site from the Zig standard library source. The idea is to inve

Dave Gauer 3 Mar 20, 2022
Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Stef Dawson 8 Oct 3, 2020
Magento-composer-installer - Composer installer for Magento modules

!!! support the maintainer of this project via Patreon: https://www.patreon.com/Flyingmana Magento Composer Installer The purpose of this project is t

null 213 Sep 24, 2022
Composer Repository Manager for selling Magento 2 extension and offering composer installation for ordered packages.

Magento 2 Composer Repository Credits We got inspired by https://github.com/Genmato. Composer Repository for Magento 2 This extension works as a Magen

EAdesign 18 Dec 16, 2021
Composer registry manager that help to easily switch to the composer repository you want

CRM - Composer Registry Manager Composer Registry Manager can help you easily and quickly switch between different composer repositories. 简体中文 Install

Tao 500 Dec 29, 2022
Dependency graph visualization for composer.json (PHP + Composer)

clue/graph-composer Graph visualization for your project's composer.json and its dependencies: Table of contents Usage graph-composer show graph-compo

Christian Lück 797 Jan 5, 2023
Composer Registrar Composer Plugin for Magento 2

This module add a global registration.php that replace the default glob search performed for each request to discover the components not installed from composer.

OpenGento 3 Mar 22, 2022
Drupal Composer Scaffold - A flexible Composer project scaffold builder

This project provides a composer plugin for placing scaffold files (like index.php, update.php, …) from the drupal/core project into their desired location inside the web root. Only individual files may be scaffolded with this plugin.

Drupal 44 Sep 22, 2022
Victor The Cleaner for Composer - This tool removes unnecessary files and directories from Composer vendor directory.

Victor The Cleaner for Composer This tool removes unnecessary files and directories from Composer vendor directory. The Cleaner leaves only directorie

David Grudl 133 Oct 26, 2022
Opinionated version of Wikimedia composer-merge-plugin to work in pair with Bamarni composer-bin-plugin.

Composer Inheritance Plugin Opinionated version of Wikimedia composer-merge-plugin to work in pair with bamarni/composer-bin-plugin. Usage If you are

Théo FIDRY 25 Dec 2, 2022
One-file composer scripts

Melody - One-file composer scripts Create a file named test.php: <?php <<<CONFIG packages: - "symfony/finder: ~2.8" CONFIG; $finder = Symfony\Com

SensioLabs 399 Aug 18, 2022
Applies a patch from a local or remote file to any package that is part of a given composer project.

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level in package config or separate JSON file. Declaration-free mode (using embedded info within patch files) is available as well.

Vaimo 245 Dec 15, 2022
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

null 2 Nov 20, 2021
Decimal handling as value object instead of plain strings.

Decimal Object Decimal value object for PHP. Background When working with monetary values, normal data types like int or float are not suitable for ex

Spryker 16 Oct 24, 2022
QueryHandler - Handling PDO ' s query with mySQL database

QueryHandler this class's method are static .... that mean you don't need to create an object to use it . All methodes will return an Exception if it

null 7 Aug 9, 2022
html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users

html-sanitizer html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users (who you cannot trust), allowing yo

Titouan Galopin 381 Dec 12, 2022
Firebird-PHP: A library created to meet a work need when handling a Firebird database

Firebird-PHP: A library created to meet a work need when handling a Firebird database

Philipe  Lima 3 Jun 27, 2022