PHPackages                             lokhman/silex-config - 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. lokhman/silex-config

ActiveLibrary

lokhman/silex-config
====================

Silex 2.0+ service provider for lightweight framework configuration

2.0.2(9y ago)530.7k—4.8%21MITPHP

Since Jul 16Pushed 7y ago2 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (8)Used By (1)

silex-config
============

[](#silex-config)

[![Build Status](https://camo.githubusercontent.com/a9448b15225a85100359c1859197147e6848d4891b4c0b5705b52555d335043f/68747470733a2f2f7472617669732d63692e6f72672f6c6f6b686d616e2f73696c65782d636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lokhman/silex-config)[![StyleCI](https://camo.githubusercontent.com/11b5fe4aaf1f8b75defee2dccbbfee25963d8368df9f57aece867877ab092daf/68747470733a2f2f7374796c6563692e696f2f7265706f732f33393230333436362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/39203466)[![codecov](https://camo.githubusercontent.com/6ca61fca654eea2985016ce86c53802a9ce22a9c5583d155fcd09a51021fe2e1/68747470733a2f2f636f6465636f762e696f2f67682f6c6f6b686d616e2f73696c65782d636f6e6669672f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/lokhman/silex-config)[![Downloads](https://camo.githubusercontent.com/24491cae40ecb7dd463f8d96e221da743e9628368118657e611e221cb9f46e29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6b686d616e2f73696c65782d636f6e6669672e737667)](https://packagist.org/packages/lokhman/silex-config/stats)[![Packagist](https://camo.githubusercontent.com/e69fb415ce27a65f62e492851e4df6c9c6eb1c9e20c5809b91c1c979e246c53c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6b686d616e2f73696c65782d636f6e6669672e737667)](https://packagist.org/packages/lokhman/silex-config)[![License](https://camo.githubusercontent.com/db8337e60a69e8cf1b56f6a2c1159e6b9e805ed6c7e1faad69c3250eda3c47ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f6b686d616e2f73696c65782d636f6e6669672e737667)](https://github.com/lokhman/silex-config/blob/master/LICENSE)

Lightweight configuration service provider for [**Silex 2.0+**](http://silex.sensiolabs.org/) micro-framework.

> This project is a part of [`silex-tools`](https://github.com/lokhman/silex-tools) library.

Installation
----------------------------------------------------

[](#installation)

You can install `silex-config` with [Composer](http://getcomposer.org):

```
composer require lokhman/silex-config

```

Documentation
------------------------------------------------------

[](#documentation)

Simple and lightweight configuration provider, which uses JSON files to manage application configuration. Library supports different environments via setting a global environment variable.

```
use Lokhman\Silex\Provider\ConfigServiceProvider;

$app->register(new ConfigServiceProvider(), [
    'config.dir' => __DIR__ . '/../app/config',
]);

```

### File structure

[](#file-structure)

First off, create a `config` folder in your application directory and add configuration JSON files one per intended environment (default is `local`):

```
/
  app/
    config/
      dev.json
      local.json
      prod.json
      staging.json
    logs/
  src/
  tests/
  vendor/
  web/
    index.php
  composer.json
  ...

```

### Config files

[](#config-files)

Next, add all your defaults to the config files, e.g.:

```
{
    "env": "%__ENV__%",
    "debug": true,
    "dbs.options": {
        "default": {
            "driver": "pdo_mysql",
            "host": "localhost",
            "dbname": "database",
            "user": "root",
            "password": "",
            "charset": "utf8"
        }
    },
    "any": {
        "other": "constant"
    }
}

```

### Register

[](#register)

Now register service provider in your Silex application:

```
use Lokhman\Silex\Provider as ToolsProviders;

$app->register(new ToolsProviders\ConfigServiceProvider(), [
    'config.dir' => __DIR__ . '/../app/config',
]);

```

`config.dir` parameter refers to a configuration folder path with JSON files.

### Global environment variable

[](#global-environment-variable)

Finally, you can set up your web server to add support of different deployment environments. In order to do this, you have to set a global environmental variable.

#### nginx + PHP-FPM

[](#nginx--php-fpm)

```
fastcgi_param SILEX_ENV prod

```

#### Apache

[](#apache)

```
SetEnv SILEX_ENV prod

```

### CLI

[](#cli)

```
$ SILEX_ENV=prod bash -c "php bin/console migrations:status"

```

If you use [Console Application](https://github.com/lokhman/silex-console) together with `ConfigServiceProvider` you can pass `--env` (`-e` in short) option to all registered commands:

```
$ php bin/console migrations:status --env=prod

```

Parameters
----------

[](#parameters)

`ConfigServiceProvider` supports the following parameters:

ParameterDescriptionDefault`config.dir`Folder path with JSON files.`null``config.params`Array of replacement tokens to use in configuration.`[]``config.env`Environment to use strictly on provider registration (ignores global environment variable).`"local"``config.varname`Name of global environment variable.`"SILEX_ENV"`By default, service provider embeds tokens `__DIR__` and `__ENV__`, as well as all PHP environment variables (e.g. `REMOTE_ADDR`, `SERVER_NAME`, etc).

Dynamic tokens
--------------

[](#dynamic-tokens)

You can define tokens dynamically in the JSON files using property `$params`:

```
local.json
{
    "$params": {
        "SECRET": "3ecd45ff71c87269569e682f2f6b2ec4"
    },
    "settings": {
        "prop1": "%SECRET%",
        "prop2": "%secret%",
        "prop3": "%SeCrEt%"
    }
}

```

**N.B.:** All tokens are case insensitive.

Extending
---------

[](#extending)

You can extend JSON configuration (include one JSON file into another) simply using root property `$extends`, that points to the file to extend (file extension can be omitted). For example:

```
local.json
{
    "env": "%__ENV__%",
    "debug": true,
    "locale": "en"
}

prod.json
{
    "$extends": "local",
    "debug": false
}

```

License
------------------------------------------

[](#license)

Library is available under the MIT license. The included LICENSE file describes this in detail.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

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

Recently: every ~147 days

Total

7

Last Release

3358d ago

Major Versions

0.2 → v1.x-dev2015-07-29

1.0 → 2.0.02017-01-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/17a4b2bb3c64905c2663115cb0a3ef36854123b51709645576a591fb72fbef10?d=identicon)[lokhman](/maintainers/lokhman)

---

Top Contributors

[![lokhman](https://avatars.githubusercontent.com/u/7714105?v=4)](https://github.com/lokhman "lokhman (33 commits)")

---

Tags

configsilextoolsconfigtoolssilex

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lokhman-silex-config/health.svg)

```
[![Health](https://phpackages.com/badges/lokhman-silex-config/health.svg)](https://phpackages.com/packages/lokhman-silex-config)
```

###  Alternatives

[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[jakoch/nginx-conf

A Nginx Conf parser and generator.

111.5k](/packages/jakoch-nginx-conf)

PHPackages © 2026

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