PHPackages                             ojezu/dynamic-parameter-bundle - 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. ojezu/dynamic-parameter-bundle

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

ojezu/dynamic-parameter-bundle
==============================

Symfony3.4 bundle that facilitates dynamic parameter loading at start of each request

v2.0.0(6y ago)15.0k2MITPHP

Since Oct 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/OJezu/dynamic-parameter-bundle)[ Packagist](https://packagist.org/packages/ojezu/dynamic-parameter-bundle)[ RSS](/packages/ojezu-dynamic-parameter-bundle/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)Dependencies (7)Versions (8)Used By (0)

OJezu/DynamicParameterBundle
============================

[](#ojezudynamicparameterbundle)

This bundle enables having multiple configurations (installations) in one Symfony application. It does so, by supplying two independent features:

- Installation-aware kernel, and installation-dependent parameters
- Advanced parameter provider, that can read parameters from any source.

Combination of this features enable implementing multi-tenant applications, configured to use different resources separated at infrastructure level for each tenant. The resources can be database connection, filesystem adapters, etc. Moreover, configuration storage can be off-loaded to a database server, JSON file, zookeeper instance, with a custom or build-in parameter provider service, which will load appropriate configuration based on installation selected in application kernel.

### Requirements

[](#requirements)

This bundle requires Symfony 3.4, as it depends on advanced environment variable processing.

### Usage

[](#usage)

**Note:** Processors from this bundle *do not* read actual environment variables.

#### Multi-installation

[](#multi-installation)

Provide kernel with information about installation (see configuration below), and then in your configuration you can use that information as parameters.

```
#app/config/config.yml

ojezu_dynamic_parameter:
    multi_installation: true

file_storage:
    bucket: "/myapp/installation/%env(ojezu_installation:name)%/"
```

Usage is similar to plain environment variables, but gives more control, as it's developer who decides what and from where will find its way into `Installation` object. Installation parameters can be set based on request headers, php-cli arguments and any other data source, as implemented in application using this bundle (see configuration below).

All `Installation` class instance public properties can be accessed, and Installation class can be extended, with properties you need.

#### Advanced parameter provider

[](#advanced-parameter-provider)

After configuring advanced parameter provider (see below), you are able to map parameters to abstract configuration paths used to obtain parameter values from any source, as long as there is a provider for that source. Providers are very simple services, that just have to implement `ParameterProviderInterface`. JSON local and remote file provider is already provided by this bundle, more powerful than Symfony built-in "json:" env variable processor.

```
# app/config/config.yml

ojezu_dynamic_parameter:
    advanced_parameters:
        provider: 'OJezu\DynamicParameterBundle\Service\LocalJsonFileParameterProvider'
        parameter_map:
            database_host: { path: ['database', 'host'] }

doctrine:
    dbal:
        driver:   pdo_mysql
        server_version: 5.7
        host:     "%env(ojezu_param:database_host)%"
```

```
# services.yml

services:
    OJezu\DynamicParameterBundle\Service\LocalJsonFileParameterProvider:
        arguments:
            - '%kernel.root_dir%/config/config.json'
```

This configuration will find database.host value in JSON config file, and provide it to DBAL configuration.

#### Using them together

[](#using-them-together)

While both features offer more than what's built in Symfony 3.4, using them together allows for easy management of multiple configurations supported by same Symfony application.

```
#app/config/config.yml

ojezu_dynamic_parameter:
    multi_installation: true
    advanced_parameters:
        provider: 'OJezu\DynamicParameterBundle\Service\LocalJsonFileParameterProvider'
        parameter_map:
            database_name: { path: ['installation', '%env(ojezu_installation:name)%', 'database', 'name'] }

doctrine:
    dbal:
        driver:   pdo_mysql
        server_version: 5.7
        host:   "mysql.example.com"
        dbname: "%env(ojezu_param:database_name)%"
```

```
#services.yml

services:
    OJezu\DynamicParameterBundle\Service\LocalJsonFileParameterProvider:
        arguments:
            - '%kernel.root_dir%/config/config.json'
```

```
{
  "installation": {
    "application1": {
      "database": {
        "name": "app1_database",
      }
    },
    "application2": {
      "database": {
        "name": "app2_database",
      }
    }
  }
}
```

### Configuration

[](#configuration)

#### Multi-installation

[](#multi-installation-1)

In order to be able to use multi-installation support:

1. Enable it in configuration:

    ```
    #app/config/config.yml

    ojezu_dynamic_parameter:
        multi_installation: true
    ```
2. Change your AppKernel to extend `\OJezu\DynamicParameterBundle\Kernel\Kernel`

    ```
