2017 © Pedro Peláez
 

library dynamic-parameters-bundle

Runtime retrieval of parameters from environment variables for Symfony

image

incenteev/dynamic-parameters-bundle

Runtime retrieval of parameters from environment variables for Symfony

  • Sunday, April 30, 2017
  • by Stof
  • Repository
  • 7 Watchers
  • 47 Stars
  • 6,286 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 5 Open issues
  • 1 Versions
  • 13 % Grown

The README.md

DynamicParametersBundle

This bundle provides a way to read parameters from environment variables at runtime. The value defined in the container parameter is used as fallback when the environment variable is not available., (*1)

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Latest Stable Version Latest Unstable Version License, (*2)

Installation

Installation is a quick (I promise!) 2 step process:, (*3)

  1. Download IncenteevDynamicParametersBundle
  2. Enable the bundle

Step 1: Install IncenteevDynamicParametersBundle with composer

Run the following composer require command:, (*4)

$ composer require incenteev/dynamic-parameters-bundle

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:, (*5)

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Incenteev\DynamicParametersBundle\IncenteevDynamicParametersBundle(),
    );
}

Usage

Define the map of parameter names with the environment variable used to configure them., (*6)

# app/config/config.yml
incenteev_dynamic_parameters:
    parameters:
        database_host: DATABASE_HOST
        "database.name": DATABASE_NAME

Environment variables are always strings. To be able to set parameters of other types, the bundle supports parsing the environment variable as inline Yaml:, (*7)

# app/config/config.yml
incenteev_dynamic_parameters:
    parameters:
        use_ssl:
            variable: HAS_SSL
            yaml: true

ParameterHandler integration

If you are using the env-map feature of the Incenteev ParameterHandler, you can import the whole env-map very easily:, (*8)

# app/config/config.yml
incenteev_dynamic_parameters:
    import_parameter_handler_map: true
    parameters:
        something_else: NOT_IN_THE_COMPOSER_JSON

The ParameterHandler parses the environment variables as inline Yaml, so the Yaml parsing is automatically enabled for these variables when importing the map., (*9)

Note: Any parameter defined explicitly will win over the imported map., (*10)

By default, the bundle will look for the composer.json file in %kernel.root_dir%/../composer.json. If you use a non-standard location for your kernel, you can change the path to your composer.json file to read the env-map:, (*11)

# app/config/config.yml
incenteev_dynamic_parameters:
    import_parameter_handler_map: true
    composer_file: path/to/composer.json

Retrieving parameters at runtime

The bundle takes care of service arguments, but changing the behavior of $container->getParameter() is not possible. However, it exposes a service to get parameters taking the environment variables into account., (*12)

$this->get('incenteev_dynamic_parameters.retriever')->get('use_ssl');

Limitations

  • Getting a parameter from the container directly at runtime will not use the environment variable
  • Parameters or arguments built by concatenating other parameters together will not rely on the environment variables (yet)

The Versions

30/04 2017

dev-master

9999999-dev https://github.com/Incenteev/DynamicParametersBundle

Runtime retrieval of parameters from environment variables for Symfony

  Sources   Download

MIT

The Requires

 

symfony parameters environment variable