--- nfo/php/libs/net.php.pear/Log/composite.php 2002/10/25 15:15:23 1.1 +++ nfo/php/libs/net.php.pear/Log/composite.php 2003/02/05 21:48:31 1.2 @@ -1,129 +1,137 @@ - - * @version $Revision: 1.1 $ - * @since Horde 1.3 -*/ -class Log_composite { - - // {{{ properties - - /** Array holding all Log instances which should be sent events - sent to the composite. */ - var $children = array(); - - // }}} - - - // {{{ constructor - /** - * Constructs a new composite Log object. - * - * @param $log_name (optional) This is ignored. - * @param $ident (optional) This is ignored. - * @param $conf (optional) This is ignored. - */ - function Log_composite ($log_name = false, $ident = false, $conf = false) { - } - // }}} - - - // {{{ open() - /** - * Open the log connections of each and every child of this - * composite. - */ - function open () { - if (!$this->opened) { - reset($this->children); - foreach ($this->children as $child) { - $child->open(); - } - } - } - // }}} - - // {{{ close() - /** - * If we've gone ahead and opened each child, go through and close - * each child. - */ - function close () { - if ($this->opened) { - reset($this->children); - foreach ($this->children as $child) { - $child->close(); - } - } - } - // }}} - - // {{{ log() - /** - * Sends $message and $priority to every child of this composite. - * - * @param $message The textual message to be logged. - * @param $priority (optional) The priority of the message. Valid - * values are: LOG_EMERG, LOG_ALERT, LOG_CRIT, - * LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, - * and LOG_DEBUG. The default is LOG_INFO. - */ - function log ($message, $priority = LOG_INFO) { - reset($this->children); - foreach ($this->children as $child) { - $child->log($message, $priority); - } - - $this->notifyAll(array('priority' => $priority, 'message' => $message)); - } - // }}} - - // {{{ isComposite() - /** - * @return a Boolean: true if this is a composite class, false - * otherwise. Always returns true since this is the composite - * subclass. - */ - function isComposite () { - return true; - } - // }}} - - // {{{ addChild() - /** - * Add a Log instance to the list of children that messages sent - * to us should be passed on to. - * - * @param $child The Log instance to add. - */ - function addChild (&$child) { - if (!is_object($child)) - return false; - - $child->_childID = uniqid(rand()); - - $this->children[$child->_listenerID] = &$child; - } - // }}} - - // {{{ removeChild() - /** - * Remove a Log instance from the list of children that messages - * sent to us should be passed on to. - * - * @param $child The Log instance to remove. - */ - function removeChild ($child) { - if (isset($this->children[$child->_childID])) - unset($this->children[$child->_childID]); - } - // }}} - -} - -?> + + * @version $Revision: 1.2 $ + * @since Horde 1.3 + * @package Log + */ + +class Log_composite extends Log { + + /** + * Array holding all Log instances + * which should be sent events sent to the composite. + * @var array + */ + var $_children = array(); + + + /** + * Constructs a new composite Log object. + * + * @param boolean $name This is ignored. + * @param boolean $ident This is ignored. + * @param boolean $conf This is ignored. + * @param boolean $maxLevel This is ignored. + * @access public + */ + function Log_composite($name = false, $ident = false, $conf = false, + $maxLevel = PEAR_LOG_DEBUG) + { + } + + /** + * Open the log connections of each and every child of this + * composite. + * @access public + */ + function open() + { + if (!$this->_opened) { + reset($this->_children); + foreach ($this->_children as $child) { + $child->open(); + } + } + } + + /** + * If we've gone ahead and opened each child, go through and close + * each child. + * @access public + */ + function close() + { + if ($this->_opened) { + reset($this->_children); + foreach ($this->_children as $child) { + $child->close(); + } + } + } + + /** + * Sends $message and $priority to every child of this composite. + * + * @param string $message The textual message to be logged. + * @param string $priority (optional) The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * The default is PEAR_LOG_INFO. + * @return boolean True on success or false on failure. + */ + function log($message, $priority = PEAR_LOG_INFO) + { + reset($this->_children); + foreach ($this->_children as $child) { + $child->log($message, $priority); + } + + $this->notifyAll(array('priority' => $priority, 'message' => $message)); + + return true; + } + + /** + * @return boolean true if this is a composite class, false + * otherwise. Always returns true since this is the composite + * subclass. + * @access public + */ + function isComposite() + { + return true; + } + + /** + * Add a Log instance to the list of children that messages sent + * to us should be passed on to. + * + * @param object Log &$child The Log instance to add. + * @access public + * @return boolean false, if &$child isn't a Log instance + */ + function addChild(&$child) + { + if (!is_object($child)) { + return false; + } + + $child->_childID = uniqid(rand()); + + $this->_children[$child->_childID] = &$child; + } + + /** + * Remove a Log instance from the list of children that messages + * sent to us should be passed on to. + * + * @param object Log $child The Log instance to remove. + * @access public + */ + function removeChild($child) + { + if (isset($this->_children[$child->_childID])) { + unset($this->_children[$child->_childID]); + } + } +} + +?>