HTTPS clone URL
Subversion checkout URL
Clone this wiki locally
- New Instance
- Optional Configuration
For Silex configuration, please see the service provider.
To configure Wisdom, you must first create an instance.
<?php $wisdom = new Wisdom ('/path/to/config/files/directory');
Note that you may also pass an array of directory paths, instead.
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
<?php $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
ArrayLoaderclass offered by Symfony's Config component. You may create your own loader by extending the
KevinGH\Wisdom\Loader\Loaderabstract class. Because the abstract class implements
Symfony\Component\Config\Loader\LoaderInterface, you will still need to create your own
Your Wisdom configuration manager instance is now ready to be used.
<?php $iniData = $wisdom->get('test.ini'); $jsonData = $wisdom->get('test.json'); $yamlData = $wisdom->get('test.yml');
Caching is only performed when a cache directory path has been set. To set a cache directory path, you will need to call
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.
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
<?php $wisdom->setPrefix('dev.'); $wisdom->get('sub/test.yml');
get()method will first try to load
sub/dev.test.yml, then fallback to
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%"
<?php define('REPLACED', 123); $wisdom->setValues(array( 'replaced' => 456 )); $myData = $wisdom->get('test.yml');
The final result:
<?php $myData = array( 'replacedConstant' => '123', 'replacedVariable' => '456', 'unchangedConstant' => '#UNCHANGED#', 'unchangedVariable' => '%unchanged%' );
The values are quoted because the
%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.