Dot ini files parser class with extended section support
by itrascastro
When I developed xenframework I had to create a component to enable developers to store configuration data in a familiar INI format and read them in the application by using nested object property syntax. The INI format is specialized to provide both the ability to have a hierarchy of configuration data keys and inheritance between configuration data sections. Configuration data hierarchies are supported by separating the keys with the dot or period character (“.”). A section may extend or inherit from another section by following the section name with a colon character (“:”) and the name of the section from which data are to be inherited.
Example of use
This example illustrates a basic use of the Ini component combined with the Config component for loading configuration data from an INI file. In this example there are configuration data for both a production system and for a development system. Because the development system configuration data are very similar to those for production, the development section inherits from the production section. In this case, the decision is arbitrary and could have been written conversely, with the production section inheriting from the development section, though this may not be the case for more complex situations. Suppose, then, that the following configuration data are contained in /path/to/config.ini:
Next, assume that the application developer needs the development configuration data from the INI file. It is a simple matter to load these data by specifying the INI file and the development section:
The Ini class
Now we are going to see the code of the Ini class which is well documented:
where the Config class creates the object representation of the section array: