PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/php/Log/composite.php

https://bitbucket.org/adarshj/convenient_website
PHP | 196 lines | 73 code | 19 blank | 104 comment | 7 complexity | 41847293444d895807d840c5ef570834 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * $Header: /repository/pear/Log/Log/composite.php,v 1.23 2004/08/09 06:04:11 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.23 $
  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 = false, $ident = false, $conf = false,
  43. $level = PEAR_LOG_DEBUG)
  44. {
  45. }
  46. /**
  47. * Opens the child connections.
  48. *
  49. * @access public
  50. */
  51. function open()
  52. {
  53. if (!$this->_opened) {
  54. foreach ($this->_children as $id => $child) {
  55. $this->_children[$id]->open();
  56. }
  57. $this->_opened = true;
  58. }
  59. }
  60. /**
  61. * Closes any child instances.
  62. *
  63. * @access public
  64. */
  65. function close()
  66. {
  67. if ($this->_opened) {
  68. foreach ($this->_children as $id => $child) {
  69. $this->_children[$id]->close();
  70. }
  71. $this->_opened = false;
  72. }
  73. }
  74. /**
  75. * Flushes all open child instances.
  76. *
  77. * @access public
  78. * @since Log 1.8.2
  79. */
  80. function flush()
  81. {
  82. if ($this->_opened) {
  83. foreach ($this->_children as $id => $child) {
  84. $this->_children[$id]->flush();
  85. }
  86. }
  87. }
  88. /**
  89. * Sends $message and $priority to each child of this composite.
  90. *
  91. * @param mixed $message String or object containing the message
  92. * to log.
  93. * @param string $priority (optional) The priority of the message.
  94. * Valid values are: PEAR_LOG_EMERG,
  95. * PEAR_LOG_ALERT, PEAR_LOG_CRIT,
  96. * PEAR_LOG_ERR, PEAR_LOG_WARNING,
  97. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and
  98. * PEAR_LOG_DEBUG.
  99. *
  100. * @return boolean True if the entry is successfully logged.
  101. *
  102. * @access public
  103. */
  104. function log($message, $priority = null)
  105. {
  106. /* If a priority hasn't been specified, use the default value. */
  107. if ($priority === null) {
  108. $priority = $this->_priority;
  109. }
  110. foreach ($this->_children as $id => $child) {
  111. $this->_children[$id]->log($message, $priority);
  112. }
  113. $this->_announce(array('priority' => $priority, 'message' => $message));
  114. return true;
  115. }
  116. /**
  117. * Returns true if this is a composite.
  118. *
  119. * @return boolean True if this is a composite class.
  120. *
  121. * @access public
  122. */
  123. function isComposite()
  124. {
  125. return true;
  126. }
  127. /**
  128. * Sets this identification string for all of this composite's children.
  129. *
  130. * @param string $ident The new identification string.
  131. *
  132. * @access public
  133. * @since Log 1.6.7
  134. */
  135. function setIdent($ident)
  136. {
  137. foreach ($this->_children as $id => $child) {
  138. $this->_children[$id]->setIdent($ident);
  139. }
  140. }
  141. /**
  142. * Adds a Log instance to the list of children.
  143. *
  144. * @param object $child The Log instance to add.
  145. *
  146. * @return boolean True if the Log instance was successfully added.
  147. *
  148. * @access public
  149. */
  150. function addChild(&$child)
  151. {
  152. /* Make sure this is a Log instance. */
  153. if (!is_a($child, 'Log')) {
  154. return false;
  155. }
  156. $this->_children[$child->_id] = &$child;
  157. return true;
  158. }
  159. /**
  160. * Removes a Log instance from the list of children.
  161. *
  162. * @param object $child The Log instance to remove.
  163. *
  164. * @return boolean True if the Log instance was successfully removed.
  165. *
  166. * @access public
  167. */
  168. function removeChild($child)
  169. {
  170. if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) {
  171. return false;
  172. }
  173. unset($this->_children[$child->_id]);
  174. return true;
  175. }
  176. }
  177. ?>