Skip to content


Subversion checkout URL

You can clone with
Download ZIP


kherge edited this page · 7 revisions

Table of Contents

  1. New Instance
    1. Adding Loaders
  2. Optional Configuration
    1. Caching
    2. Debugging
    3. File Name Prefixes (Environment Specific Files)
    4. Placeholders (On Load Search and Replace)

For Silex configuration, please see the service provider.

New Instance

To configure Wisdom, you must first create an instance.


    $wisdom = new Wisdom ('/path/to/config/files/directory');

Note that you may also pass an array of directory paths, instead.

Adding Loaders

Now you just need to add the loaders for the data formats you want to support. Wisdom includes three loaders, one for INI, JSON, and YAML. To add one, you simply pass a loader instance to the addLoader() method.


    $wisdom->addLoader(new KevinGH\Wisdom\Loader\INI);
    $wisdom->addLoader(new KevinGH\Wisdom\Loader\JSON);
    $wisdom->addLoader(new KevinGH\Wisdom\Loader\YAML);

Wisdom uses a modified version of the ArrayLoader class offered by Symfony's Config component. You may create your own loader by extending the KevinGH\Wisdom\Loader\Loader abstract class. Because the abstract class implements Symfony\Component\Config\Loader\LoaderInterface, you will still need to create your own load() and supports() methods.

Your Wisdom configuration manager instance is now ready to be used.


    $iniData = $wisdom->get('test.ini');
    $jsonData = $wisdom->get('test.json');
    $yamlData = $wisdom->get('test.yml');

Optional Configuration


Caching is only performed when a cache directory path has been set. To set a cache directory path, you will need to call setCache().




The Symony Config ConfigCache class is used to create and manage cache files. The cache class does not update the cached file unless debugging is enabled. To enable debugging, you need call the setDebug() method. Passing TRUE enables debugging, while passing FALSE disables it.



File Name Prefixes

As you develop your application, you may realize that you need different configuration files for different environments. Wisdom supports this by offering the ability to set a file name prefix. To set a file name prefix, you will need to call the setPrefix() method.




The get() method will first try to load sub/dev.test.yml, then fallback to sub/test.yml.


Wisdom supports the use of placeholders in raw configuration file data. Placeholders are fixed strings that are replaced before the raw data is parsed into native PHP data. To set placeholder values, you will need to call the setValues() method. Placeholders, such as %myVariable%, are replaced with the values you have provided. Constants, such as #MY_CONSTANT#, are replaced with the constant's value. If the placeholder does not have a corresponding value, as in the variable or constant was not set, the placeholder is left in as-is.


replacedConstant: "#REPLACED#"
replacedVariable: "%replaced%"
unchangedConstant: "#UNCHANGED#"
unchangedVariable: "%unchanged%"



    define('REPLACED', 123);

        'replaced' => 456

    $myData = $wisdom->get('test.yml');

The final result:


    $myData = array(
        'replacedConstant' => '123',
        'replacedVariable' => '456',
        'unchangedConstant' => '#UNCHANGED#',
        'unchangedVariable' => '%unchanged%'

The values are quoted because the # and % characters have special meaning in YAML. However, if you would like to preserve the value's type, you will want to leave it unquoted. The replacement occurs before the any parser is used.

Something went wrong with that request. Please try again.