Websublime\Config
, (*1)
Syntax
Config component is a package based on Symfony Config where it is used as a catalogue of configurations. It can be inserted or just loading from two types of files: yml and php. We do not have made more supported files because it is this kind of files that we most use., (*2)
How To Use
First create an instance of which type of loader for the file you want to use., (*3)
$yaml = new YamlConfigLoader('/path/where/config/will/be');
Then create an instance of Config and set the loader resolver., (*4)
$config = new Config();
$config->setConfigResolver($yaml);
After, you have to import your configuration file., (*5)
$config->import('myconfig.yml');
The import method is void. The configuration is added to ConfigCatalogue were you can interact in Config. Lets say your config fil have:, (*6)
config:
key: 'My new option'
When you import your configuration file it is registered in ConfigCatalogue with the name of your file without extension and if it is an array multidimensional it will be transformer in a flatten array. So to get our value from our config we call:, (*7)
$config->get('myconfig.config.key');
The methods present in ConfigCatalogue are:, (*8)
ConfigCatalogue->get($key);
ConfigCatalogue->add($value, $key=null);
ConfigCatalogue->remove($key);
ConfigCatalogue->exist($key);
ConfigCatalogue->all();
Of course it isn't mandatory to use a file of configurations. You can use it without one. Just instantiate the Config and you are rock and load to use the ConfigueCatalogue methods., (*9)
Changelog
- Added version 0.2
- Added support for loading php files for configs
- Added methods getDelegateLoader() and getLoaderResolver() on ConfigResolver.