Recommend this page to a friend! |
Classes of philippe thomassigny | xconfig | README.md | Download |
|
DownloadXConfigVersion 2.0.2 The XConfig library is used to easily build a config object based on a descriptor file. Change Historyv2.0.2: - Error corrected on static NEWLINE string v2.0.1: - Some errors corrected in Iterator (was stopped if there was a false value in the parameter) - constructor and merge method enhanced v2.0.0: - Now compatible with PHP7 - Now uses namespace xconfig v1.1.0: - Compiler now accept ';' as comment - Better compiler, respect '=' after first occurence as value - Compiler now converts 'true', 'yes', 'on' to true and 'false', 'no', 'off', 'none' to false v1.0.2: - Default values added - __print function made to print better the variables - manual more complete v1.0.1: - Original release User guideThe configuration file have the following syntax for example:
As version 1.1, xconfig now accept true, on, yes as a boolean 'true' and false, off, no, none as a boolean 'false'. For instance, that means parameter=off is now a boolean false, and parameter=yes is now a boolean true. Before verion 1.0, note the config file is always read as a STRING. That means parameter=0, parameter=false, parameter=123 will be caught as "0", "false", "123", not integers or booleans This will be converted into the XConfig object. The XConfig object is easily usable as:
or
Concrete Example 1:
Concrete Example 2:
Once you have an instance of your configuration, you may use it like this:
Advanced topicDefault values:You may pass an array of default values to the constructor so if the parameter is not present into the config file, it will take the default value. Note: default values will be taken only if the parameter DOES NOT EXIST into the config file. This means an empty value is considerated as a value Something like this: parameter1= will not fire the default value because the parameter is present into the config file You may encapsulate the config object into a specific personal object with a local default set of parameters. Example:class myConfig extends XConfig { private $default = array(
); public function __construct($data) {
} } Merging:You may merge two config file (or more), for example when you have a master config file and a local replacement values config file:
with files:
The result config after merging local into global will be:
|