2017 © Pedro Peláez
 

library json-settings

Package to easily manage a json setting file

image

wubs/json-settings

Package to easily manage a json setting file

  • Wednesday, June 19, 2013
  • by megawubs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

json-settings

This package aims to make a json setting file usable and easy maintainable., (*1)

The json file is build like this:, (*2)

{
    "foo":{
        "bar":"foo",
        "bars":"foos",
    }
}

Where foo is a group and bar a key value pair., (*3)

It is possible to append groups and add new groups., (*4)

usage examples

Getting settings

Getting a setting is straight forward., (*5)

//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

Filling the settings file

This can be done by giving $settings as a parameter when creating a new Settings object, (*6)

$settings can either be a json string or an array, (*7)

$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, (*8)

$settings = array('foo'=>array('bar'=>'foo', 'bars'=>'foos'));
$s = new Settings(); 
$s->fill($settings);

Appending groups

To add new settings to a existing group goes as follows, (*9)

//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, (*10)

$s->appendGroup('foo','cackes','cheesecake');

Add a new group

Adding a new group to the settings file, and give it some default settings., (*11)

$s->addGroup('files')->appendGroup('files', 'logfile', '/location/to/file.log');

Todo:

  • [x] Make it a separate package, (*12)

  • [x] Add functionality to extend the json settings, (*13)

  • [x] Make the settings file dynamic, (*14)

  • [ ] Allow greater settings depth, (*15)

  • [ ] Allow arrays when adding a new group, (*16)

The Versions

19/06 2013

dev-master

9999999-dev

Package to easily manage a json setting file

  Sources   Download

MIT