Next, it's time to use the patConfiguration engine to read and use the values in the configuration file. Here's how:
Here's the output:
Let's dissect this a little to see how it works. 1. The first step is, obviously, to include all the relevant files for the class to work.
Once that's done, I can safely create an object of the patConfiguration class.
This object instance will serve as the primary access point to the data in the application configuration file(s), allowing me to do all kinds of nifty things with it. 2. Next, the object's setConfigDir() method is used to set the default location of the configuration files,
and the parseConfigFile() method is used to actually read each file into the object's internal stack.
You can parse multiple configuration files by calling parseConfigFile() for each file, and telling patConfiguration to append (instead of overwriting) each set of configuration variables to the existing stack via the additional "a" option - as in the following code snippet:
4. Finally, all that's left is to actually use the configuration data - in this case, print it all to the standard output device.
The getConfigValue() method gets the value of a specified configuration variable from the configuration file(s). If no variable name is specified, the entire set of values is returned...as in the example above.
blog comments powered by Disqus |