Home arrow PHP arrow Page 7 - Easy Application Configuration With patConfiguration

Speaking Native - PHP

Tired of handcrafting configuration file manipulation tools for your Web application? Save yourself some time with patConfiguration, a PHP class designed to assist developers with reading, writing and maintaining application configuration files.

TABLE OF CONTENTS:
  1. Easy Application Configuration With patConfiguration
  2. Plug And Play
  3. Your Friendly Neighbourhood Spiderman
  4. Anatomy Class
  5. Version Control
  6. The Write Stuff
  7. Speaking Native
  8. Not Your Type
  9. When Time Is Money, Recycle!
  10. Cache Cow
  11. Link Zone
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 1
January 29, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
If XML isn't really your cup of tea, patConfiguration can also create configuration files using traditional PHP as well - this can work better in some cases, since the configuration file only needs to be include()d in your application, not parsed by an XML parser as well. Consider the following example and its output, which demonstrate how this works:


<? // include class require("patConfiguration.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // set config values $conf->setConfigValue("screen.width", 500); $conf->setConfigValue("screen.height", 650); // write file $conf->writeConfigFile("config.php", "php"); ?>


Here's the output:


<?PHP // Configuration generated by patConfiguration $config = array(); $config["screen.height"] = 650; $config["screen.width"] = 500; ?>


As you can see, the variable value pairs defined in the patConfiguration table get converted into a PHP associative array and written to a file. By default, this associative array is named $config - you can change it by providing an alternative name via the "varname" argument to writeConfigFile().


<? // include class require("patConfiguration.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // set config values $conf->setConfigValue("screen.width", 500); $conf->setConfigValue("screen.height", 650); // write file $conf->writeConfigFile("config.php", "php", array("varname" => "appConfig")); ?>


Here's the revised output:


<?PHP // Configuration generated by patConfiguration $appConfig = array(); $appConfig["screen.height"] = 650; $appConfig["screen.width"] = 500; ?>


 
 
>>> More PHP Articles          >>> More By Vikram Vaswani, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: