This package aims to make a json setting file usable and easy maintainable.
The json file is build like this:
{
"foo":{
"bar":"foo",
"bars":"foos",
}
}
Where foo
is a group and bar
a key value pair.
It is possible to append groups and add new groups.
Getting a setting is straight forward.
//gets the value of bar in the foo group
$value = $s->get('foo.bar'); //foo
//gets the value of bars in the foo group
$values = $s->get('foo.bars'); //foos
This can be done by giving $settings
as a parameter when creating a new Settings object
$settings
can either be a json string or an array
$settings = array('foo'=>array('bar'=>'foo', 'bars'=>'foos'));
$s = new Settings($settings);
print_r($s->getSettingsAsArray());
/**
* Array
*(
* [foo] => Array
* (
* [bar] => foo
* [bars] => foos
* )
*
*)
*
*/
Or by calling the fill method
$settings = array('foo'=>array('bar'=>'foo', 'bars'=>'foos'));
$s = new Settings();
$s->fill($settings);
To add new settings to a existing group goes as follows
//we assume the settings file is already filled
$s->appendGroup('foo','cackes');
The group foo has now a new key value pair with the key 'cackes'
. The value defaults to ''
If you want to add a default value use a third parameter like this
$s->appendGroup('foo','cackes','cheesecake');
Adding a new group to the settings file, and give it some default settings.
$s->addGroup('files')->appendGroup('files', 'logfile', '/location/to/file.log');
-
Make it a separate package
-
Add functionality to extend the json settings
-
Make the settings file dynamic
-
Allow greater settings depth
-
Allow arrays when adding a new group