Config Builder

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 "danzabar\config":"2.1.x"

Basic Usage

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;

Note that will only LOAD a file, you can also CREATE a new file like:

$file = new ConfigFile();

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



// You can also save into different formats..



// Although the file has been deleted, you can restore this by saving


The contents of the file is converted to a PHP object and presented as a ParamBag instance in the ConfigFile

// Get Params

// Set params
$file->params()->test = 'foo';

The ParamBag class has many functions to help manipulate the data inside it...

// Load an array into the params

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

// We can get the params array back

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

ParamBags Also have a backup function


$file->params()->foo = 'new';


That pretty much wraps it up... remember this project is on github.. Where there is more documentation.

comments powered by Disqus