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

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

kron0s/config-service-provider
==============================

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

v1.2.2(11y ago)024MITPHP

Since Jul 14Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (10)Used By (0)

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

[](#configserviceprovider)

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

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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 68.2% 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 ~90 days

Recently: every ~121 days

Total

9

Last Release

4334d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b37c15018ad73da5b58fca27562190ac5d8c8676bba396c88c1d0d74018f8f2?d=identicon)[Kron0S](/maintainers/Kron0S)

---

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)")[![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)")[![Kron0S](https://avatars.githubusercontent.com/u/553268?v=4)](https://github.com/Kron0S "Kron0S (2 commits)")[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (2 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")[![gido](https://avatars.githubusercontent.com/u/101859?v=4)](https://github.com/gido "gido (1 commits)")[![danapplegate](https://avatars.githubusercontent.com/u/759698?v=4)](https://github.com/danapplegate "danapplegate (1 commits)")

---

Tags

silex

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/kron0s-config-service-provider/health.svg)](https://phpackages.com/packages/kron0s-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)
