home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / composite.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  4.7 KB  |  195 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/composite.php,v 1.22 2004/01/19 08:02:40 jon Exp $
  4.  * $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $
  5.  *
  6.  * @version $Revision: 1.22 $
  7.  * @package Log
  8.  */
  9.  
  10. /**
  11.  * The Log_composite:: class implements a Composite pattern which
  12.  * allows multiple Log implementations to receive the same events.
  13.  *
  14.  * @author  Chuck Hagenbuch <chuck@horde.org>
  15.  * @author  Jon Parise <jon@php.net>
  16.  *
  17.  * @since Horde 1.3
  18.  * @since Log 1.0
  19.  * @package Log
  20.  *
  21.  * @example composite.php   Using the composite handler.
  22.  */
  23. class Log_composite extends Log
  24. {
  25.     /**
  26.      * Array holding all of the Log instances to which log events should be
  27.      * sent.
  28.      *
  29.      * @var array
  30.      * @access private
  31.      */
  32.     var $_children = array();
  33.  
  34.  
  35.     /**
  36.      * Constructs a new composite Log object.
  37.      *
  38.      * @param boolean   $name       This parameter is ignored.
  39.      * @param boolean   $ident      This parameter is ignored.
  40.      * @param boolean   $conf       This parameter is ignored.
  41.      * @param boolean   $level      This parameter is ignored.
  42.      *
  43.      * @access public
  44.      */
  45.     function Log_composite($name = false, $ident = false, $conf = false,
  46.                            $level = PEAR_LOG_DEBUG)
  47.     {
  48.     }
  49.  
  50.     /**
  51.      * Opens the child connections.
  52.      *
  53.      * @access public
  54.      */
  55.     function open()
  56.     {
  57.         if (!$this->_opened) {
  58.             foreach ($this->_children as $id => $child) {
  59.                 $this->_children[$id]->open();
  60.             }
  61.         }
  62.     }
  63.  
  64.     /**
  65.      * Closes any child instances.
  66.      *
  67.      * @access public
  68.      */
  69.     function close()
  70.     {
  71.         if ($this->_opened) {
  72.             foreach ($this->_children as $id => $child) {
  73.                 $this->_children[$id]->close();
  74.             }
  75.         }
  76.     }
  77.  
  78.     /**
  79.      * Flushes all open child instances.
  80.      *
  81.      * @access public
  82.      * @since Log 1.8.2
  83.      */
  84.     function flush()
  85.     {
  86.         if ($this->_opened) {
  87.             foreach ($this->_children as $id => $child) {
  88.                 $this->_children[$id]->flush();
  89.             }
  90.         }
  91.     }
  92.  
  93.     /**
  94.      * Sends $message and $priority to each child of this composite.
  95.      *
  96.      * @param mixed     $message    String or object containing the message
  97.      *                              to log.
  98.      * @param string    $priority   (optional) The priority of the message.
  99.      *                              Valid values are: PEAR_LOG_EMERG,
  100.      *                              PEAR_LOG_ALERT, PEAR_LOG_CRIT,
  101.      *                              PEAR_LOG_ERR, PEAR_LOG_WARNING,
  102.      *                              PEAR_LOG_NOTICE, PEAR_LOG_INFO, and
  103.      *                              PEAR_LOG_DEBUG.
  104.      *
  105.      * @return boolean  True if the entry is successfully logged.
  106.      *
  107.      * @access public
  108.      */
  109.     function log($message, $priority = null)
  110.     {
  111.         /* If a priority hasn't been specified, use the default value. */
  112.         if ($priority === null) {
  113.             $priority = $this->_priority;
  114.         }
  115.  
  116.         foreach ($this->_children as $id => $child) {
  117.             $this->_children[$id]->log($message, $priority);
  118.         }
  119.  
  120.         $this->_announce(array('priority' => $priority, 'message' => $message));
  121.  
  122.         return true;
  123.     }
  124.  
  125.     /**
  126.      * Returns true if this is a composite.
  127.      *
  128.      * @return boolean  True if this is a composite class.
  129.      *
  130.      * @access public
  131.      */
  132.     function isComposite()
  133.     {
  134.         return true;
  135.     }
  136.  
  137.     /**
  138.      * Sets this identification string for all of this composite's children.
  139.      *
  140.      * @param string    $ident      The new identification string.
  141.      *
  142.      * @access public
  143.      * @since  Log 1.6.7
  144.      */
  145.     function setIdent($ident)
  146.     {
  147.         foreach ($this->_children as $id => $child) {
  148.             $this->_children[$id]->setIdent($ident);
  149.         }
  150.     }
  151.  
  152.     /**
  153.      * Adds a Log instance to the list of children.
  154.      *
  155.      * @param object    $child      The Log instance to add.
  156.      *
  157.      * @return boolean  True if the Log instance was successfully added.
  158.      *
  159.      * @access public
  160.      */
  161.     function addChild(&$child)
  162.     {
  163.         /* Make sure this is a Log instance. */
  164.         if (!is_a($child, 'Log')) {
  165.             return false;
  166.         }
  167.  
  168.         $this->_children[$child->_id] = &$child;
  169.  
  170.         return true;
  171.     }
  172.  
  173.     /**
  174.      * Removes a Log instance from the list of children.
  175.      *
  176.      * @param object    $child      The Log instance to remove.
  177.      *
  178.      * @return boolean  True if the Log instance was successfully removed.
  179.      *
  180.      * @access public
  181.      */
  182.     function removeChild($child)
  183.     {
  184.         if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) {
  185.             return false;
  186.         }
  187.  
  188.         unset($this->_children[$child->_id]);
  189.  
  190.         return true;
  191.     }
  192. }
  193.  
  194. ?>
  195.