2017 © Pedro Peláez
 

library config-service-provider

A config ServiceProvider for Silex 2.x with support for php, json and yaml.

image

reva2/config-service-provider

A config ServiceProvider for Silex 2.x with support for php, json and yaml.

  • Friday, June 10, 2016
  • by reva2
  • Repository
  • 1 Watchers
  • 3 Stars
  • 12,472 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 66 Forks
  • 0 Open issues
  • 12 Versions
  • 19 % Grown

The README.md

ConfigServiceProvider

Build Status, (*1)

A config ServiceProvider for Silex 2 with support for php, json, yaml, and toml., (*2)

This is fork of igorw/config-service-provider., (*3)

Usage

Passing a config file

Pass the config file's path to the service provider's constructor. This is the recommended way of doing it, allowing you to define multiple environments., (*4)

$env = getenv('APP_ENV') ?: 'prod';
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/$env.json"));

Now you can specify a prod and a dev environment., (*5)

config/prod.json, (*6)

{
    "debug": false
}

config/dev.json, (*7)

{
    "debug": true
}

To switch between them, just set the APP_ENV environment variable. In apache that would be:, (*8)

SetEnv APP_ENV dev

Or in nginx with fcgi:, (*9)

fastcgi_param APP_ENV dev

Replacements

Also, you can pass an array of replacement patterns as second argument., (*10)

$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/services.json", array(
    'data_path' => __DIR__.'/data',
)));

Now you can use the pattern in your configuration file., (*11)

/config/services.json, (*12)

{
    "xsl.path": "%data_path%/xsl"
}

You can also specify replacements inside the config file by using a key with %foo% notation:, (*13)

{
    "%root_path%": "../..",
    "xsl.path": "%root_path%/xsl"
}

Using Yaml

To use Yaml instead of JSON, just pass a file that ends on .yml:, (*14)

$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/services.yml"));

Note, you will have to require the ~2.1 of the symfony/yaml package., (*15)

Using TOML

To use TOML instead of any of the other supported formats, just pass a file that ends on .toml:, (*16)

$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/services.toml"));

Note, you will have to require the ~0.1 of the jamesmoss/toml package and you are using a bleeding edge configuration format, as the spec of TOML is still subject to change., (*17)

Using plain PHP

If reading the config file on every request becomes a performance problem in production, you can use a plain PHP file instead, and it will get cached by APC., (*18)

You'll have to rewrite your config to be a PHP file that returns the array of config data, and also make sure it ends with .php:, (*19)

$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/prod.php"));

Multiple config files

You can use multiple config files, e. g. one for a whole application and a specific one for a task by calling $app->register() several times, each time passing another instance of Igorw\Silex\ConfigServiceProvider., (*20)

Register order

Make sure you register ConfigServiceProvider last with your application. If you do not do this, the default values of other Providers will override your configuration., (*21)

The Versions

10/06 2016

dev-master

9999999-dev

A config ServiceProvider for Silex 2.x with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

10/06 2016

v2.0.0

2.0.0.0

A config ServiceProvider for Silex 2.x with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

23/07 2014

dev-1.x-dev

dev-1.x-dev

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

06/07 2014

v1.2.2

1.2.2.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

31/05 2013

v1.2.1

1.2.1.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

23/04 2013

v1.2.0

1.2.0.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

09/03 2013

v1.1.5

1.1.5.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

05/03 2013

v1.1.4

1.1.4.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

03/02 2013

v1.1.3

1.1.3.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

29/01 2013

v1.1.2

1.1.2.0

A config ServiceProvider for Silex with support for php, json and yaml.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

03/01 2013

v1.1.1

1.1.1.0

A JSON/Yaml-based config ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

14/07 2012

v1.0.0

1.0.0.0

A JSON/Yaml-based config ServiceProvider for Silex.

  Sources   Download

MIT

The Requires

 

The Development Requires

silex