agoosev/json-config-loader

A simple class for reading configuration from JSON file

1.1 2015-11-28 18:02 UTC

README

Build Status

A simple class for reading configuration from JSON file.

Usage

Config is singleton.

First, create config object:

$config = Config::getInstance();
$config->loadConfig('config.json');

After that, you can get values from config:

$config->getValue('database.host'); //return value or null if key 'host' not exists.
$config->getValue('database.type', 'mysql'); // return value or 'mysql' if key 'type' not exitst

Set values:

//set value 'localhost' for key 'host'. If key don`t exists, key will be created.
$config->setValue('database.host', 'localhost');

Class have method 'reset', which set null for Config instance. I make this for testing with phpUnit.