PageRenderTime 74ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Wildfire/Plugin/FirePhp/Message.php

https://bitbucket.org/goldie/zend-framework1
PHP | 246 lines | 84 code | 23 blank | 139 comment | 2 complexity | ec088870cef9e63697ad1d50ac559919 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-2011 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 23775 2011-03-01 17:25:24Z ralph $
  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-2011 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. * @return void
  78. */
  79. function __construct($style, $message)
  80. {
  81. $this->_style = $style;
  82. $this->_message = $message;
  83. $this->_ruid = md5(microtime().mt_rand());
  84. }
  85. /**
  86. * Set the label of the message
  87. *
  88. * @param string $label The label to be set
  89. * @return void
  90. */
  91. public function setLabel($label)
  92. {
  93. $this->_label = $label;
  94. }
  95. /**
  96. * Get the label of the message
  97. *
  98. * @return string The label of the message
  99. */
  100. public function getLabel()
  101. {
  102. return $this->_label;
  103. }
  104. /**
  105. * Enable or disable message buffering
  106. *
  107. * If a message is buffered it can be updated for the duration of the
  108. * request and is only flushed at the end of the request.
  109. *
  110. * @param boolean $buffered TRUE to enable buffering FALSE otherwise
  111. * @return boolean Returns previous buffering value
  112. */
  113. public function setBuffered($buffered)
  114. {
  115. $previous = $this->_buffered;
  116. $this->_buffered = $buffered;
  117. return $previous;
  118. }
  119. /**
  120. * Determine if buffering is enabled or disabled
  121. *
  122. * @return boolean Returns TRUE if buffering is enabled, FALSE otherwise.
  123. */
  124. public function getBuffered()
  125. {
  126. return $this->_buffered;
  127. }
  128. /**
  129. * Destroy the message to prevent delivery
  130. *
  131. * @param boolean $destroy TRUE to destroy FALSE otherwise
  132. * @return boolean Returns previous destroy value
  133. */
  134. public function setDestroy($destroy)
  135. {
  136. $previous = $this->_destroy;
  137. $this->_destroy = $destroy;
  138. return $previous;
  139. }
  140. /**
  141. * Determine if message should be destroyed
  142. *
  143. * @return boolean Returns TRUE if message should be destroyed, FALSE otherwise.
  144. */
  145. public function getDestroy()
  146. {
  147. return $this->_destroy;
  148. }
  149. /**
  150. * Set the style of the message
  151. *
  152. * @return void
  153. */
  154. public function setStyle($style)
  155. {
  156. $this->_style = $style;
  157. }
  158. /**
  159. * Get the style of the message
  160. *
  161. * @return string The style of the message
  162. */
  163. public function getStyle()
  164. {
  165. return $this->_style;
  166. }
  167. /**
  168. * Set the actual message to be sent in its final format.
  169. *
  170. * @return void
  171. */
  172. public function setMessage($message)
  173. {
  174. $this->_message = $message;
  175. }
  176. /**
  177. * Get the actual message to be sent in its final format.
  178. *
  179. * @return mixed Returns the message to be sent.
  180. */
  181. public function getMessage()
  182. {
  183. return $this->_message;
  184. }
  185. /**
  186. * Set a single option
  187. *
  188. * @param string $key The name of the option
  189. * @param mixed $value The value of the option
  190. * @return mixed The previous value of the option
  191. */
  192. public function setOption($key, $value)
  193. {
  194. if(!array_key_exists($key,$this->_options)) {
  195. throw new Zend_Wildfire_Exception('Option with name "'.$key.'" does not exist!');
  196. }
  197. $previous = $this->_options[$key];
  198. $this->_options[$key] = $value;
  199. return $previous;
  200. }
  201. /**
  202. * Retrieve a single option
  203. *
  204. * @param string $key The name of the option
  205. * @return mixed The value of the option
  206. */
  207. public function getOption($key)
  208. {
  209. if(!array_key_exists($key,$this->_options)) {
  210. throw new Zend_Wildfire_Exception('Option with name "'.$key.'" does not exist!');
  211. }
  212. return $this->_options[$key];
  213. }
  214. /**
  215. * Retrieve all options
  216. *
  217. * @return array All options
  218. */
  219. public function getOptions()
  220. {
  221. return $this->_options;
  222. }
  223. }