home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / System / ProcWatch / Config / Parser.php
Encoding:
PHP Script  |  2008-07-02  |  5.4 KB  |  270 lines

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PEAR :: System :: ProcWatch :: Config :: Parser                      |
  4. // +----------------------------------------------------------------------+
  5. // | This source file is subject to version 3.0 of the PHP license,       |
  6. // | that is available at http://www.php.net/license/3_0.txt              |
  7. // | If you did not receive a copy of the PHP license and are unable      |
  8. // | to obtain it through the world-wide-web, please send a note to       |
  9. // | license@php.net so we can mail you a copy immediately.               |
  10. // +----------------------------------------------------------------------+
  11. // | Copyright (c) 2003-2004 Michael Wallner <mike@iworks.at>             |
  12. // +----------------------------------------------------------------------+
  13. //
  14. // $Id: Parser.php,v 1.4 2004/06/12 13:40:14 mike Exp $
  15.  
  16. /**
  17. * Requires XML::Parser
  18. */
  19. require_once 'XML/Parser.php';
  20.  
  21. /** 
  22. * System_ProcWatch_Config_Parser
  23. * Parses an XML configuration string into a configuration array.
  24. *
  25. * @author       Michael Wallner <mike@php.net>
  26. * @package      System_ProcWatch
  27. * @category     System
  28. * @version      $Revision: 1.4 $
  29. * @access       protected
  30. */
  31. class System_ProcWatch_Config_Parser extends XML_Parser
  32. {
  33.     /**
  34.     * Parsed Configuration
  35.     *
  36.     * @access   private
  37.     * @var      array
  38.     */
  39.     var $_conf = array();
  40.  
  41.     /**
  42.     * Current Job
  43.     *
  44.     * @access   private
  45.     * @var      reference
  46.     */
  47.     var $_cur = null;
  48.     
  49.     /**
  50.     * Current Job Name
  51.     *
  52.     * @access   private
  53.     * @var      string
  54.     */
  55.     var $_job = '';
  56.     
  57.     /**
  58.     * Current Position
  59.     *
  60.     * @access   private
  61.     * @var      reference
  62.     */
  63.     var $_pos = null;
  64.     
  65.     /**
  66.     * Constructor
  67.     *
  68.     * @access   protected
  69.     * @return   object
  70.     */
  71.     function System_ProcWatch_Config_Parser()
  72.     {
  73.         System_ProcWatch_Config_Parser::__construct();
  74.     }
  75.  
  76.     /**
  77.     * Constructor (ZE2)
  78.     *
  79.     * @access   protected
  80.     * @return   object
  81.     */
  82.     function __construct()
  83.     {
  84.         parent::__construct(null, 'func', null);
  85.     }
  86.  
  87.     /**
  88.     * Reset
  89.     *
  90.     * @access   public
  91.     * @return   void
  92.     */
  93.     function reset()
  94.     {
  95.         $this->_conf    = array();
  96.         $this->_cur     = null;
  97.         $this->_pos     = null;
  98.         
  99.         // call parent::reset()
  100.         parent::reset();
  101.     }
  102.     
  103.     /**
  104.     * Get Configuration from XML data
  105.     *
  106.     * @access   public
  107.     * @return   mixed
  108.     * @param    string  $xml    XML configuration data
  109.     */
  110.     function getConf($xml)
  111.     {
  112.         $this->reset();
  113.  
  114.         $error = $this->parseString($xml);
  115.         if (PEAR::isError($error)) {
  116.             return $error;
  117.         }
  118.         
  119.         return $this->_conf;
  120.     }
  121.     
  122.     /**
  123.     * CDATA handler
  124.     *
  125.     * @access   protected
  126.     * @return   void
  127.     */
  128.     function cdataHandler($p, $d)
  129.     {
  130.         $cdata = trim($d);
  131.         if (!empty($cdata) || $cdata === '0') {
  132.             $this->_pos .= trim($d, "\r\n");
  133.         }
  134.     }
  135.     
  136.     /**
  137.     * Watch
  138.     *
  139.     * @access   protected
  140.     * @return   void
  141.     */
  142.     function xmltag_watch($p, $e, $a)
  143.     {
  144.         $job = $a['NAME'];
  145.         
  146.         $this->_conf[$job] = array(
  147.             'pattern'   => array(),
  148.             'condition' => array(),
  149.             'execute'   => array('shell' => array(), 'php' => array())
  150.         );
  151.  
  152.         $this->_job = $job;
  153.         $this->_cur = &$this->_conf[$job];
  154.     }
  155.     
  156.     /**
  157.     * Pattern
  158.     *
  159.     * @access   protected
  160.     * @return   void
  161.     */
  162.     function xmltag_pattern($p, $e, $a)
  163.     {
  164.         $this->_pos = &$this->_cur['pattern'][$a['MATCH']];
  165.     }
  166.     
  167.     /**
  168.     * Condition
  169.     *
  170.     * @access   protected
  171.     * @return   void
  172.     */
  173.     function xmltag_condition($p, $e, $a)
  174.     {
  175.         $type = strToLower(trim($a['TYPE']));
  176.  
  177.         if ($type == 'presence') {
  178.  
  179.             $this->_cur['condition']['presence'] = array();
  180.             $this->_cur = &$this->_cur['condition']['presence'];
  181.  
  182.         } elseif ($type == 'attr') {
  183.  
  184.             $this->_cur['condition']['attr'] = array();
  185.             $this->_cur = &$this->_cur['condition']['attr'][$a['ATTR']];
  186.  
  187.         }
  188.     }
  189.     
  190.     /**
  191.     * _Condition
  192.     *
  193.     * @access   protected
  194.     * @return   mixed
  195.     */
  196.     function xmltag_condition_($p, $e)
  197.     {
  198.         $this->_cur = &$this->_conf[$this->_job];
  199.     }
  200.     
  201.     /**
  202.     * Execute
  203.     *
  204.     * @access   protected
  205.     * @return   void
  206.     */
  207.     function xmltag_execute($p, $e, $a)
  208.     {
  209.         $count = count($this->_cur['execute'][$a['TYPE']]);
  210.         $this->_pos = &$this->_cur['execute'][$a['TYPE']][$count];
  211.     }
  212.  
  213.     /**
  214.     * Max
  215.     *
  216.     * @access   protected
  217.     * @return   void
  218.     */
  219.     function xmltag_max($p, $e, $a)
  220.     {
  221.         $this->_pos = &$this->_cur['max'];
  222.     }
  223.     
  224.     /**
  225.     * Min
  226.     *
  227.     * @access   protected
  228.     * @return   void
  229.     */
  230.     function xmltag_min($p, $e, $a)
  231.     {
  232.         $this->_pos = &$this->_cur['min'];
  233.     }
  234.     
  235.     /**
  236.     * Sum
  237.     *
  238.     * @access   protected
  239.     * @return   void
  240.     */
  241.     function xmltag_sum($p, $e, $a)
  242.     {
  243.         $this->_pos = &$this->_cur['sum'];
  244.     }
  245.     
  246.     /**
  247.     * Is
  248.     *
  249.     * @access   protected
  250.     * @return   void
  251.     */
  252.     function xmltag_is($p, $e, $a)
  253.     {
  254.         $this->_pos = &$this->_cur['is'];
  255.     }
  256.     
  257.     /**
  258.     * IsNot
  259.     *
  260.     * @access   protected
  261.     * @return   void
  262.     */
  263.     function xmltag_isnot($p, $e, $a)
  264.     {
  265.         $this->_pos = &$this->_cur['isnot'];
  266.     }
  267. }
  268. ?>