Page 1 of 1

Configuration Information

Posted: Thu Sep 15, 2005 9:04 pm
by Ambush Commander
Most information should be stored in a database. However, there is some information that should be stored elsewhere, preferably in PHP files, because they are used so often. These variables include the title of a website, the database credentials (heh) etc.

Currently, I have all of these variables stowed away in local_settings.php, which basically is a bunch of $CF['key'] = 'value'; declarations (the $CF array would then be globalized). However, after learning about a Registry class, I'm wondering how I should port it over.

I've thought up of several solutions:

1. Make an inject() method on the Registry class, set up the array as normal and then "inject it in"
2. Extend the object with the default values changed to the person's config
3. Use the object's interface to set the variables

However, I also need to be able to automatically generate the file later, and also have it not to unfriendly for people who want to configure it. #1 would certainly be easy to generate, and perhaps 2 and 3 wouldn't be too bad. 3 might present a performance impact as we're calling lots of functions. 2... well 2 is just plain weird: it won't work for some cases.

What would you do? Remember, this is software that wants to be packaged and then distributed.

On a related note, should you version your program's configuration files?

Posted: Thu Sep 15, 2005 9:17 pm
by feyd
we use an ini file to store such data.. the startup class finds it, loads it if present setting application level properties where approriate..

Posted: Thu Sep 15, 2005 9:21 pm
by Ambush Commander
But wouldn't parsing an ini file be slower?

Posted: Thu Sep 15, 2005 9:25 pm
by feyd
parse_ini_file() is quite fast, it is, an' very human readable. :)


yar

Posted: Thu Sep 15, 2005 9:28 pm
by Ambush Commander
Hmm... how do you go about protecting the ini file then (without htaccess trickery) (and placing it above webserver root)?

Posted: Thu Sep 15, 2005 9:54 pm
by feyd
Our entire framework sits outside the webroot, leaving only the xml files that drive the applicaiton level pages "visible" .. however our ini contains no sensitive data.. things such as database connector information is stored with the database drivers in ini like files..

Posted: Fri Sep 16, 2005 9:32 pm
by Ambush Commander
Hmm... that's not very useful for me then. Any other suggestions? Theorization?