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 203595 2005-12-24 02:34:39Z aashley $
  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.         $return = true;
  59.         if (!is_readable($datasrc)) {
  60.             return PEAR::raiseError("Datasource file cannot be read."nullPEAR_ERROR_RETURN);
  61.         }
  62.         $lines file($datasrc);
  63.         $n = 0;
  64.         $lastline '';
  65.         $sections[0=$obj->container;
  66.         foreach ($lines as $line{
  67.             $n++;
  68.             if (!preg_match('/^\s*#/'$line&& 
  69.                  preg_match('/^\s*(.*)\s+\\\$/'$line$match)) {
  70.                 // directive on more than one line
  71.                 $lastline .= $match[1].' ';
  72.                 continue;
  73.             }
  74.             if ($lastline != ''{
  75.                 $line $lastline.trim($line);
  76.                 $lastline '';
  77.             }
  78.             if (preg_match('/^\s*#+\s*(.*?)\s*$/'$line$match)) {
  79.                 // a comment
  80.                 $currentSection =$sections[count($sections)-1];
  81.                 $currentSection->createComment($match[1]);
  82.             elseif (trim($line== ''{
  83.                 // a blank line
  84.                 $currentSection =$sections[count($sections)-1];
  85.                 $currentSection->createBlank();
  86.             elseif (preg_match('/^\s*(\w+)(?:\s+(.*?)|)\s*$/'$line$match)) {
  87.                 // a directive
  88.                 $currentSection =$sections[count($sections)-1];
  89.                 $currentSection->createDirective($match[1]$match[2]);
  90.             elseif (preg_match('/^\s*<(\w+)(?:\s+([^>]*)|\s*)>\s*$/'$line$match)) {
  91.                 // a section opening
  92.                 if (!isset($match[2]))
  93.                     $match[2'';
  94.                 $currentSection =$sections[count($sections)-1];
  95.                 $attributes explode(' '$match[2]);
  96.                 $sections[=$currentSection->createSection($match[1]$attributes);
  97.             elseif (preg_match('/^\s*<\/(\w+)\s*>\s*$/'$line$match)) {
  98.                 // a section closing
  99.                 $currentSection =$sections[count($sections)-1];
  100.                 if ($currentSection->name != $match[1]{
  101.                     return PEAR::raiseError("Section not closed in '$datasrc' at line $n."nullPEAR_ERROR_RETURN);
  102.                 }
  103.                 array_pop($sections);
  104.             else {
  105.                 return PEAR::raiseError("Syntax error in '$datasrc' at line $n."nullPEAR_ERROR_RETURN);
  106.             }
  107.         }
  108.         return $return;
  109.     // end func parseDatasrc
  110.  
  111.     /**
  112.     * Returns a formatted string of the object
  113.     * @param    object  $obj    Container object to be output as string
  114.     * @access   public
  115.     * @return   string 
  116.     */
  117.     function toString(&$obj)
  118.     {
  119.         static $deep = -1;
  120.         $ident '';
  121.         if (!$obj->isRoot()) {
  122.             // no indent for root
  123.             $deep++;
  124.             $ident str_repeat('  '$deep);
  125.         }
  126.         if (!isset($string)) {
  127.             $string '';
  128.         }
  129.         switch ($obj->type{
  130.             case 'blank':
  131.                 $string "\n";
  132.                 break;
  133.             case 'comment':
  134.                 $string $ident.'# '.$obj->content."\n";
  135.                 break;
  136.             case 'directive':
  137.                 $string $ident.$obj->name.' '.$obj->content."\n";
  138.                 break;
  139.             case 'section':
  140.                 if (!$obj->isRoot()) {
  141.                     $string $ident.'<'.$obj->name;
  142.                     if (is_array($obj->attributes&& count($obj->attributes> 0{
  143.                         foreach ($obj->attributes as $attr => $val{
  144.                             $string .= ' '.$val;
  145.                         }
  146.                     }
  147.                     $string .= ">\n";
  148.                 }
  149.                 if (count($obj->children> 0{
  150.                     for ($i = 0; $i count($obj->children)$i++{
  151.                         $string .= $this->toString($obj->getChild($i));
  152.                     }
  153.                 }
  154.                 if (!$obj->isRoot()) {
  155.                     // object is not root
  156.                     $string .= $ident.'</'.$obj->name.">\n";
  157.                 }
  158.                 break;
  159.             default:
  160.                 $string '';
  161.         }
  162.         if (!$obj->isRoot()) {
  163.             $deep--;
  164.         }
  165.         return $string;
  166.     // end func toString
  167. // end class Config_Container_Apache
  168. ?>

Documentation generated on Mon, 11 Mar 2019 15:42:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.