PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/Log/composite.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 217 lines | 75 code | 21 blank | 121 comment | 9 complexity | 158becd32ae2d23fbcaef7eabfb4433b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: composite.php 1336 2008-03-31 17:06:23Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage Log
  8. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * $Header$
  20. * $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $
  21. *
  22. * @version $ Revision: 1.26 $
  23. * @package Log
  24. */
  25. /**
  26. * The vmLog_composite:: class implements a Composite pattern which
  27. * allows multiple Log implementations to receive the same events.
  28. *
  29. * @author Chuck Hagenbuch <chuck@horde.org>
  30. * @author Jon Parise <jon@php.net>
  31. *
  32. * @since Horde 1.3
  33. * @since Log 1.0
  34. * @package Log
  35. *
  36. * @example composite.php Using the composite handler.
  37. */
  38. class vmLog_composite extends vmLog
  39. {
  40. /**
  41. * Array holding all of the Log instances to which log events should be
  42. * sent.
  43. *
  44. * @var array
  45. * @access private
  46. */
  47. var $_children = array();
  48. /**
  49. * Constructs a new composite Log object.
  50. *
  51. * @param boolean $name This parameter is ignored.
  52. * @param boolean $ident This parameter is ignored.
  53. * @param boolean $conf This parameter is ignored.
  54. * @param boolean $level This parameter is ignored.
  55. *
  56. * @access public
  57. */
  58. function vmLog_composite($name, $ident = '', $conf = array(),
  59. $level = PEAR_LOG_DEBUG)
  60. {
  61. $this->_ident = $ident;
  62. }
  63. /**
  64. * Opens the child connections.
  65. *
  66. * @access public
  67. */
  68. function open()
  69. {
  70. if (!$this->_opened) {
  71. foreach ($this->_children as $id => $child) {
  72. $this->_children[$id]->open();
  73. }
  74. $this->_opened = true;
  75. }
  76. }
  77. /**
  78. * Closes any child instances.
  79. *
  80. * @access public
  81. */
  82. function close()
  83. {
  84. if ($this->_opened) {
  85. foreach ($this->_children as $id => $child) {
  86. $this->_children[$id]->close();
  87. }
  88. $this->_opened = false;
  89. }
  90. }
  91. /**
  92. * Flushes all open child instances.
  93. *
  94. * @access public
  95. * @since Log 1.8.2
  96. */
  97. function flush()
  98. {
  99. if ($this->_opened) {
  100. foreach ($this->_children as $id => $child) {
  101. $this->_children[$id]->flush();
  102. }
  103. }
  104. }
  105. /**
  106. * Sends $message and $priority to each child of this composite.
  107. *
  108. * @param mixed $message String or object containing the message
  109. * to log.
  110. * @param string $priority (optional) The priority of the message.
  111. * Valid values are: PEAR_LOG_EMERG,
  112. * PEAR_LOG_ALERT, PEAR_LOG_CRIT,
  113. * PEAR_LOG_ERR, PEAR_LOG_WARNING,
  114. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and
  115. * PEAR_LOG_DEBUG.
  116. *
  117. * @return boolean True if the entry is successfully logged.
  118. *
  119. * @access public
  120. */
  121. function log($message, $priority = null)
  122. {
  123. /* If a priority hasn't been specified, use the default value. */
  124. if ($priority === null) {
  125. $priority = $this->_priority;
  126. }
  127. foreach ($this->_children as $id => $child) {
  128. $this->_children[$id]->log($message, $priority);
  129. }
  130. $this->_announce(array('priority' => $priority, 'message' => $message));
  131. return true;
  132. }
  133. /**
  134. * Returns true if this is a composite.
  135. *
  136. * @return boolean True if this is a composite class.
  137. *
  138. * @access public
  139. */
  140. function isComposite()
  141. {
  142. return true;
  143. }
  144. /**
  145. * Sets this identification string for all of this composite's children.
  146. *
  147. * @param string $ident The new identification string.
  148. *
  149. * @access public
  150. * @since Log 1.6.7
  151. */
  152. function setIdent($ident)
  153. {
  154. /* Call our base class's setIdent() method. */
  155. parent::setIdent($ident);
  156. /* ... and then call setIdent() on all of our children. */
  157. foreach ($this->_children as $id => $child) {
  158. $this->_children[$id]->setIdent($ident);
  159. }
  160. }
  161. /**
  162. * Adds a Log instance to the list of children.
  163. *
  164. * @param object $child The Log instance to add.
  165. *
  166. * @return boolean True if the Log instance was successfully added.
  167. *
  168. * @access public
  169. */
  170. function addChild(&$child)
  171. {
  172. /* Make sure this is a Log instance. */
  173. if (!is_a($child, 'vmLog')) { /*@MWM1: Bugfix, was 'Log', changed to 'vmLog' */
  174. return false;
  175. }
  176. $this->_children[$child->_id] = &$child;
  177. return true;
  178. }
  179. /**
  180. * Removes a Log instance from the list of children.
  181. *
  182. * @param object $child The Log instance to remove.
  183. *
  184. * @return boolean True if the Log instance was successfully removed.
  185. *
  186. * @access public
  187. */
  188. function removeChild($child)
  189. {
  190. if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) {
  191. return false;
  192. }
  193. unset($this->_children[$child->_id]);
  194. return true;
  195. }
  196. }