/library/Zend/Wildfire/Plugin/FirePhp/Message.php

https://bitbucket.org/Ebozavrik/test-application · PHP · 256 lines · 84 code · 27 blank · 145 comment · 2 complexity · d3c6a1e2debae41ccd13fdf16bd20292 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Wildfire
  17. * @subpackage Plugin
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Message.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /**
  23. * A message envelope that can be passed to Zend_Wildfire_Plugin_FirePhp to be
  24. * logged to Firebug instead of a variable.
  25. *
  26. * @category Zend
  27. * @package Zend_Wildfire
  28. * @subpackage Plugin
  29. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Wildfire_Plugin_FirePhp_Message
  33. {
  34. /**
  35. * The style of the message
  36. * @var string
  37. */
  38. protected $_style = null;
  39. /**
  40. * The label of the message
  41. * @var string
  42. */
  43. protected $_label = null;
  44. /**
  45. * The message value
  46. * @var mixed
  47. */
  48. protected $_message = null;
  49. /**
  50. * Flag indicating if message buffering is enabled
  51. * @var boolean
  52. */
  53. protected $_buffered = false;
  54. /**
  55. * Flag indicating if message should be destroyed and not delivered
  56. * @var boolean
  57. */
  58. protected $_destroy = false;
  59. /**
  60. * Random unique ID used to identify message in comparison operations
  61. * @var string
  62. */
  63. protected $_ruid = false;
  64. /**
  65. * Options for the object
  66. * @var array
  67. */
  68. protected $_options = array(
  69. 'traceOffset' => null, /* The offset in the trace which identifies the source of the message */
  70. 'includeLineNumbers' => null /* Whether to include line and file info for this message */
  71. );
  72. /**
  73. * Creates a new message with the given style and message
  74. *
  75. * @param string $style Style of the message.
  76. * @param mixed $message The message
  77. *
  78. * @return void
  79. */
  80. function __construct ($style, $message)
  81. {
  82. $this->_style = $style;
  83. $this->_message = $message;
  84. $this->_ruid = md5(microtime() . mt_rand());
  85. }
  86. /**
  87. * Set the label of the message
  88. *
  89. * @param string $label The label to be set
  90. *
  91. * @return void
  92. */
  93. public function setLabel ($label)
  94. {
  95. $this->_label = $label;
  96. }
  97. /**
  98. * Get the label of the message
  99. *
  100. * @return string The label of the message
  101. */
  102. public function getLabel ()
  103. {
  104. return $this->_label;
  105. }
  106. /**
  107. * Enable or disable message buffering
  108. *
  109. * If a message is buffered it can be updated for the duration of the
  110. * request and is only flushed at the end of the request.
  111. *
  112. * @param boolean $buffered TRUE to enable buffering FALSE otherwise
  113. *
  114. * @return boolean Returns previous buffering value
  115. */
  116. public function setBuffered ($buffered)
  117. {
  118. $previous = $this->_buffered;
  119. $this->_buffered = $buffered;
  120. return $previous;
  121. }
  122. /**
  123. * Determine if buffering is enabled or disabled
  124. *
  125. * @return boolean Returns TRUE if buffering is enabled, FALSE otherwise.
  126. */
  127. public function getBuffered ()
  128. {
  129. return $this->_buffered;
  130. }
  131. /**
  132. * Destroy the message to prevent delivery
  133. *
  134. * @param boolean $destroy TRUE to destroy FALSE otherwise
  135. *
  136. * @return boolean Returns previous destroy value
  137. */
  138. public function setDestroy ($destroy)
  139. {
  140. $previous = $this->_destroy;
  141. $this->_destroy = $destroy;
  142. return $previous;
  143. }
  144. /**
  145. * Determine if message should be destroyed
  146. *
  147. * @return boolean Returns TRUE if message should be destroyed, FALSE otherwise.
  148. */
  149. public function getDestroy ()
  150. {
  151. return $this->_destroy;
  152. }
  153. /**
  154. * Set the style of the message
  155. *
  156. * @return void
  157. */
  158. public function setStyle ($style)
  159. {
  160. $this->_style = $style;
  161. }
  162. /**
  163. * Get the style of the message
  164. *
  165. * @return string The style of the message
  166. */
  167. public function getStyle ()
  168. {
  169. return $this->_style;
  170. }
  171. /**
  172. * Set the actual message to be sent in its final format.
  173. *
  174. * @return void
  175. */
  176. public function setMessage ($message)
  177. {
  178. $this->_message = $message;
  179. }
  180. /**
  181. * Get the actual message to be sent in its final format.
  182. *
  183. * @return mixed Returns the message to be sent.
  184. */
  185. public function getMessage ()
  186. {
  187. return $this->_message;
  188. }
  189. /**
  190. * Set a single option
  191. *
  192. * @param string $key The name of the option
  193. * @param mixed $value The value of the option
  194. *
  195. * @return mixed The previous value of the option
  196. */
  197. public function setOption ($key, $value)
  198. {
  199. if (!array_key_exists($key, $this->_options)) {
  200. throw new Zend_Wildfire_Exception( 'Option with name "' . $key . '" does not exist!' );
  201. }
  202. $previous = $this->_options[$key];
  203. $this->_options[$key] = $value;
  204. return $previous;
  205. }
  206. /**
  207. * Retrieve a single option
  208. *
  209. * @param string $key The name of the option
  210. *
  211. * @return mixed The value of the option
  212. */
  213. public function getOption ($key)
  214. {
  215. if (!array_key_exists($key, $this->_options)) {
  216. throw new Zend_Wildfire_Exception( 'Option with name "' . $key . '" does not exist!' );
  217. }
  218. return $this->_options[$key];
  219. }
  220. /**
  221. * Retrieve all options
  222. *
  223. * @return array All options
  224. */
  225. public function getOptions ()
  226. {
  227. return $this->_options;
  228. }
  229. }