2017 © Pedro Peláez
 

library config-service-provider

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

image

igorw/config-service-provider

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

  • Wednesday, July 23, 2014
  • by igorw
  • Repository
  • 10 Watchers
  • 225 Stars
  • 395,366 Installations
  • PHP
  • 36 Dependents
  • 6 Suggesters
  • 66 Forks
  • 23 Open issues
  • 10 Versions
  • 3 % Grown

The README.md

ConfigServiceProvider

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

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., (*2)

$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., (*3)

config/prod.json, (*4)

{
    "debug": false
}

config/dev.json, (*5)

{
    "debug": true
}

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

SetEnv APP_ENV dev

Or in nginx with fcgi:, (*7)

fastcgi_param APP_ENV dev

Replacements

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

$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., (*9)

/config/services.json, (*10)

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

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

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

Using Yaml

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

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

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

Using TOML

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

$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., (*15)

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., (*16)

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:, (*17)

$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., (*18)

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., (*19)

The Versions

23/07 2014

dev-master

9999999-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