I often find myself needing a configuration module of some sort -- for
storing application parameters, bootstrapping, template variables, what have
you. I typically will either:
- Create a PHP file that creates and returns an array, and suck that in
via include, or
- Create an INI file and suck it in via
parse_ini_file, or
- Create an XML file and suck it in via
SimpleXML.
The first method gives great flexibility of structure and types, but isn't
portable to other languages (well, not easily; you could turn it into JSON,
or serialize it, etc). The second method (INI files) is handy because the
syntax is so concise, and can translate to other projects in other languages
easily if necessary; however, you can only easily go two levels deep (using
[sections] in the file). The third method is very portable, and allows
nested structures -- but doesn't allow usage of many specific PHP types.
I find, however, that each has their place. The problem, however, is: once I
bring them into my project, how can I access them? Better yet, would there
be a way to bring in configurations of many types and still access them all
in the same way?
Not happy with solutions out there, I did the only logical thing: I
reinvented the wheel, and added some new tread of my own.