PHP file for configuring my application
I am working on several projects and I am distributing them on sourceforge.
I have a couple PHP files that hold settings for dropdown menus, user privleges, MySQL server settings and lots of other stuff. The settings are like: $UseType['A']['Description'] = "Administrator"; $UseType['A']['Access'] = "All"; $UseType['B']['Description'] = "List Manager"; $UseType['B']['Access'] = "0,1,2"; I want to come up with a way to allow other people to customize these settings without having to edit a PHP file. What have other people done to acheive this? If I had a plain text file like: UseType A { Description = Administrator Access = All } UseType B { Description = List Manager Access = 0 1 2 } How would I parse that into constants or variables for my scripts? |
You may use xml for configuration and parse it with the builtin facilities. If you don't want to write xml maybe the easiest way is to define a simple syntax and parse it with regular expressions. Also you can make small abstraction layer all over this and use different ways to store the configuration (simultaneously?), maybe even sql.
|
What do you mean by "small abstraction layer"?
|
I am interested in some examples if anyone has anything that they have done.
I started a script that edits the PHP file through an administration form but I hate to reinvent the wheel. There must be a standard way to do this. |
PHP5 offers some interesting features like overloading and the ArrayAccess interface. You can abstract your configuraton with them so everything looks like regular objects or arrays.
Code:
$someConfig = new XMLConfig('sample.conf'); Code:
$anotherConfig = new SQLConfig($sqllink); |
All times are GMT -5. The time now is 01:07 PM. |