Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.

Berlioz Configuration

Latest Version Software license Build Status Quality Grade Total Downloads

Berlioz Configuration is a PHP library to manage your configuration files.



You can install Berlioz Configuration with Composer, it's the recommended installation.

$ composer require berlioz/config


  • PHP ^7.1 || ^8.0
  • PHP libraries:
    • ext-json
  • Packages:
    • berlioz/helpers


Create configuration object

You can create configuration like this:

// Using files
$config = new JsonConfig('/path/of-project/config/config.json', true);
$config = new ExtendedJsonConfig('/path/of-project/config/config.json', true);

// Using data
$config = new JsonConfig('{"config": "test"}');
$config = new ExtendedJsonConfig('{"config": "test"}');

Second parameter of constructor is if the first parameter is an URL.

Get value of key

Configuration file:

  "var1": "value1",
  "var2": {
    "var3": "value3"

To get value, you must do like this:

$config->get('var1'); // returns string 'value1'
$config->get('var2'); // returns array ['var3' => 'value3']
$config->get('var2.var3'); // returns 'value3'
$config->get('var3'); // returns NULL
$config->get('var3', true); // returns TRUE (default value given)

If you get an unknown value, the method return the default value given in second parameter else NULL.

You can also test if a key exists, like this:

$config->has('var1'); // returns true
$config->has('var2'); // returns true
$config->has('var4'); // returns false


In values of JSON keys, you can add this syntax to use variables: %var1.var2%, that's get key var1.var2 in replacement of value.

Some variables are available by default:

  • php_version: the value of constant PHP_VERSION
  • php_version_id: the value of constant PHP_VERSION_ID
  • php_major_version: the value of constant PHP_MAJOR_VERSION
  • php_minor_version: the value of constant PHP_MINOR_VERSION
  • php_release_version: the value of constant PHP_RELEASE_VERSION
  • php_sapi: the value of constant PHP_SAPI
  • system_os: the value of constant PHP_OS
  • system_os_family: the value of constant PHP_OS_FAMILY

You can also define your own variables with the methods:

  • setVariable(string $name, mixed $value)
  • setVariables(array $variables)

WARNING: Priority is given to the user defined variable in the config object instead of JSON path.

Extended JSON format

We created an extended format of the JSON format. Just to do actions like include or extends JSON files.


  • Include another file: %include:filename.json%
  • Extends a file: %extends:filename.json, filename2.json, filename3.json%
  • Replace by an env variable: %env:VAR_NAME%
  • Replace by a constant: %const:VAR_NAME% or %constant:VAR_NAME%
  • Allow inline comments : // My comment (comment must be alone on a line)

You can define your own actions with static method ExtendedJsonConfig::addAction(string $name, callable $callback).

Extends configurations files

You can extends the current configuration file with another with special key @extends:

  // Extends
  "@extends": "another.json",
  // Keys
  "key": "value"


File config.json:

  "@extends": "config.another.json",
  "var1": "value1",
  "var2": {
    "var3": "value3"
  "var4": "%include:config3.json%",
  "var5": "%extends:config3.json, config2.json%"

File config.another.json:

  "var.another": "value",
  "var1": "valueX"

File config2.json:

  "var6": "value1",
  "var7": false

File config3.json:

  "var7": true

The final config file is:

  "var.another": "value",
  "var1": "value1",
  "var2": {
    "var3": "value3"
  "var4": {
    "var7": true
  "var5": {
    "var6": "value1",
    "var7": false


Berlioz Configuration is a PHP library to manage your configuration files.




No packages published