Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 lines
5.0 KiB

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