PHP
  Home arrow PHP arrow Page 4 - Easy Application Configuration With patConfiguration
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Easy Application Configuration With patConfiguration
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2003-01-29


    Table of Contents:
  • Easy Application Configuration With patConfiguration
  • Plug And Play
  • Your Friendly Neighbourhood Spiderman
  • Anatomy Class
  • Version Control
  • The Write Stuff
  • Speaking Native
  • Not Your Type
  • When Time Is Money, Recycle!
  • Cache Cow
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Easy Application Configuration With patConfiguration - Anatomy Class
    ( Page 4 of 11 )

    Next, it's time to use the patConfiguration engine to read and use the values in the configuration file. Here's how:


    <? // include class require("patConfiguration.php"); // create patConfiguration object $conf = new patConfiguration; // set config file locations $conf->setConfigDir("config"); // read config file $conf->parseConfigFile("config.xml"); // print configuration print_r($conf->getConfigValue()); ?>


    Here's the output:


    Array ( [application.name] => SomeApp [application.version] => 2.3 [application.window.height] => 600 [application.window.width] => 500 [application.window.list.maxItems] => 5 )


    Let's dissect this a little to see how it works.

    1. The first step is, obviously, to include all the relevant files for the class to work.


    // include class require("patConfiguration.php");


    Once that's done, I can safely create an object of the patConfiguration class.


    // create patConfiguration object $conf = new patConfiguration;


    This object instance will serve as the primary access point to the data in the application configuration file(s), allowing me to do all kinds of nifty things with it.

    2. Next, the object's setConfigDir() method is used to set the default location of the configuration files,


    // set config file locations $conf->setConfigDir("config");


    and the parseConfigFile() method is used to actually read each file into the object's internal stack.


    // read config file $conf->parseConfigFile("config.xml");


    You can parse multiple configuration files by calling parseConfigFile() for each file, and telling patConfiguration to append (instead of overwriting) each set of configuration variables to the existing stack via the additional "a" option - as in the following code snippet:


    // read config files $conf->parseConfigFile("config.main.xml"); $conf->parseConfigFile("config.local.xml", "a"); $conf->parseConfigFile("config.users.xml", "a");


    4. Finally, all that's left is to actually use the configuration data - in this case, print it all to the standard output device.


    // print configuration print_r($conf->getConfigValue());


    The getConfigValue() method gets the value of a specified configuration variable from the configuration file(s). If no variable name is specified, the entire set of values is returned...as in the example above.

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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT