1 | <?php |
||
33 | class Response extends AbstractResponse |
||
34 | { |
||
35 | use Features\DomCommands; |
||
36 | use Features\JsCommands; |
||
37 | use Features\DomTreeCommands; |
||
38 | |||
39 | /** |
||
40 | * The commands that will be sent to the browser in the response |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $aCommands = []; |
||
45 | |||
46 | /** |
||
47 | * A string, array or integer value to be returned to the caller when using 'synchronous' mode requests. |
||
48 | * See <jaxon->setMode> for details. |
||
49 | * |
||
50 | * @var mixed |
||
51 | */ |
||
52 | private $returnValue; |
||
53 | |||
54 | /** |
||
55 | * Get the content type, which is always set to 'application/json' |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getContentType() |
||
63 | |||
64 | /** |
||
65 | * Provides access to registered response plugins |
||
66 | * |
||
67 | * Pass the plugin name as the first argument and the plugin object will be returned. |
||
68 | * |
||
69 | * @param string $sName The name of the plugin |
||
70 | * |
||
71 | * @return null|\Jaxon\Plugin\Response |
||
72 | */ |
||
73 | public function plugin($sName) |
||
83 | |||
84 | /** |
||
85 | * Magic PHP function |
||
86 | * |
||
87 | * Used to permit plugins to be called as if they where native members of the Response instance. |
||
88 | * |
||
89 | * @param string $sPluginName The name of the plugin |
||
90 | * |
||
91 | * @return null|\Jaxon\Plugin\Response |
||
92 | */ |
||
93 | public function __get($sPluginName) |
||
97 | |||
98 | /** |
||
99 | * Create a JQuery Element with a given selector, and link it to the current response. |
||
100 | * |
||
101 | * This is a shortcut to the JQuery plugin. |
||
102 | * |
||
103 | * @param string $sSelector The jQuery selector |
||
104 | * @param string $sContext A context associated to the selector |
||
105 | * |
||
106 | * @return \Jaxon\Response\Plugin\JQuery\Dom\Element |
||
107 | */ |
||
108 | public function jq($sSelector = '', $sContext = '') |
||
112 | |||
113 | /** |
||
114 | * Create a JQuery Element with a given selector, and link it to the current response. |
||
115 | * |
||
116 | * This is a shortcut to the JQuery plugin. |
||
117 | * |
||
118 | * @param string $sSelector The jQuery selector |
||
119 | * @param string $sContext A context associated to the selector |
||
120 | * |
||
121 | * @return \Jaxon\Response\Plugin\JQuery\Dom\Element |
||
122 | */ |
||
123 | public function jQuery($sSelector = '', $sContext = '') |
||
127 | |||
128 | /** |
||
129 | * Add a response command to the array of commands that will be sent to the browser |
||
130 | * |
||
131 | * @param array $aAttributes Associative array of attributes that will describe the command |
||
132 | * @param mixed $mData The data to be associated with this command |
||
133 | * |
||
134 | * @return Response |
||
135 | */ |
||
136 | public function addCommand(array $aAttributes, $mData) |
||
179 | |||
180 | /** |
||
181 | * Add a response command to the array of commands that will be sent to the browser |
||
182 | * |
||
183 | * @param string $sName The command name |
||
184 | * @param array $aAttributes Associative array of attributes that will describe the command |
||
185 | * @param mixed $mData The data to be associated with this command |
||
186 | * @param boolean $bRemoveEmpty If true, remove empty attributes |
||
187 | * |
||
188 | * @return Response |
||
189 | */ |
||
190 | protected function _addCommand($sName, array $aAttributes, $mData, $bRemoveEmpty = false) |
||
217 | |||
218 | /** |
||
219 | * Clear all the commands already added to the response |
||
220 | * |
||
221 | * @return Response |
||
222 | */ |
||
223 | public function clearCommands() |
||
229 | |||
230 | /** |
||
231 | * Add a response command that is generated by a plugin |
||
232 | * |
||
233 | * @param \Jaxon\Plugin\Response $xPlugin The plugin object |
||
234 | * @param array $aAttributes The attributes for this response command |
||
235 | * @param string $mData The data to be sent with this command |
||
236 | * |
||
237 | * @return Response |
||
238 | */ |
||
239 | public function addPluginCommand($xPlugin, $aAttributes, $mData) |
||
244 | |||
245 | /** |
||
246 | * Merge the response commands from the specified <Response> object with |
||
247 | * the response commands in this <Response> object |
||
248 | * |
||
249 | * @param AbstractResponse|array $mCommands The <Response> object |
||
250 | * @param boolean $bBefore Add the new commands to the beginning of the list |
||
251 | * |
||
252 | * @return void |
||
253 | */ |
||
254 | public function appendResponse($mCommands, $bBefore = false) |
||
283 | |||
284 | /** |
||
285 | * Get the commands in the response |
||
286 | * |
||
287 | * @return array |
||
288 | */ |
||
289 | public function getCommands() |
||
293 | |||
294 | /** |
||
295 | * Get the number of commands in the response |
||
296 | * |
||
297 | * @return integer |
||
298 | */ |
||
299 | public function getCommandCount() |
||
303 | |||
304 | /** |
||
305 | * Stores a value that will be passed back as part of the response |
||
306 | * |
||
307 | * When making synchronous requests, the calling javascript can obtain this value |
||
308 | * immediately as the return value of the <jaxon.call> javascript function |
||
309 | * |
||
310 | * @param mixed $value Any value |
||
311 | * |
||
312 | * @return Response |
||
313 | */ |
||
314 | public function setReturnValue($value) |
||
319 | |||
320 | /** |
||
321 | * Return the output, generated from the commands added to the response, that will be sent to the browser |
||
322 | * |
||
323 | * @return string |
||
324 | */ |
||
325 | public function getOutput() |
||
343 | } |
||
344 |