Coder Social home page Coder Social logo

digitalkaoz / dynamicparametersbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from incenteev/dynamicparametersbundle

0.0 3.0 0.0 15 KB

Runtime retrieval of parameters from environment variables for Symfony

License: MIT License

PHP 100.00%

dynamicparametersbundle's Introduction

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.

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Latest Stable Version Latest Unstable Version License

Installation

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

  1. Download IncenteevDynamicParametersBundle
  2. Enable the bundle

Step 1: Install IncenteevDynamicParametersBundle with composer

Run the following composer require command:

$ composer require incenteev/dynamic-parameters-bundle

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:

// 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.

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

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

# 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.

Note: Any parameter defined explicitly will win over the imported map.

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:

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

Retrieving parameters at runtime

The bundle taks 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.

$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)

dynamicparametersbundle's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.