2017 © Pedro Peláez
 

library config-service-provider

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

image

saxulum/config-service-provider

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

  • Tuesday, October 11, 2016
  • by dominikzogg
  • Repository
  • 3 Watchers
  • 14 Stars
  • 26,838 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 67 Forks
  • 1 Open issues
  • 16 Versions
  • 6 % Grown

The README.md

ConfigServiceProvider

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality, (*1)

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

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

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

config/prod.json, (*5)

{
    "debug": false
}

config/dev.json, (*6)

{
    "debug": true
}

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

SetEnv APP_ENV dev

Or in nginx with fcgi:, (*8)

fastcgi_param APP_ENV dev

Replacements

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

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

/config/services.json, (*11)

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

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

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

Using Yaml

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

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

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

Using TOML

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

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

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

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

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

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

The Versions

11/10 2016

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

The Development Requires

silex pimple

11/10 2016

2.0.1

2.0.1.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

silex pimple

01/12 2015

2.0.0

2.0.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

silex pimple

01/12 2015

1.x-dev

1.9999999.9999999.9999999-dev

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

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

01/12 2015

v1.2.5

1.2.5.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

09/08 2015

v1.2.4

1.2.4.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

silex

05/06 2015

v1.2.3

1.2.3.0

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