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