LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP file for configuring my application (https://www.linuxquestions.org/questions/programming-9/php-file-for-configuring-my-application-472408/)

firemankurt 08-09-2006 03:54 PM

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?

silent_cutthroat 08-09-2006 04:19 PM

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.

firemankurt 08-09-2006 09:03 PM

What do you mean by "small abstraction layer"?

firemankurt 08-10-2006 12:42 AM

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.

silent_cutthroat 08-10-2006 03:21 AM

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');
echo $someConfig->attr0;
$someConfig->attr1 = 'blahblahblah';
$someConfig->update();

Or if you don't use php5:

Code:

$anotherConfig = new SQLConfig($sqllink);
echo $anotherConfig->getAttr('attr0');
$anotherConfig->setAttr('attr1', 'asdf');
$anotherConfig->update();



All times are GMT -5. The time now is 01:07 PM.