The Config package is great for frameworks or projects where you Write/Create/Edit/Merge configuration files in YAML or JSON. Since the last version I have dropped XML support, purely because it didn't fit well with YAML or JSON configurations.
You can install this package through composer, add this to your composer json
Since the last version all the functionality has been moved to a class called
ConfigFile, which is the only way to interact with the files now.
$file = new ConfigFile; $file->load('/directory/to/file.yml');
Note that will only LOAD a file, you can also CREATE a new file like:
$file = new ConfigFile(); $file->create('/destination/of/file.json');
There is also the init function which attempts to load the file first, and failing this, creates it.
So now you have a loaded file, what else can we do? Well lets go through a little list of features...
$file->save(); // You can also save into different formats.. $file->saveAs('json'); $file->saveAs('yml');
$file->delete(); // Although the file has been deleted, you can restore this by saving $file->save();
The contents of the file is converted to a PHP object and presented as a
ParamBag instance in the
// Get Params $file->params()->test; // Set params $file->params()->test = 'foo'; $file->save();
ParamBag class has many functions to help manipulate the data inside it...
// Load an array into the params $file->load(Array()); // We can set new values $file->params()->foo = 'bar'; // We can get set values $file->params()->foo; // bar // We can get check for set values isset($file->params()->bar) // false // unset a param unset($file->params()->bar) // We can get the params array back $file->params()->all(); // We can perform a recursive search and replace on all the data $file->params()->recursiveReplace('search', 'replace'); // We can also merge another array into the params $file->params()->merge(Array());
ParamBags Also have a backup function
$file->params()->backup(); $file->params()->foo = 'new'; $file->params()->rollback();
That pretty much wraps it up... remember this project is on github.. Where there is more documentation.