PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

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