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

Not Your Type - 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
You'll remember, from a couple pages back, that patConfiguration supports a number of different data types for its configuration variables. This variable type can be set via the setConfigValue() method, and currently can be any one of "string", "integer", "boolean", "array" and "float".

Here's an example which demonstrates how strings, integers and Booleans work:


<? // 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, "integer"); $conf->setConfigValue("font.face", "Verdana", "string"); $conf->setConfigValue("window.toolbar.visibility", true, "boolean"); // write file $conf->writeConfigFile("config.xml", "xml", array("mode" => "pretty")); ?>


Here's the XML output:


<?xml version="1.0" encoding="ISO-8859-1"?> <configuration> <path name="font"> <configValue name="face" type="string">Verdana</configValue> </path> <path name="screen"> <configValue name="width" type="int">500</configValue> </path> <path name="window"> <path name="toolbar"> <configValue name="visibility" type="bool">true</configValue> </path> </path> </configuration>


Wanna use arrays in your configuration? patConfiguration supports those as well:


<? // include class require("patConfiguration.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // set config values $conf->setConfigValue("friends", array("Rachel", "Ross", "Monica", "Joey", "Chandler", "Phoebe"), "array"); // write file $conf->writeConfigFile("config.xml", "xml", array("mode" => "pretty")); ?>


Here's the XML output,


<?xml version="1.0" encoding="ISO-8859-1"?> <configuration> <configValue name="friends" type="array"> <configValue type="string">Rachel</configValue> <configValue type="string">Ross</configValue> <configValue type="string">Monica</configValue> <configValue type="string">Joey</configValue> <configValue type="string">Chandler</configValue> <configValue type="string">Phoebe</configValue> </configValue> </configuration>


and here's the PHP output:


<?PHP // Configuration generated by patConfiguration $config = array(); $config["friends"] = array(); $config["friends"][0] = "Rachel"; $config["friends"][1] = "Ross"; $config["friends"][2] = "Monica"; $config["friends"][3] = "Joey"; $config["friends"][4] = "Chandler"; $config["friends"][5] = "Phoebe"; ?>


 
 
>>> 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: