Configuration Information

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Configuration Information

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

But wouldn't parsing an ini file be slower?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

parse_ini_file() is quite fast, it is, an' very human readable. :)


yar
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Hmm... how do you go about protecting the ini file then (without htaccess trickery) (and placing it above webserver root)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Hmm... that's not very useful for me then. Any other suggestions? Theorization?
Post Reply