Config
[ class tree: Config ] [ index: Config ] [ all elements ]

Source for file Apache.php

Documentation is available at Apache.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2003 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 2.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/2_02.txt.                                 |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Author: Bertrand Mansion <bmansion@mamasam.com>                      |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: Apache.php,v 1.9 2003/04/02 11:50:52 mansion Exp $
  19.  
  20. /**
  21. * Simple config parser for apache httpd.conf files
  22. * A more complex version could handle directives as
  23. * associative arrays.
  24. *
  25. @author      Bertrand Mansion <bmansion@mamasam.com>
  26. @package     Config
  27. */
  28.  
  29.     /**
  30.     * This class options
  31.     * Not used at the moment
  32.     *
  33.     * @var  array 
  34.     */
  35.     var $options = array();
  36.  
  37.     /**
  38.     * Constructor
  39.     *
  40.     * @access public
  41.     * @param    string  $options    (optional)Options to be used by renderer
  42.     */
  43.     function Config_Container_Apache($options = array())
  44.     {
  45.         $this->options = $options;
  46.     // end constructor
  47.  
  48.     /**
  49.     * Parses the data of the given configuration file
  50.     *
  51.     * @access public
  52.     * @param string $datasrc    path to the configuration file
  53.     * @param object $obj        reference to a config object
  54.     * @return mixed returns a PEAR_ERROR, if error occurs or true if ok
  55.     */
  56.     function &parseDatasrc($datasrc&$obj)
  57.     {
  58.         if (!is_readable($datasrc)) {
  59.             return PEAR::raiseError("Datasource file cannot be read."nullPEAR_ERROR_RETURN);
  60.         }
  61.         $lines file($datasrc);
  62.         $n = 0;
  63.         $lastline '';
  64.         $sections[0=$obj->container;
  65.         foreach ($lines as $line{
  66.             $n++;
  67.             if (!preg_match('/^\s*#/'$line&& 
  68.                  preg_match('/^\s*(.*)\s+\\\$/'$line$match)) {
  69.                 // directive on more than one line
  70.                 $lastline .= $match[1].' ';
  71.                 continue;
  72.             }
  73.             if ($lastline != ''{
  74.                 $line $lastline.trim($line);
  75.                 $lastline '';
  76.             }
  77.             if (preg_match('/^\s*#+\s*(.*?)\s*$/'$line$match)) {
  78.                 // a comment
  79.                 $currentSection =$sections[count($sections)-1];
  80.                 $currentSection->createComment($match[1]);
  81.             elseif (trim($line== ''{
  82.                 // a blank line
  83.                 $currentSection =$sections[count($sections)-1];
  84.                 $currentSection->createBlank();
  85.             elseif (preg_match('/^\s*(\w+)(?:\s+(.*?)|)\s*$/'$line$match)) {
  86.                 // a directive
  87.                 $currentSection =$sections[count($sections)-1];
  88.                 $currentSection->createDirective($match[1]$match[2]);
  89.             elseif (preg_match('/^\s*<(\w+)(?:\s+([^>]*)|\s*)>\s*$/'$line$match)) {
  90.                 // a section opening
  91.                 if (!isset($match[2]))
  92.                     $match[2'';
  93.                 $currentSection =$sections[count($sections)-1];
  94.                 $attributes explode(' '$match[2]);
  95.                 $sections[=$currentSection->createSection($match[1]$attributes);
  96.             elseif (preg_match('/^\s*<\/(\w+)\s*>\s*$/'$line$match)) {
  97.                 // a section closing
  98.                 $currentSection =$sections[count($sections)-1];
  99.                 if ($currentSection->name != $match[1]{
  100.                     return PEAR::raiseError("Section not closed in '$datasrc' at line $n."nullPEAR_ERROR_RETURN);
  101.                 }
  102.                 array_pop($sections);
  103.             else {
  104.                 return PEAR::raiseError("Syntax error in '$datasrc' at line $n."nullPEAR_ERROR_RETURN);
  105.             }
  106.         }
  107.         return true;
  108.     // end func parseDatasrc
  109.  
  110.     /**
  111.     * Returns a formatted string of the object
  112.     * @param    object  $obj    Container object to be output as string
  113.     * @access   public
  114.     * @return   string 
  115.     */
  116.     function toString(&$obj)
  117.     {
  118.         static $deep = -1;
  119.         $ident '';
  120.         if (!$obj->isRoot()) {
  121.             // no indent for root
  122.             $deep++;
  123.             $ident str_repeat('  '$deep);
  124.         }
  125.         if (!isset($string)) {
  126.             $string '';
  127.         }
  128.         switch ($obj->type{
  129.             case 'blank':
  130.                 $string "\n";
  131.                 break;
  132.             case 'comment':
  133.                 $string $ident.'# '.$obj->content."\n";
  134.                 break;
  135.             case 'directive':
  136.                 $string $ident.$obj->name.' '.$obj->content."\n";
  137.                 break;
  138.             case 'section':
  139.                 if (!$obj->isRoot()) {
  140.                     $string $ident.'<'.$obj->name;
  141.                     if (is_array($obj->attributes&& count($obj->attributes> 0{
  142.                         while (list(,$valeach($obj->attributes)) {
  143.                             $string .= ' '.$val;
  144.                         }
  145.                     }
  146.                     $string .= ">\n";
  147.                 }
  148.                 if (count($obj->children> 0{
  149.                     for ($i = 0; $i count($obj->children)$i++{
  150.                         $string .= $this->toString($obj->getChild($i));
  151.                     }
  152.                 }
  153.                 if (!$obj->isRoot()) {
  154.                     // object is not root
  155.                     $string .= $ident.'</'.$obj->name.">\n";
  156.                 }
  157.                 break;
  158.             default:
  159.                 $string '';
  160.         }
  161.         if (!$obj->isRoot()) {
  162.             $deep--;
  163.         }
  164.         return $string;
  165.     // end func toString
  166. // end class Config_Container_Apache
  167. ?>

Documentation generated on Mon, 11 Mar 2019 13:51:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.