PHPackages                             reva2/config-service-provider - 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. reva2/config-service-provider

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

reva2/config-service-provider
=============================

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

v2.0.0(9y ago)240.9k—9.4%1MITPHP

Since Jul 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/reva2/ConfigServiceProvider)[ Packagist](https://packagist.org/packages/reva2/config-service-provider)[ RSS](/packages/reva2-config-service-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (12)Used By (1)

ConfigServiceProvider
=====================

[](#configserviceprovider)

[![Build Status](https://camo.githubusercontent.com/41e2ae540ecded71ac848ed875faa247779377fdb95e4cfe9a47ddaf4fa7e683/68747470733a2f2f7472617669732d63692e6f72672f72657661322f436f6e6669675365727669636550726f76696465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/reva2/ConfigServiceProvider)

A config ServiceProvider for [Silex 2](http://silex.sensiolabs.org) with support for php, json, yaml, and toml.

This is fork of [igorw/config-service-provider](https://github.com/igorw/ConfigServiceProvider).

Usage
-----

[](#usage)

### Passing a config file

[](#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.

```
$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.

**config/prod.json**

```
{
    "debug": false
}

```

**config/dev.json**

```
{
    "debug": true
}

```

To switch between them, just set the `APP_ENV` environment variable. In apache that would be:

```
SetEnv APP_ENV dev

```

Or in nginx with fcgi:

```
fastcgi_param APP_ENV dev

```

### Replacements

[](#replacements)

Also, you can pass an array of replacement patterns as second argument.

```
$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.

**/config/services.json**

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

```

You can also specify replacements inside the config file by using a key with `%foo%` notation:

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

```

### Using Yaml

[](#using-yaml)

To use Yaml instead of JSON, just pass a file that ends on `.yml`:

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

```

Note, you will have to require the `~2.1` of the `symfony/yaml` package.

### Using TOML

[](#using-toml)

To use [TOML](https://github.com/mojombo/toml) instead of any of the other supported formats, just pass a file that ends on `.toml`:

```
$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.

### Using plain PHP

[](#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.

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

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

```

### Multiple config files

[](#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`.

### Register order

[](#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.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 64.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~158 days

Recently: every ~297 days

Total

10

Last Release

3629d ago

Major Versions

v1.2.2 → v2.0.02016-06-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bae35e83cd467b6521a74cf226a65408172eceb9e7213013bfa37e09e65a3d8?d=identicon)[reva2](/maintainers/reva2)

---

Top Contributors

[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (60 commits)")[![jeromemacias](https://avatars.githubusercontent.com/u/582446?v=4)](https://github.com/jeromemacias "jeromemacias (8 commits)")[![reva2work](https://avatars.githubusercontent.com/u/538756?v=4)](https://github.com/reva2work "reva2work (7 commits)")[![alcohol](https://avatars.githubusercontent.com/u/21414?v=4)](https://github.com/alcohol "alcohol (4 commits)")[![airdeck](https://avatars.githubusercontent.com/u/3452572?v=4)](https://github.com/airdeck "airdeck (3 commits)")[![rsvasyliev](https://avatars.githubusercontent.com/u/1588011?v=4)](https://github.com/rsvasyliev "rsvasyliev (2 commits)")[![fzerorubigd](https://avatars.githubusercontent.com/u/935155?v=4)](https://github.com/fzerorubigd "fzerorubigd (2 commits)")[![jbinfo](https://avatars.githubusercontent.com/u/761378?v=4)](https://github.com/jbinfo "jbinfo (2 commits)")[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (2 commits)")[![danapplegate](https://avatars.githubusercontent.com/u/759698?v=4)](https://github.com/danapplegate "danapplegate (1 commits)")[![gido](https://avatars.githubusercontent.com/u/101859?v=4)](https://github.com/gido "gido (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")

---

Tags

silex

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/reva2-config-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/reva2-config-service-provider/health.svg)](https://phpackages.com/packages/reva2-config-service-provider)
```

###  Alternatives

[igorw/config-service-provider

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

215636.5k13](/packages/igorw-config-service-provider)[franmomu/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

1312.1k](/packages/franmomu-silex-pagerfanta-provider)[emanueleminotto/faker-service-provider

Faker Service Provider for Silex

162.9k](/packages/emanueleminotto-faker-service-provider)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
