XML is often used by humans to store information that can easily be parsed by computer programs, like for instance application configuration options.
However, XML parsing is often a process that consumes too much CPU and memory when parsing many documents or the same document many times.
This class provides a solution to override the overhead of repeatedly parsing XML configuration files. It creates a PHP class file with variables set to the configuration values retrieved from the XML file.
This way the XML file does not have to be parsed in all requests on which its information is needed. The speedup can be further optimized by using a PHP caching engine extension, as the generated PHP class does not need to be parsed and compiled again.
Auto-generates a set of php configuration classes from a supplied xml file.
This class can be used to generate a PHP class from an XML file. The element (tag) names become property names and the text contained in the elements becomes the property's value. It also supports nested elements.
If the generated php file is older than the xml file, it is re-generated using the data in the newer xml file.
For example, this xml file:
<config>
<database>
<connString>This is my connection string</connString>
</database>
</config>
Would be accessed in php as follows (after the ConfigurationLoader.update method had been called:
$config = new config();
echo $config->database->connString;
This class also supports array types using the <item> element inside an element whose type attribute is set to "array". Please read the documentation and see example xml files for more details.
Once you have your configuration classes you can get or set the values as required.