Source for file Ini.class.php

Documentation is available at Ini.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Config
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Config INI Reader
  22.  * 
  23.  * This class will read an INI file using the parse_ini_file function.  It will
  24.  * automatically separate sections.  A standard INI file format:
  25.  * 
  26.  * <pre>
  27.  * ; for Comments
  28.  * [section]
  29.  * name = value
  30.  * name = value
  31.  * ...
  32.  * </pre>
  33.  *
  34.  * @category Gumbo
  35.  * @package Config
  36.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  37.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  38.  * @author Michael Luster <mluster79@yahoo.com>
  39.  * @link http://sourceforge.net/projects/phpgumbo
  40.  * @desc Config INI Reader
  41.  * @version 0.0.1
  42.  */
  43.  
  44. gumbo_load ("Interface_Config_Reader");
  45.  
  46. class Gumbo_Config_Reader_Ini implements Gumbo_Interface_Config_Reader {
  47.     
  48.     /** ACTION METHODS **/
  49.     /**
  50.      * Reads the given configuration into memory, and returns the results
  51.      * @param string $file 
  52.      * @return Gumbo_Interface_Composite 
  53.      * @throws Gumbo_Exception
  54.      * @uses Gumbo_Converter, Gumbo_Branch
  55.      */
  56.     public function read ($file{
  57.         
  58.         gumbo_load ("Interface_Composite");
  59.         gumbo_load ("Branch");
  60.         gumbo_load ("Converter");
  61.         
  62.         try {
  63.             // verify precondition
  64.             if (!is_string ($file)) {
  65.                 throw new Gumbo_Exception ("Invalid Argument 'file:str' => {$file}:gettype ($file));
  66.             }
  67.             if (!file_exists ($file)) {
  68.                 throw new Gumbo_Exception ("File Not Found: {$file}");
  69.             }
  70.             
  71.             $obj new Gumbo_Converter ();
  72.             if (($res $obj->factory ("array")->convert (parse_ini_file ($filetrue)"composite")) instanceof Gumbo_Interface_Composite{
  73.                 return $res;
  74.             }
  75.         catch (Gumbo_Exception $e{
  76.             $e->setFunction (__METHOD__);
  77.             gumbo_trigger ($e);
  78.         }
  79.         return new Gumbo_Branch ();
  80.     }
  81.     
  82. }
  83.  
  84. ?>