@@ -237,20 +237,20 @@ discard block |
||
237 | 237 | public function raiseCallbackEvent($param) |
238 | 238 | { |
239 | 239 | $token = $param->getCallbackParameter(); |
240 | - if(is_array($token) && count($token) == 2) |
|
240 | + if (is_array($token) && count($token) == 2) |
|
241 | 241 | { |
242 | - if($token[1] === '__TJuiAutoComplete_onSuggest__') |
|
242 | + if ($token[1] === '__TJuiAutoComplete_onSuggest__') |
|
243 | 243 | { |
244 | 244 | $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), $token[0]); |
245 | 245 | $this->onSuggest($parameter); |
246 | 246 | } |
247 | - elseif($token[1] === '__TJuiAutoComplete_onSuggestionSelected__') |
|
247 | + elseif ($token[1] === '__TJuiAutoComplete_onSuggestionSelected__') |
|
248 | 248 | { |
249 | 249 | $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), null, $token[0]); |
250 | 250 | $this->onSuggestionSelected($parameter); |
251 | 251 | } |
252 | 252 | } |
253 | - elseif($this->getAutoPostBack()) |
|
253 | + elseif ($this->getAutoPostBack()) |
|
254 | 254 | parent::raiseCallbackEvent($param); |
255 | 255 | } |
256 | 256 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | public function dataBind() |
294 | 294 | { |
295 | 295 | parent::dataBind(); |
296 | - if($this->getPage()->getIsCallback()) |
|
296 | + if ($this->getPage()->getIsCallback()) |
|
297 | 297 | $this->renderSuggestions($this->getResponse()->createHtmlWriter()); |
298 | 298 | } |
299 | 299 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function getResultPanel() |
304 | 304 | { |
305 | - if($this->_resultPanel === null) |
|
305 | + if ($this->_resultPanel === null) |
|
306 | 306 | $this->_resultPanel = $this->createResultPanel(); |
307 | 307 | return $this->_resultPanel; |
308 | 308 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | public function getSuggestions() |
325 | 325 | { |
326 | - if($this->_repeater === null) |
|
326 | + if ($this->_repeater === null) |
|
327 | 327 | $this->_repeater = $this->createRepeater(); |
328 | 328 | return $this->_repeater; |
329 | 329 | } |
@@ -372,16 +372,16 @@ discard block |
||
372 | 372 | */ |
373 | 373 | public function renderSuggestions($writer) |
374 | 374 | { |
375 | - if($this->getActiveControl()->canUpdateClientSide(true)) |
|
375 | + if ($this->getActiveControl()->canUpdateClientSide(true)) |
|
376 | 376 | { |
377 | 377 | $data = []; |
378 | 378 | $items = $this->getSuggestions()->getItems(); |
379 | 379 | $writer = new TTextWriter; |
380 | - for($i = 0; $i < $items->Count; $i++) |
|
380 | + for ($i = 0; $i < $items->Count; $i++) |
|
381 | 381 | { |
382 | 382 | $items->itemAt($i)->render($writer); |
383 | 383 | $item = $writer->flush(); |
384 | - $data[] = [ 'id' => $i, 'label' => $item]; |
|
384 | + $data[] = ['id' => $i, 'label' => $item]; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $this->getResponse()->getAdapter()->setResponseData($data); |
@@ -395,19 +395,19 @@ discard block |
||
395 | 395 | { |
396 | 396 | $options = $this->getOptions()->toArray(); |
397 | 397 | |
398 | - if(strlen($separator = $this->getSeparator())) |
|
398 | + if (strlen($separator = $this->getSeparator())) |
|
399 | 399 | $options['Separators'] = $separator; |
400 | 400 | |
401 | - if($this->getAutoPostBack()) |
|
401 | + if ($this->getAutoPostBack()) |
|
402 | 402 | { |
403 | 403 | $options = array_merge($options, parent::getPostBackOptions()); |
404 | 404 | $options['AutoPostBack'] = true; |
405 | 405 | } |
406 | - if(strlen($textCssClass = $this->getTextCssClass())) |
|
406 | + if (strlen($textCssClass = $this->getTextCssClass())) |
|
407 | 407 | $options['textCssClass'] = $textCssClass; |
408 | 408 | $options['minLength'] = $this->getMinChars(); |
409 | 409 | $options['delay'] = $this->getFrequency() * 1000.0; |
410 | - $options['appendTo'] = '#' . $this->getResultPanel()->getClientID(); |
|
410 | + $options['appendTo'] = '#'.$this->getResultPanel()->getClientID(); |
|
411 | 411 | $options['ID'] = $this->getClientID(); |
412 | 412 | $options['EventTarget'] = $this->getUniqueID(); |
413 | 413 | $options['CausesValidation'] = $this->getCausesValidation(); |
@@ -243,15 +243,14 @@ discard block |
||
243 | 243 | { |
244 | 244 | $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), $token[0]); |
245 | 245 | $this->onSuggest($parameter); |
246 | - } |
|
247 | - elseif($token[1] === '__TJuiAutoComplete_onSuggestionSelected__') |
|
246 | + } elseif($token[1] === '__TJuiAutoComplete_onSuggestionSelected__') |
|
248 | 247 | { |
249 | 248 | $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), null, $token[0]); |
250 | 249 | $this->onSuggestionSelected($parameter); |
251 | 250 | } |
251 | + } elseif($this->getAutoPostBack()) { |
|
252 | + parent::raiseCallbackEvent($param); |
|
252 | 253 | } |
253 | - elseif($this->getAutoPostBack()) |
|
254 | - parent::raiseCallbackEvent($param); |
|
255 | 254 | } |
256 | 255 | |
257 | 256 | /** |
@@ -293,8 +292,9 @@ discard block |
||
293 | 292 | public function dataBind() |
294 | 293 | { |
295 | 294 | parent::dataBind(); |
296 | - if($this->getPage()->getIsCallback()) |
|
297 | - $this->renderSuggestions($this->getResponse()->createHtmlWriter()); |
|
295 | + if($this->getPage()->getIsCallback()) { |
|
296 | + $this->renderSuggestions($this->getResponse()->createHtmlWriter()); |
|
297 | + } |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -302,8 +302,9 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public function getResultPanel() |
304 | 304 | { |
305 | - if($this->_resultPanel === null) |
|
306 | - $this->_resultPanel = $this->createResultPanel(); |
|
305 | + if($this->_resultPanel === null) { |
|
306 | + $this->_resultPanel = $this->createResultPanel(); |
|
307 | + } |
|
307 | 308 | return $this->_resultPanel; |
308 | 309 | } |
309 | 310 | |
@@ -323,8 +324,9 @@ discard block |
||
323 | 324 | */ |
324 | 325 | public function getSuggestions() |
325 | 326 | { |
326 | - if($this->_repeater === null) |
|
327 | - $this->_repeater = $this->createRepeater(); |
|
327 | + if($this->_repeater === null) { |
|
328 | + $this->_repeater = $this->createRepeater(); |
|
329 | + } |
|
328 | 330 | return $this->_repeater; |
329 | 331 | } |
330 | 332 | |
@@ -395,16 +397,18 @@ discard block |
||
395 | 397 | { |
396 | 398 | $options = $this->getOptions()->toArray(); |
397 | 399 | |
398 | - if(strlen($separator = $this->getSeparator())) |
|
399 | - $options['Separators'] = $separator; |
|
400 | + if(strlen($separator = $this->getSeparator())) { |
|
401 | + $options['Separators'] = $separator; |
|
402 | + } |
|
400 | 403 | |
401 | 404 | if($this->getAutoPostBack()) |
402 | 405 | { |
403 | 406 | $options = array_merge($options, parent::getPostBackOptions()); |
404 | 407 | $options['AutoPostBack'] = true; |
405 | 408 | } |
406 | - if(strlen($textCssClass = $this->getTextCssClass())) |
|
407 | - $options['textCssClass'] = $textCssClass; |
|
409 | + if(strlen($textCssClass = $this->getTextCssClass())) { |
|
410 | + $options['textCssClass'] = $textCssClass; |
|
411 | + } |
|
408 | 412 | $options['minLength'] = $this->getMinChars(); |
409 | 413 | $options['delay'] = $this->getFrequency() * 1000.0; |
410 | 414 | $options['appendTo'] = '#' . $this->getResultPanel()->getClientID(); |
@@ -128,7 +128,7 @@ |
||
128 | 128 | $writer->addAttribute('id', $this->getClientID()); |
129 | 129 | $options = TJavaScript::encode($this->getPostBackOptions()); |
130 | 130 | $cs = $this->getPage()->getClientScript(); |
131 | - $code = "jQuery('#" . $this->getWidgetID() . "')." . $this->getWidget() . "(" . $options . ");"; |
|
131 | + $code = "jQuery('#".$this->getWidgetID()."').".$this->getWidget()."(".$options.");"; |
|
132 | 132 | $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); |
133 | 133 | } |
134 | 134 |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | protected function getAssetUrl($file = '') |
75 | 75 | { |
76 | 76 | $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl('jquery-ui'); |
77 | - return $base . '/' . $file; |
|
77 | + return $base.'/'.$file; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function publishJuiStyle($file) |
86 | 86 | { |
87 | - $url = $this->getAssetUrl(self::CSS_PATH . '/' . $this->getJuiBaseStyle() . '/' . $file); |
|
87 | + $url = $this->getAssetUrl(self::CSS_PATH.'/'.$this->getJuiBaseStyle().'/'.$file); |
|
88 | 88 | $cs = $this->getPage()->getClientScript(); |
89 | - if(!$cs->isStyleSheetFileRegistered($url)) |
|
89 | + if (!$cs->isStyleSheetFileRegistered($url)) |
|
90 | 90 | $cs->registerStyleSheetFile($url, $url); |
91 | 91 | return $url; |
92 | 92 | } |
@@ -86,8 +86,9 @@ |
||
86 | 86 | { |
87 | 87 | $url = $this->getAssetUrl(self::CSS_PATH . '/' . $this->getJuiBaseStyle() . '/' . $file); |
88 | 88 | $cs = $this->getPage()->getClientScript(); |
89 | - if(!$cs->isStyleSheetFileRegistered($url)) |
|
90 | - $cs->registerStyleSheetFile($url, $url); |
|
89 | + if(!$cs->isStyleSheetFileRegistered($url)) { |
|
90 | + $cs->registerStyleSheetFile($url, $url); |
|
91 | + } |
|
91 | 92 | return $url; |
92 | 93 | } |
93 | 94 |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $writer->addAttribute('id', $this->getClientID()); |
143 | 143 | $options = TJavaScript::encode($this->getPostBackOptions()); |
144 | 144 | $cs = $this->getPage()->getClientScript(); |
145 | - $code = "jQuery('#" . $this->getWidgetID() . "')." . $this->getWidget() . "(" . $options . ");"; |
|
145 | + $code = "jQuery('#".$this->getWidgetID()."').".$this->getWidget()."(".$options.");"; |
|
146 | 146 | $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); |
147 | 147 | } |
148 | 148 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * Raises the OnActivate event |
161 | 161 | * @param object $params event parameters |
162 | 162 | */ |
163 | - public function onActivate ($params) |
|
163 | + public function onActivate($params) |
|
164 | 164 | { |
165 | 165 | $this->raiseEvent('OnActivate', $this, $params); |
166 | 166 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * Raises the OnCreate event |
170 | 170 | * @param object $params event parameters |
171 | 171 | */ |
172 | - public function onCreate ($params) |
|
172 | + public function onCreate($params) |
|
173 | 173 | { |
174 | 174 | $this->raiseEvent('OnCreate', $this, $params); |
175 | 175 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Raises the OnDeactivate event |
179 | 179 | * @param object $params event parameters |
180 | 180 | */ |
181 | - public function onDeactivate ($params) |
|
181 | + public function onDeactivate($params) |
|
182 | 182 | { |
183 | 183 | $this->raiseEvent('OnDeactivate', $this, $params); |
184 | 184 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * Raises the OnDrop event |
188 | 188 | * @param object $params event parameters |
189 | 189 | */ |
190 | - public function onDrop ($params) |
|
190 | + public function onDrop($params) |
|
191 | 191 | { |
192 | 192 | $this->raiseEvent('OnDrop', $this, $params); |
193 | 193 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * Raises the OnOut event |
197 | 197 | * @param object $params event parameters |
198 | 198 | */ |
199 | - public function OnOut ($params) |
|
199 | + public function OnOut($params) |
|
200 | 200 | { |
201 | 201 | $this->raiseEvent('OnOut', $this, $params); |
202 | 202 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * Raises the OnOver event |
206 | 206 | * @param object $params event parameters |
207 | 207 | */ |
208 | - public function OnOver ($params) |
|
208 | + public function OnOver($params) |
|
209 | 209 | { |
210 | 210 | $this->raiseEvent('OnOver', $this, $params); |
211 | 211 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function setControl($control) |
62 | 62 | { |
63 | - if(!$control instanceof IJuiOptions) |
|
63 | + if (!$control instanceof IJuiOptions) |
|
64 | 64 | throw new THttpException(500, 'juioptions_control_invalid', $control->ID); |
65 | 65 | $this->_control = $control; |
66 | 66 | } |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function __set($name, $value) |
76 | 76 | { |
77 | - if($this->_options === null) |
|
77 | + if ($this->_options === null) |
|
78 | 78 | $this->_options = []; |
79 | 79 | |
80 | - foreach($this->_control->getValidOptions() as $option) |
|
80 | + foreach ($this->_control->getValidOptions() as $option) |
|
81 | 81 | { |
82 | - if(0 == strcasecmp($name, $option)) |
|
82 | + if (0 == strcasecmp($name, $option)) |
|
83 | 83 | { |
84 | 84 | $low = strtolower($value); |
85 | - if($low === 'null') |
|
85 | + if ($low === 'null') |
|
86 | 86 | { |
87 | 87 | $this->_options[$option] = null; |
88 | - } elseif($low === 'true') { |
|
88 | + } elseif ($low === 'true') { |
|
89 | 89 | $this->_options[$option] = true; |
90 | - } elseif($low === 'false') { |
|
90 | + } elseif ($low === 'false') { |
|
91 | 91 | $this->_options[$option] = false; |
92 | - } elseif(is_numeric($value)) { |
|
92 | + } elseif (is_numeric($value)) { |
|
93 | 93 | // trick to get float or integer automatically when needed |
94 | 94 | $this->_options[$option] = $value + 0; |
95 | - } elseif(substr($low, 0, 8) == 'function') { |
|
95 | + } elseif (substr($low, 0, 8) == 'function') { |
|
96 | 96 | $this->_options[$option] = new TJavaScriptLiteral($value); |
97 | 97 | } else { |
98 | 98 | $this->_options[$option] = $value; |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function __get($name) |
114 | 114 | { |
115 | - if($this->_options === null) |
|
115 | + if ($this->_options === null) |
|
116 | 116 | $this->_options = []; |
117 | 117 | |
118 | - foreach($this->_control->getValidOptions() as $option) |
|
118 | + foreach ($this->_control->getValidOptions() as $option) |
|
119 | 119 | { |
120 | - if(0 == strcasecmp($name, $option) && isset($this->_options[$option])) |
|
120 | + if (0 == strcasecmp($name, $option) && isset($this->_options[$option])) |
|
121 | 121 | { |
122 | 122 | return $this->_options[$option]; |
123 | 123 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | { |
142 | 142 | $ret = ($this->_options === null) ? [] : $this->_options; |
143 | 143 | |
144 | - foreach($this->_control->getValidEvents() as $event) |
|
145 | - if($this->_control->hasEventHandler('on' . $event)) |
|
146 | - $ret[$event] = new TJavaScriptLiteral("function( event, ui ) { Prado.JuiCallback(" . TJavaScript::encode($this->_control->getUniqueID()) . ", " . TJavaScript::encode($event) . ", event, ui, this); }"); |
|
144 | + foreach ($this->_control->getValidEvents() as $event) |
|
145 | + if ($this->_control->hasEventHandler('on'.$event)) |
|
146 | + $ret[$event] = new TJavaScriptLiteral("function( event, ui ) { Prado.JuiCallback(".TJavaScript::encode($this->_control->getUniqueID()).", ".TJavaScript::encode($event).", event, ui, this); }"); |
|
147 | 147 | |
148 | 148 | return $ret; |
149 | 149 | } |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | public function raiseCallbackEvent($param) |
156 | 156 | { |
157 | 157 | $callbackParam = $param->CallbackParameter; |
158 | - if(isset($callbackParam->event)) |
|
158 | + if (isset($callbackParam->event)) |
|
159 | 159 | { |
160 | - $eventName = 'On' . ucfirst($callbackParam->event); |
|
161 | - if($this->_control->hasEventHandler($eventName)) |
|
160 | + $eventName = 'On'.ucfirst($callbackParam->event); |
|
161 | + if ($this->_control->hasEventHandler($eventName)) |
|
162 | 162 | { |
163 | 163 | $this->_control->$eventName(new TJuiEventParameter( |
164 | 164 | $this->_control->getResponse(), |
@@ -60,8 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function setControl($control) |
62 | 62 | { |
63 | - if(!$control instanceof IJuiOptions) |
|
64 | - throw new THttpException(500, 'juioptions_control_invalid', $control->ID); |
|
63 | + if(!$control instanceof IJuiOptions) { |
|
64 | + throw new THttpException(500, 'juioptions_control_invalid', $control->ID); |
|
65 | + } |
|
65 | 66 | $this->_control = $control; |
66 | 67 | } |
67 | 68 | |
@@ -74,8 +75,9 @@ discard block |
||
74 | 75 | */ |
75 | 76 | public function __set($name, $value) |
76 | 77 | { |
77 | - if($this->_options === null) |
|
78 | - $this->_options = []; |
|
78 | + if($this->_options === null) { |
|
79 | + $this->_options = []; |
|
80 | + } |
|
79 | 81 | |
80 | 82 | foreach($this->_control->getValidOptions() as $option) |
81 | 83 | { |
@@ -112,8 +114,9 @@ discard block |
||
112 | 114 | */ |
113 | 115 | public function __get($name) |
114 | 116 | { |
115 | - if($this->_options === null) |
|
116 | - $this->_options = []; |
|
117 | + if($this->_options === null) { |
|
118 | + $this->_options = []; |
|
119 | + } |
|
117 | 120 | |
118 | 121 | foreach($this->_control->getValidOptions() as $option) |
119 | 122 | { |
@@ -141,9 +144,10 @@ discard block |
||
141 | 144 | { |
142 | 145 | $ret = ($this->_options === null) ? [] : $this->_options; |
143 | 146 | |
144 | - foreach($this->_control->getValidEvents() as $event) |
|
145 | - if($this->_control->hasEventHandler('on' . $event)) |
|
147 | + foreach($this->_control->getValidEvents() as $event) { |
|
148 | + if($this->_control->hasEventHandler('on' . $event)) |
|
146 | 149 | $ret[$event] = new TJavaScriptLiteral("function( event, ui ) { Prado.JuiCallback(" . TJavaScript::encode($this->_control->getUniqueID()) . ", " . TJavaScript::encode($event) . ", event, ui, this); }"); |
150 | + } |
|
147 | 151 | |
148 | 152 | return $ret; |
149 | 153 | } |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | { |
106 | 106 | $options = $this->getOptions()->toArray(); |
107 | 107 | // always make the dialog a child of the form, or its inner inputs won't be collected |
108 | - if(!isset($options['appendTo'])) |
|
108 | + if (!isset($options['appendTo'])) |
|
109 | 109 | $options['appendTo'] = 'form:first'; |
110 | 110 | |
111 | - foreach($this->getControls() as $control) |
|
112 | - if($control instanceof TJuiDialogButton) |
|
111 | + foreach ($this->getControls() as $control) |
|
112 | + if ($control instanceof TJuiDialogButton) |
|
113 | 113 | $options['buttons'][] = $control->getPostBackOptions(); |
114 | 114 | |
115 | 115 | return $options; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $writer->addAttribute('id', $this->getClientID()); |
127 | 127 | $options = TJavaScript::encode($this->getPostBackOptions()); |
128 | 128 | $cs = $this->getPage()->getClientScript(); |
129 | - $code = "jQuery('#" . $this->getWidgetID() . "')." . $this->getWidget() . "(" . $options . ");"; |
|
129 | + $code = "jQuery('#".$this->getWidgetID()."').".$this->getWidget()."(".$options.");"; |
|
130 | 130 | $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); |
131 | 131 | } |
132 | 132 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * Raises the OnCreate event |
145 | 145 | * @param object $params event parameters |
146 | 146 | */ |
147 | - public function onOpen ($params) |
|
147 | + public function onOpen($params) |
|
148 | 148 | { |
149 | 149 | $this->raiseEvent('OnOpen', $this, $params); |
150 | 150 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | private function triggerClientMethod($method) |
169 | 169 | { |
170 | 170 | $cs = $this->getPage()->getClientScript(); |
171 | - $code = "jQuery(document).ready(function() { jQuery('#" . $this->getClientId() . "').dialog('" . $method . "'); })"; |
|
171 | + $code = "jQuery(document).ready(function() { jQuery('#".$this->getClientId()."').dialog('".$method."'); })"; |
|
172 | 172 | $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); |
173 | 173 | } |
174 | 174 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function render($writer) |
191 | 191 | { |
192 | - if($this->getHasPreRendered() && $this->getActiveControl()->canUpdateClientSide()) |
|
192 | + if ($this->getHasPreRendered() && $this->getActiveControl()->canUpdateClientSide()) |
|
193 | 193 | { |
194 | 194 | parent::renderContents($writer); |
195 | 195 | $this->getPage()->getCallbackClient()->replaceContent($this, $writer, false); |
@@ -105,12 +105,14 @@ discard block |
||
105 | 105 | { |
106 | 106 | $options = $this->getOptions()->toArray(); |
107 | 107 | // always make the dialog a child of the form, or its inner inputs won't be collected |
108 | - if(!isset($options['appendTo'])) |
|
109 | - $options['appendTo'] = 'form:first'; |
|
108 | + if(!isset($options['appendTo'])) { |
|
109 | + $options['appendTo'] = 'form:first'; |
|
110 | + } |
|
110 | 111 | |
111 | - foreach($this->getControls() as $control) |
|
112 | - if($control instanceof TJuiDialogButton) |
|
112 | + foreach($this->getControls() as $control) { |
|
113 | + if($control instanceof TJuiDialogButton) |
|
113 | 114 | $options['buttons'][] = $control->getPostBackOptions(); |
115 | + } |
|
114 | 116 | |
115 | 117 | return $options; |
116 | 118 | } |
@@ -193,8 +195,8 @@ discard block |
||
193 | 195 | { |
194 | 196 | parent::renderContents($writer); |
195 | 197 | $this->getPage()->getCallbackClient()->replaceContent($this, $writer, false); |
198 | + } else { |
|
199 | + parent::render($writer); |
|
196 | 200 | } |
197 | - else |
|
198 | - parent::render($writer); |
|
199 | 201 | } |
200 | 202 | } |
@@ -192,38 +192,38 @@ discard block |
||
192 | 192 | public function instantiateIn($tplControl, $parentControl = null) |
193 | 193 | { |
194 | 194 | $this->_tplControl = $tplControl; |
195 | - if($parentControl === null) |
|
195 | + if ($parentControl === null) |
|
196 | 196 | $parentControl = $tplControl; |
197 | - if(($page = $tplControl->getPage()) === null) |
|
197 | + if (($page = $tplControl->getPage()) === null) |
|
198 | 198 | $page = $this->getService()->getRequestedPage(); |
199 | 199 | $controls = []; |
200 | 200 | $directChildren = []; |
201 | - foreach($this->_tpl as $key => $object) |
|
201 | + foreach ($this->_tpl as $key => $object) |
|
202 | 202 | { |
203 | - if($object[0] === -1) |
|
203 | + if ($object[0] === -1) |
|
204 | 204 | $parent = $parentControl; |
205 | - elseif(isset($controls[$object[0]])) |
|
205 | + elseif (isset($controls[$object[0]])) |
|
206 | 206 | $parent = $controls[$object[0]]; |
207 | 207 | else |
208 | 208 | continue; |
209 | - if(isset($object[2])) // component |
|
209 | + if (isset($object[2])) // component |
|
210 | 210 | { |
211 | 211 | $component = Prado::createComponent($object[1]); |
212 | 212 | $properties = &$object[2]; |
213 | - if($component instanceof TControl) |
|
213 | + if ($component instanceof TControl) |
|
214 | 214 | { |
215 | - if($component instanceof \Prado\Web\UI\WebControls\TOutputCache) |
|
216 | - $component->setCacheKeyPrefix($this->_hashCode . $key); |
|
215 | + if ($component instanceof \Prado\Web\UI\WebControls\TOutputCache) |
|
216 | + $component->setCacheKeyPrefix($this->_hashCode.$key); |
|
217 | 217 | $component->setTemplateControl($tplControl); |
218 | - if(isset($properties['id'])) |
|
218 | + if (isset($properties['id'])) |
|
219 | 219 | { |
220 | - if(is_array($properties['id'])) |
|
220 | + if (is_array($properties['id'])) |
|
221 | 221 | $properties['id'] = $component->evaluateExpression($properties['id'][1]); |
222 | 222 | $tplControl->registerObject($properties['id'], $component); |
223 | 223 | } |
224 | - if(isset($properties['skinid'])) |
|
224 | + if (isset($properties['skinid'])) |
|
225 | 225 | { |
226 | - if(is_array($properties['skinid'])) |
|
226 | + if (is_array($properties['skinid'])) |
|
227 | 227 | $component->setSkinID($component->evaluateExpression($properties['skinid'][1])); |
228 | 228 | else |
229 | 229 | $component->setSkinID($properties['skinid']); |
@@ -233,32 +233,32 @@ discard block |
||
233 | 233 | $component->trackViewState(false); |
234 | 234 | |
235 | 235 | $component->applyStyleSheetSkin($page); |
236 | - foreach($properties as $name => $value) |
|
236 | + foreach ($properties as $name => $value) |
|
237 | 237 | $this->configureControl($component, $name, $value); |
238 | 238 | |
239 | 239 | $component->trackViewState(true); |
240 | 240 | |
241 | - if($parent === $parentControl) |
|
241 | + if ($parent === $parentControl) |
|
242 | 242 | $directChildren[] = $component; |
243 | 243 | else |
244 | 244 | $component->createdOnTemplate($parent); |
245 | - if($component->getAllowChildControls()) |
|
245 | + if ($component->getAllowChildControls()) |
|
246 | 246 | $controls[$key] = $component; |
247 | 247 | } |
248 | - elseif($component instanceof TComponent) |
|
248 | + elseif ($component instanceof TComponent) |
|
249 | 249 | { |
250 | 250 | $controls[$key] = $component; |
251 | - if(isset($properties['id'])) |
|
251 | + if (isset($properties['id'])) |
|
252 | 252 | { |
253 | - if(is_array($properties['id'])) |
|
253 | + if (is_array($properties['id'])) |
|
254 | 254 | $properties['id'] = $component->evaluateExpression($properties['id'][1]); |
255 | 255 | $tplControl->registerObject($properties['id'], $component); |
256 | - if(!$component->hasProperty('id')) |
|
256 | + if (!$component->hasProperty('id')) |
|
257 | 257 | unset($properties['id']); |
258 | 258 | } |
259 | - foreach($properties as $name => $value) |
|
259 | + foreach ($properties as $name => $value) |
|
260 | 260 | $this->configureComponent($component, $name, $value); |
261 | - if($parent === $parentControl) |
|
261 | + if ($parent === $parentControl) |
|
262 | 262 | $directChildren[] = $component; |
263 | 263 | else |
264 | 264 | $component->createdOnTemplate($parent); |
@@ -266,19 +266,19 @@ discard block |
||
266 | 266 | } |
267 | 267 | else |
268 | 268 | { |
269 | - if($object[1] instanceof TCompositeLiteral) |
|
269 | + if ($object[1] instanceof TCompositeLiteral) |
|
270 | 270 | { |
271 | 271 | // need to clone a new object because the one in template is reused |
272 | 272 | $o = clone $object[1]; |
273 | 273 | $o->setContainer($tplControl); |
274 | - if($parent === $parentControl) |
|
274 | + if ($parent === $parentControl) |
|
275 | 275 | $directChildren[] = $o; |
276 | 276 | else |
277 | 277 | $parent->addParsedObject($o); |
278 | 278 | } |
279 | 279 | else |
280 | 280 | { |
281 | - if($parent === $parentControl) |
|
281 | + if ($parent === $parentControl) |
|
282 | 282 | $directChildren[] = $object[1]; |
283 | 283 | else |
284 | 284 | $parent->addParsedObject($object[1]); |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | // delay setting parent till now because the parent may cause |
289 | 289 | // the child to do lifecycle catchup which may cause problem |
290 | 290 | // if the child needs its own child controls. |
291 | - foreach($directChildren as $control) |
|
291 | + foreach ($directChildren as $control) |
|
292 | 292 | { |
293 | - if($control instanceof TComponent) |
|
293 | + if ($control instanceof TComponent) |
|
294 | 294 | $control->createdOnTemplate($parentControl); |
295 | 295 | else |
296 | 296 | $parentControl->addParsedObject($control); |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | */ |
306 | 306 | protected function configureControl($control, $name, $value) |
307 | 307 | { |
308 | - if(strncasecmp($name, 'on', 2) === 0) // is an event |
|
308 | + if (strncasecmp($name, 'on', 2) === 0) // is an event |
|
309 | 309 | $this->configureEvent($control, $name, $value, $control); |
310 | - elseif(($pos = strrpos($name, '.')) === false) // is a simple property or custom attribute |
|
310 | + elseif (($pos = strrpos($name, '.')) === false) // is a simple property or custom attribute |
|
311 | 311 | $this->configureProperty($control, $name, $value); |
312 | 312 | else // is a subproperty |
313 | 313 | $this->configureSubProperty($control, $name, $value); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | protected function configureComponent($component, $name, $value) |
323 | 323 | { |
324 | - if(strpos($name, '.') === false) // is a simple property or custom attribute |
|
324 | + if (strpos($name, '.') === false) // is a simple property or custom attribute |
|
325 | 325 | $this->configureProperty($component, $name, $value); |
326 | 326 | else // is a subproperty |
327 | 327 | $this->configureSubProperty($component, $name, $value); |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | */ |
337 | 337 | protected function configureEvent($control, $name, $value, $contextControl) |
338 | 338 | { |
339 | - if(strpos($value, '.') === false) |
|
340 | - $control->attachEventHandler($name, [$contextControl,'TemplateControl.' . $value]); |
|
339 | + if (strpos($value, '.') === false) |
|
340 | + $control->attachEventHandler($name, [$contextControl, 'TemplateControl.'.$value]); |
|
341 | 341 | else |
342 | - $control->attachEventHandler($name, [$contextControl,$value]); |
|
342 | + $control->attachEventHandler($name, [$contextControl, $value]); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -350,37 +350,37 @@ discard block |
||
350 | 350 | */ |
351 | 351 | protected function configureProperty($component, $name, $value) |
352 | 352 | { |
353 | - if(is_array($value)) |
|
353 | + if (is_array($value)) |
|
354 | 354 | { |
355 | - switch($value[0]) |
|
355 | + switch ($value[0]) |
|
356 | 356 | { |
357 | 357 | case self::CONFIG_DATABIND: |
358 | 358 | $component->bindProperty($name, $value[1]); |
359 | 359 | break; |
360 | 360 | case self::CONFIG_EXPRESSION: |
361 | - if($component instanceof TControl) |
|
361 | + if ($component instanceof TControl) |
|
362 | 362 | $component->autoBindProperty($name, $value[1]); |
363 | 363 | else |
364 | 364 | { |
365 | - $setter = 'set' . $name; |
|
365 | + $setter = 'set'.$name; |
|
366 | 366 | $component->$setter($this->_tplControl->evaluateExpression($value[1])); |
367 | 367 | } |
368 | 368 | break; |
369 | 369 | case self::CONFIG_TEMPLATE: |
370 | - $setter = 'set' . $name; |
|
370 | + $setter = 'set'.$name; |
|
371 | 371 | $component->$setter($value[1]); |
372 | 372 | break; |
373 | 373 | case self::CONFIG_ASSET: // asset URL |
374 | - $setter = 'set' . $name; |
|
375 | - $url = $this->publishFilePath($this->_contextPath . DIRECTORY_SEPARATOR . $value[1]); |
|
374 | + $setter = 'set'.$name; |
|
375 | + $url = $this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]); |
|
376 | 376 | $component->$setter($url); |
377 | 377 | break; |
378 | 378 | case self::CONFIG_PARAMETER: // application parameter |
379 | - $setter = 'set' . $name; |
|
379 | + $setter = 'set'.$name; |
|
380 | 380 | $component->$setter($this->getApplication()->getParameters()->itemAt($value[1])); |
381 | 381 | break; |
382 | 382 | case self::CONFIG_LOCALIZATION: |
383 | - $setter = 'set' . $name; |
|
383 | + $setter = 'set'.$name; |
|
384 | 384 | $component->$setter(Prado::localize($value[1])); |
385 | 385 | break; |
386 | 386 | default: // an error if reaching here |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | if (substr($name, 0, 2) == 'js') |
394 | 394 | if ($value and !($value instanceof TJavaScriptLiteral)) |
395 | 395 | $value = new TJavaScriptLiteral($value); |
396 | - $setter = 'set' . $name; |
|
396 | + $setter = 'set'.$name; |
|
397 | 397 | $component->$setter($value); |
398 | 398 | } |
399 | 399 | } |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | */ |
407 | 407 | protected function configureSubProperty($component, $name, $value) |
408 | 408 | { |
409 | - if(is_array($value)) |
|
409 | + if (is_array($value)) |
|
410 | 410 | { |
411 | - switch($value[0]) |
|
411 | + switch ($value[0]) |
|
412 | 412 | { |
413 | 413 | case self::CONFIG_DATABIND: // databinding |
414 | 414 | $component->bindProperty($name, $value[1]); |
415 | 415 | break; |
416 | 416 | case self::CONFIG_EXPRESSION: // expression |
417 | - if($component instanceof TControl) |
|
417 | + if ($component instanceof TControl) |
|
418 | 418 | $component->autoBindProperty($name, $value[1]); |
419 | 419 | else |
420 | 420 | $component->setSubProperty($name, $this->_tplControl->evaluateExpression($value[1])); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | $component->setSubProperty($name, $value[1]); |
424 | 424 | break; |
425 | 425 | case self::CONFIG_ASSET: // asset URL |
426 | - $url = $this->publishFilePath($this->_contextPath . DIRECTORY_SEPARATOR . $value[1]); |
|
426 | + $url = $this->publishFilePath($this->_contextPath.DIRECTORY_SEPARATOR.$value[1]); |
|
427 | 427 | $component->setSubProperty($name, $url); |
428 | 428 | break; |
429 | 429 | case self::CONFIG_PARAMETER: // application parameter |
@@ -476,105 +476,105 @@ discard block |
||
476 | 476 | $this->_directive = null; |
477 | 477 | try |
478 | 478 | { |
479 | - for($i = 0;$i < $n;++$i) |
|
479 | + for ($i = 0; $i < $n; ++$i) |
|
480 | 480 | { |
481 | 481 | $match = &$matches[$i]; |
482 | 482 | $str = $match[0][0]; |
483 | 483 | $matchStart = $match[0][1]; |
484 | 484 | $matchEnd = $matchStart + strlen($str) - 1; |
485 | - if(strpos($str, '<com:') === 0) // opening component tag |
|
485 | + if (strpos($str, '<com:') === 0) // opening component tag |
|
486 | 486 | { |
487 | - if($expectPropEnd) |
|
487 | + if ($expectPropEnd) |
|
488 | 488 | continue; |
489 | - if($matchStart > $textStart) |
|
490 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
489 | + if ($matchStart > $textStart) |
|
490 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
491 | 491 | $textStart = $matchEnd + 1; |
492 | 492 | $type = $match[1][0]; |
493 | 493 | $attributes = $this->parseAttributes($match[2][0], $match[2][1]); |
494 | 494 | $class = $this->validateAttributes($type, $attributes); |
495 | - $tpl[$c++] = [$container,$class,$attributes]; |
|
496 | - if($str[strlen($str) - 2] !== '/') // open tag |
|
495 | + $tpl[$c++] = [$container, $class, $attributes]; |
|
496 | + if ($str[strlen($str) - 2] !== '/') // open tag |
|
497 | 497 | { |
498 | 498 | $stack[] = $type; |
499 | 499 | $container = $c - 1; |
500 | 500 | } |
501 | 501 | } |
502 | - elseif(strpos($str, '</com:') === 0) // closing component tag |
|
502 | + elseif (strpos($str, '</com:') === 0) // closing component tag |
|
503 | 503 | { |
504 | - if($expectPropEnd) |
|
504 | + if ($expectPropEnd) |
|
505 | 505 | continue; |
506 | - if($matchStart > $textStart) |
|
507 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
506 | + if ($matchStart > $textStart) |
|
507 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
508 | 508 | $textStart = $matchEnd + 1; |
509 | 509 | $type = $match[1][0]; |
510 | 510 | |
511 | - if(empty($stack)) |
|
511 | + if (empty($stack)) |
|
512 | 512 | throw new TConfigurationException('template_closingtag_unexpected', "</com:$type>"); |
513 | 513 | |
514 | 514 | $name = array_pop($stack); |
515 | - if($name !== $type) |
|
515 | + if ($name !== $type) |
|
516 | 516 | { |
517 | - $tag = $name[0] === '@' ? '</prop:' . substr($name, 1) . '>' : "</com:$name>"; |
|
517 | + $tag = $name[0] === '@' ? '</prop:'.substr($name, 1).'>' : "</com:$name>"; |
|
518 | 518 | throw new TConfigurationException('template_closingtag_expected', $tag, "</com:$type>"); |
519 | 519 | } |
520 | 520 | $container = $tpl[$container][0]; |
521 | 521 | } |
522 | - elseif(strpos($str, '<%@') === 0) // directive |
|
522 | + elseif (strpos($str, '<%@') === 0) // directive |
|
523 | 523 | { |
524 | - if($expectPropEnd) |
|
524 | + if ($expectPropEnd) |
|
525 | 525 | continue; |
526 | - if($matchStart > $textStart) |
|
527 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
526 | + if ($matchStart > $textStart) |
|
527 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
528 | 528 | $textStart = $matchEnd + 1; |
529 | - if(isset($tpl[0]) || $this->_directive !== null) |
|
529 | + if (isset($tpl[0]) || $this->_directive !== null) |
|
530 | 530 | throw new TConfigurationException('template_directive_nonunique'); |
531 | 531 | $this->_directive = $this->parseAttributes($match[4][0], $match[4][1]); |
532 | 532 | } |
533 | - elseif(strpos($str, '<%') === 0) // expression |
|
533 | + elseif (strpos($str, '<%') === 0) // expression |
|
534 | 534 | { |
535 | - if($expectPropEnd) |
|
535 | + if ($expectPropEnd) |
|
536 | 536 | continue; |
537 | - if($matchStart > $textStart) |
|
538 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
537 | + if ($matchStart > $textStart) |
|
538 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
539 | 539 | $textStart = $matchEnd + 1; |
540 | 540 | $literal = trim($match[5][0]); |
541 | - if($str[2] === '=') // expression |
|
542 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,$literal]]; |
|
543 | - elseif($str[2] === '%') // statements |
|
544 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_STATEMENTS,$literal]]; |
|
545 | - elseif($str[2] === '#') |
|
546 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_DATABINDING,$literal]]; |
|
547 | - elseif($str[2] === '$') |
|
548 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"]]; |
|
549 | - elseif($str[2] === '~') |
|
550 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"]]; |
|
551 | - elseif($str[2] === '/') |
|
552 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]]; |
|
553 | - elseif($str[2] === '[') |
|
541 | + if ($str[2] === '=') // expression |
|
542 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_EXPRESSION, $literal]]; |
|
543 | + elseif ($str[2] === '%') // statements |
|
544 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_STATEMENTS, $literal]]; |
|
545 | + elseif ($str[2] === '#') |
|
546 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_DATABINDING, $literal]]; |
|
547 | + elseif ($str[2] === '$') |
|
548 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_EXPRESSION, "\$this->getApplication()->getParameters()->itemAt('$literal')"]]; |
|
549 | + elseif ($str[2] === '~') |
|
550 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_EXPRESSION, "\$this->publishFilePath('$this->_contextPath/$literal')"]]; |
|
551 | + elseif ($str[2] === '/') |
|
552 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_EXPRESSION, "rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]]; |
|
553 | + elseif ($str[2] === '[') |
|
554 | 554 | { |
555 | - $literal = strtr(trim(substr($literal, 0, strlen($literal) - 1)), ["'" => "\'","\\" => "\\\\"]); |
|
556 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')"]]; |
|
555 | + $literal = strtr(trim(substr($literal, 0, strlen($literal) - 1)), ["'" => "\'", "\\" => "\\\\"]); |
|
556 | + $tpl[$c++] = [$container, [TCompositeLiteral::TYPE_EXPRESSION, "Prado::localize('$literal')"]]; |
|
557 | 557 | } |
558 | 558 | } |
559 | - elseif(strpos($str, '<prop:') === 0) // opening property |
|
559 | + elseif (strpos($str, '<prop:') === 0) // opening property |
|
560 | 560 | { |
561 | - if(strrpos($str, '/>') === strlen($str) - 2) //subproperties |
|
561 | + if (strrpos($str, '/>') === strlen($str) - 2) //subproperties |
|
562 | 562 | { |
563 | - if($expectPropEnd) |
|
563 | + if ($expectPropEnd) |
|
564 | 564 | continue; |
565 | - if($matchStart > $textStart) |
|
566 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
565 | + if ($matchStart > $textStart) |
|
566 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
567 | 567 | $textStart = $matchEnd + 1; |
568 | 568 | $prop = strtolower($match[6][0]); |
569 | 569 | $attrs = $this->parseAttributes($match[7][0], $match[7][1]); |
570 | 570 | $attributes = []; |
571 | - foreach($attrs as $name => $value) |
|
572 | - $attributes[$prop . '.' . $name] = $value; |
|
571 | + foreach ($attrs as $name => $value) |
|
572 | + $attributes[$prop.'.'.$name] = $value; |
|
573 | 573 | $type = $tpl[$container][1]; |
574 | 574 | $this->validateAttributes($type, $attributes); |
575 | - foreach($attributes as $name => $value) |
|
575 | + foreach ($attributes as $name => $value) |
|
576 | 576 | { |
577 | - if(isset($tpl[$container][2][$name])) |
|
577 | + if (isset($tpl[$container][2][$name])) |
|
578 | 578 | throw new TConfigurationException('template_property_duplicated', $name); |
579 | 579 | $tpl[$container][2][$name] = $value; |
580 | 580 | } |
@@ -582,41 +582,41 @@ discard block |
||
582 | 582 | else // regular property |
583 | 583 | { |
584 | 584 | $prop = strtolower($match[3][0]); |
585 | - $stack[] = '@' . $prop; |
|
586 | - if(!$expectPropEnd) |
|
585 | + $stack[] = '@'.$prop; |
|
586 | + if (!$expectPropEnd) |
|
587 | 587 | { |
588 | - if($matchStart > $textStart) |
|
589 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
588 | + if ($matchStart > $textStart) |
|
589 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
590 | 590 | $textStart = $matchEnd + 1; |
591 | 591 | $expectPropEnd = true; |
592 | 592 | } |
593 | 593 | } |
594 | 594 | } |
595 | - elseif(strpos($str, '</prop:') === 0) // closing property |
|
595 | + elseif (strpos($str, '</prop:') === 0) // closing property |
|
596 | 596 | { |
597 | 597 | $prop = strtolower($match[3][0]); |
598 | - if(empty($stack)) |
|
598 | + if (empty($stack)) |
|
599 | 599 | throw new TConfigurationException('template_closingtag_unexpected', "</prop:$prop>"); |
600 | 600 | $name = array_pop($stack); |
601 | - if($name !== '@' . $prop) |
|
601 | + if ($name !== '@'.$prop) |
|
602 | 602 | { |
603 | - $tag = $name[0] === '@' ? '</prop:' . substr($name, 1) . '>' : "</com:$name>"; |
|
603 | + $tag = $name[0] === '@' ? '</prop:'.substr($name, 1).'>' : "</com:$name>"; |
|
604 | 604 | throw new TConfigurationException('template_closingtag_expected', $tag, "</prop:$prop>"); |
605 | 605 | } |
606 | - if(($last = count($stack)) < 1 || $stack[$last - 1][0] !== '@') |
|
606 | + if (($last = count($stack)) < 1 || $stack[$last - 1][0] !== '@') |
|
607 | 607 | { |
608 | - if($matchStart > $textStart) |
|
608 | + if ($matchStart > $textStart) |
|
609 | 609 | { |
610 | 610 | $value = substr($input, $textStart, $matchStart - $textStart); |
611 | - if(substr($prop, -8, 8) === 'template') |
|
611 | + if (substr($prop, -8, 8) === 'template') |
|
612 | 612 | $value = $this->parseTemplateProperty($value, $textStart); |
613 | 613 | else |
614 | 614 | $value = $this->parseAttribute($value); |
615 | - if($container >= 0) |
|
615 | + if ($container >= 0) |
|
616 | 616 | { |
617 | 617 | $type = $tpl[$container][1]; |
618 | 618 | $this->validateAttributes($type, [$prop => $value]); |
619 | - if(isset($tpl[$container][2][$prop])) |
|
619 | + if (isset($tpl[$container][2][$prop])) |
|
620 | 620 | throw new TConfigurationException('template_property_duplicated', $prop); |
621 | 621 | $tpl[$container][2][$prop] = $value; |
622 | 622 | } |
@@ -627,56 +627,56 @@ discard block |
||
627 | 627 | $expectPropEnd = false; |
628 | 628 | } |
629 | 629 | } |
630 | - elseif(strpos($str, '<!--') === 0) // comments |
|
630 | + elseif (strpos($str, '<!--') === 0) // comments |
|
631 | 631 | { |
632 | - if($expectPropEnd) |
|
632 | + if ($expectPropEnd) |
|
633 | 633 | throw new TConfigurationException('template_comments_forbidden'); |
634 | - if($matchStart > $textStart) |
|
635 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
634 | + if ($matchStart > $textStart) |
|
635 | + $tpl[$c++] = [$container, substr($input, $textStart, $matchStart - $textStart)]; |
|
636 | 636 | $textStart = $matchEnd + 1; |
637 | 637 | } |
638 | 638 | else |
639 | 639 | throw new TConfigurationException('template_matching_unexpected', $match); |
640 | 640 | } |
641 | - if(!empty($stack)) |
|
641 | + if (!empty($stack)) |
|
642 | 642 | { |
643 | 643 | $name = array_pop($stack); |
644 | - $tag = $name[0] === '@' ? '</prop:' . substr($name, 1) . '>' : "</com:$name>"; |
|
644 | + $tag = $name[0] === '@' ? '</prop:'.substr($name, 1).'>' : "</com:$name>"; |
|
645 | 645 | throw new TConfigurationException('template_closingtag_expected', $tag, "nothing"); |
646 | 646 | } |
647 | - if($textStart < strlen($input)) |
|
648 | - $tpl[$c++] = [$container,substr($input, $textStart)]; |
|
647 | + if ($textStart < strlen($input)) |
|
648 | + $tpl[$c++] = [$container, substr($input, $textStart)]; |
|
649 | 649 | } |
650 | - catch(\Exception $e) |
|
650 | + catch (\Exception $e) |
|
651 | 651 | { |
652 | - if(($e instanceof TException) && ($e instanceof TTemplateException)) |
|
652 | + if (($e instanceof TException) && ($e instanceof TTemplateException)) |
|
653 | 653 | throw $e; |
654 | - if($matchEnd === 0) |
|
654 | + if ($matchEnd === 0) |
|
655 | 655 | $line = $this->_startingLine + 1; |
656 | 656 | else |
657 | 657 | $line = $this->_startingLine + count(explode("\n", substr($input, 0, $matchEnd + 1))); |
658 | 658 | $this->handleException($e, $line, $input); |
659 | 659 | } |
660 | 660 | |
661 | - if($this->_directive === null) |
|
661 | + if ($this->_directive === null) |
|
662 | 662 | $this->_directive = []; |
663 | 663 | |
664 | 664 | // optimization by merging consecutive strings, expressions, statements and bindings |
665 | 665 | $objects = []; |
666 | 666 | $parent = null; |
667 | 667 | $merged = []; |
668 | - foreach($tpl as $id => $object) |
|
668 | + foreach ($tpl as $id => $object) |
|
669 | 669 | { |
670 | - if(isset($object[2]) || $object[0] !== $parent) |
|
670 | + if (isset($object[2]) || $object[0] !== $parent) |
|
671 | 671 | { |
672 | - if($parent !== null) |
|
672 | + if ($parent !== null) |
|
673 | 673 | { |
674 | - if(count($merged[1]) === 1 && is_string($merged[1][0])) |
|
675 | - $objects[$id - 1] = [$merged[0],$merged[1][0]]; |
|
674 | + if (count($merged[1]) === 1 && is_string($merged[1][0])) |
|
675 | + $objects[$id - 1] = [$merged[0], $merged[1][0]]; |
|
676 | 676 | else |
677 | - $objects[$id - 1] = [$merged[0],new TCompositeLiteral($merged[1])]; |
|
677 | + $objects[$id - 1] = [$merged[0], new TCompositeLiteral($merged[1])]; |
|
678 | 678 | } |
679 | - if(isset($object[2])) |
|
679 | + if (isset($object[2])) |
|
680 | 680 | { |
681 | 681 | $parent = null; |
682 | 682 | $objects[$id] = $object; |
@@ -684,18 +684,18 @@ discard block |
||
684 | 684 | else |
685 | 685 | { |
686 | 686 | $parent = $object[0]; |
687 | - $merged = [$parent,[$object[1]]]; |
|
687 | + $merged = [$parent, [$object[1]]]; |
|
688 | 688 | } |
689 | 689 | } |
690 | 690 | else |
691 | 691 | $merged[1][] = $object[1]; |
692 | 692 | } |
693 | - if($parent !== null) |
|
693 | + if ($parent !== null) |
|
694 | 694 | { |
695 | - if(count($merged[1]) === 1 && is_string($merged[1][0])) |
|
696 | - $objects[$id] = [$merged[0],$merged[1][0]]; |
|
695 | + if (count($merged[1]) === 1 && is_string($merged[1][0])) |
|
696 | + $objects[$id] = [$merged[0], $merged[1][0]]; |
|
697 | 697 | else |
698 | - $objects[$id] = [$merged[0],new TCompositeLiteral($merged[1])]; |
|
698 | + $objects[$id] = [$merged[0], new TCompositeLiteral($merged[1])]; |
|
699 | 699 | } |
700 | 700 | $tpl = $objects; |
701 | 701 | return $objects; |
@@ -708,28 +708,28 @@ discard block |
||
708 | 708 | */ |
709 | 709 | protected function parseAttributes($str, $offset) |
710 | 710 | { |
711 | - if($str === '') |
|
711 | + if ($str === '') |
|
712 | 712 | return []; |
713 | 713 | $pattern = '/([\w\.\-]+)\s*=\s*(\'.*?\'|".*?"|<%.*?%>)/msS'; |
714 | 714 | $attributes = []; |
715 | 715 | $n = preg_match_all($pattern, $str, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); |
716 | - for($i = 0;$i < $n;++$i) |
|
716 | + for ($i = 0; $i < $n; ++$i) |
|
717 | 717 | { |
718 | 718 | $match = &$matches[$i]; |
719 | 719 | $name = strtolower($match[1][0]); |
720 | - if(isset($attributes[$name])) |
|
720 | + if (isset($attributes[$name])) |
|
721 | 721 | throw new TConfigurationException('template_property_duplicated', $name); |
722 | 722 | $value = $match[2][0]; |
723 | - if(substr($name, -8, 8) === 'template') |
|
723 | + if (substr($name, -8, 8) === 'template') |
|
724 | 724 | { |
725 | - if($value[0] === '\'' || $value[0] === '"') |
|
725 | + if ($value[0] === '\'' || $value[0] === '"') |
|
726 | 726 | $attributes[$name] = $this->parseTemplateProperty(substr($value, 1, strlen($value) - 2), $match[2][1] + 1); |
727 | 727 | else |
728 | 728 | $attributes[$name] = $this->parseTemplateProperty($value, $match[2][1]); |
729 | 729 | } |
730 | 730 | else |
731 | 731 | { |
732 | - if($value[0] === '\'' || $value[0] === '"') |
|
732 | + if ($value[0] === '\'' || $value[0] === '"') |
|
733 | 733 | $attributes[$name] = $this->parseAttribute(substr($value, 1, strlen($value) - 2)); |
734 | 734 | else |
735 | 735 | $attributes[$name] = $this->parseAttribute($value); |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | protected function parseTemplateProperty($content, $offset) |
742 | 742 | { |
743 | 743 | $line = $this->_startingLine + count(explode("\n", substr($this->_content, 0, $offset))) - 1; |
744 | - return [self::CONFIG_TEMPLATE,new TTemplate($content, $this->_contextPath, $this->_tplFile, $line, false)]; |
|
744 | + return [self::CONFIG_TEMPLATE, new TTemplate($content, $this->_contextPath, $this->_tplFile, $line, false)]; |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
@@ -751,44 +751,44 @@ discard block |
||
751 | 751 | */ |
752 | 752 | protected function parseAttribute($value) |
753 | 753 | { |
754 | - if(($n = preg_match_all('/<%[#=].*?%>/msS', $value, $matches, PREG_OFFSET_CAPTURE)) > 0) |
|
754 | + if (($n = preg_match_all('/<%[#=].*?%>/msS', $value, $matches, PREG_OFFSET_CAPTURE)) > 0) |
|
755 | 755 | { |
756 | 756 | $isDataBind = false; |
757 | 757 | $textStart = 0; |
758 | 758 | $expr = ''; |
759 | - for($i = 0;$i < $n;++$i) |
|
759 | + for ($i = 0; $i < $n; ++$i) |
|
760 | 760 | { |
761 | 761 | $match = $matches[0][$i]; |
762 | 762 | $token = $match[0]; |
763 | 763 | $offset = $match[1]; |
764 | 764 | $length = strlen($token); |
765 | - if($token[2] === '#') |
|
765 | + if ($token[2] === '#') |
|
766 | 766 | $isDataBind = true; |
767 | - if($offset > $textStart) |
|
768 | - $expr .= ".'" . strtr(substr($value, $textStart, $offset - $textStart), ["'" => "\\'","\\" => "\\\\"]) . "'"; |
|
769 | - $expr .= '.(' . substr($token, 3, $length - 5) . ')'; |
|
767 | + if ($offset > $textStart) |
|
768 | + $expr .= ".'".strtr(substr($value, $textStart, $offset - $textStart), ["'" => "\\'", "\\" => "\\\\"])."'"; |
|
769 | + $expr .= '.('.substr($token, 3, $length - 5).')'; |
|
770 | 770 | $textStart = $offset + $length; |
771 | 771 | } |
772 | 772 | $length = strlen($value); |
773 | - if($length > $textStart) |
|
774 | - $expr .= ".'" . strtr(substr($value, $textStart, $length - $textStart), ["'" => "\\'","\\" => "\\\\"]) . "'"; |
|
775 | - if($isDataBind) |
|
776 | - return [self::CONFIG_DATABIND,ltrim($expr, '.')]; |
|
773 | + if ($length > $textStart) |
|
774 | + $expr .= ".'".strtr(substr($value, $textStart, $length - $textStart), ["'" => "\\'", "\\" => "\\\\"])."'"; |
|
775 | + if ($isDataBind) |
|
776 | + return [self::CONFIG_DATABIND, ltrim($expr, '.')]; |
|
777 | 777 | else |
778 | - return [self::CONFIG_EXPRESSION,ltrim($expr, '.')]; |
|
778 | + return [self::CONFIG_EXPRESSION, ltrim($expr, '.')]; |
|
779 | 779 | } |
780 | - elseif(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS', $value, $matches) && $matches[0] === $value) |
|
780 | + elseif (preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS', $value, $matches) && $matches[0] === $value) |
|
781 | 781 | { |
782 | 782 | $value = $matches[1]; |
783 | - if($value[2] === '~') |
|
784 | - return [self::CONFIG_ASSET,trim(substr($value, 3, strlen($value) - 5))]; |
|
785 | - elseif($value[2] === '[') |
|
786 | - return [self::CONFIG_LOCALIZATION,trim(substr($value, 3, strlen($value) - 6))]; |
|
787 | - elseif($value[2] === '$') |
|
788 | - return [self::CONFIG_PARAMETER,trim(substr($value, 3, strlen($value) - 5))]; |
|
789 | - elseif($value[2] === '/') { |
|
783 | + if ($value[2] === '~') |
|
784 | + return [self::CONFIG_ASSET, trim(substr($value, 3, strlen($value) - 5))]; |
|
785 | + elseif ($value[2] === '[') |
|
786 | + return [self::CONFIG_LOCALIZATION, trim(substr($value, 3, strlen($value) - 6))]; |
|
787 | + elseif ($value[2] === '$') |
|
788 | + return [self::CONFIG_PARAMETER, trim(substr($value, 3, strlen($value) - 5))]; |
|
789 | + elseif ($value[2] === '/') { |
|
790 | 790 | $literal = trim(substr($value, 3, strlen($value) - 5)); |
791 | - return [self::CONFIG_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]; |
|
791 | + return [self::CONFIG_EXPRESSION, "rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]; |
|
792 | 792 | } |
793 | 793 | } |
794 | 794 | else |
@@ -798,71 +798,71 @@ discard block |
||
798 | 798 | protected function validateAttributes($type, $attributes) |
799 | 799 | { |
800 | 800 | Prado::using($type); |
801 | - if(($pos = strrpos($type, '.')) !== false) |
|
801 | + if (($pos = strrpos($type, '.')) !== false) |
|
802 | 802 | $className = substr($type, $pos + 1); |
803 | 803 | else |
804 | 804 | $className = $type; |
805 | 805 | $class = new \ReflectionClass($className); |
806 | - if(is_subclass_of($className, '\Prado\Web\UI\TControl') || $className === '\Prado\Web\UI\TControl') |
|
806 | + if (is_subclass_of($className, '\Prado\Web\UI\TControl') || $className === '\Prado\Web\UI\TControl') |
|
807 | 807 | { |
808 | - foreach($attributes as $name => $att) |
|
808 | + foreach ($attributes as $name => $att) |
|
809 | 809 | { |
810 | - if(($pos = strpos($name, '.')) !== false) |
|
810 | + if (($pos = strpos($name, '.')) !== false) |
|
811 | 811 | { |
812 | 812 | // a subproperty, so the first segment must be readable |
813 | 813 | $subname = substr($name, 0, $pos); |
814 | - if(!$class->hasMethod('get' . $subname)) |
|
814 | + if (!$class->hasMethod('get'.$subname)) |
|
815 | 815 | throw new TConfigurationException('template_property_unknown', $type, $subname); |
816 | 816 | } |
817 | - elseif(strncasecmp($name, 'on', 2) === 0) |
|
817 | + elseif (strncasecmp($name, 'on', 2) === 0) |
|
818 | 818 | { |
819 | 819 | // an event |
820 | - if(!$class->hasMethod($name)) |
|
820 | + if (!$class->hasMethod($name)) |
|
821 | 821 | throw new TConfigurationException('template_event_unknown', $type, $name); |
822 | - elseif(!is_string($att)) |
|
822 | + elseif (!is_string($att)) |
|
823 | 823 | throw new TConfigurationException('template_eventhandler_invalid', $type, $name); |
824 | 824 | } |
825 | 825 | else |
826 | 826 | { |
827 | 827 | // a simple property |
828 | - if (! ($class->hasMethod('set' . $name) || $class->hasMethod('setjs' . $name) || $this->isClassBehaviorMethod($class, 'set' . $name))) |
|
828 | + if (!($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name) || $this->isClassBehaviorMethod($class, 'set'.$name))) |
|
829 | 829 | { |
830 | - if ($class->hasMethod('get' . $name) || $class->hasMethod('getjs' . $name)) |
|
830 | + if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name)) |
|
831 | 831 | throw new TConfigurationException('template_property_readonly', $type, $name); |
832 | 832 | else |
833 | 833 | throw new TConfigurationException('template_property_unknown', $type, $name); |
834 | 834 | } |
835 | - elseif(is_array($att) && $att[0] !== self::CONFIG_EXPRESSION) |
|
835 | + elseif (is_array($att) && $att[0] !== self::CONFIG_EXPRESSION) |
|
836 | 836 | { |
837 | - if(strcasecmp($name, 'id') === 0) |
|
837 | + if (strcasecmp($name, 'id') === 0) |
|
838 | 838 | throw new TConfigurationException('template_controlid_invalid', $type); |
839 | - elseif(strcasecmp($name, 'skinid') === 0) |
|
839 | + elseif (strcasecmp($name, 'skinid') === 0) |
|
840 | 840 | throw new TConfigurationException('template_controlskinid_invalid', $type); |
841 | 841 | } |
842 | 842 | } |
843 | 843 | } |
844 | 844 | } |
845 | - elseif(is_subclass_of($className, '\Prado\TComponent') || $className === '\Prado\TComponent') |
|
845 | + elseif (is_subclass_of($className, '\Prado\TComponent') || $className === '\Prado\TComponent') |
|
846 | 846 | { |
847 | - foreach($attributes as $name => $att) |
|
847 | + foreach ($attributes as $name => $att) |
|
848 | 848 | { |
849 | - if(is_array($att) && ($att[0] === self::CONFIG_DATABIND)) |
|
849 | + if (is_array($att) && ($att[0] === self::CONFIG_DATABIND)) |
|
850 | 850 | throw new TConfigurationException('template_databind_forbidden', $type, $name); |
851 | - if(($pos = strpos($name, '.')) !== false) |
|
851 | + if (($pos = strpos($name, '.')) !== false) |
|
852 | 852 | { |
853 | 853 | // a subproperty, so the first segment must be readable |
854 | 854 | $subname = substr($name, 0, $pos); |
855 | - if(!$class->hasMethod('get' . $subname)) |
|
855 | + if (!$class->hasMethod('get'.$subname)) |
|
856 | 856 | throw new TConfigurationException('template_property_unknown', $type, $subname); |
857 | 857 | } |
858 | - elseif(strncasecmp($name, 'on', 2) === 0) |
|
858 | + elseif (strncasecmp($name, 'on', 2) === 0) |
|
859 | 859 | throw new TConfigurationException('template_event_forbidden', $type, $name); |
860 | 860 | else |
861 | 861 | { |
862 | 862 | // id is still alowed for TComponent, even if id property doesn't exist |
863 | - if(strcasecmp($name, 'id') !== 0 && !($class->hasMethod('set' . $name) || $this->isClassBehaviorMethod($class, 'set' . $name))) |
|
863 | + if (strcasecmp($name, 'id') !== 0 && !($class->hasMethod('set'.$name) || $this->isClassBehaviorMethod($class, 'set'.$name))) |
|
864 | 864 | { |
865 | - if($class->hasMethod('get' . $name)) |
|
865 | + if ($class->hasMethod('get'.$name)) |
|
866 | 866 | throw new TConfigurationException('template_property_readonly', $type, $name); |
867 | 867 | else |
868 | 868 | throw new TConfigurationException('template_property_unknown', $type, $name); |
@@ -895,13 +895,13 @@ discard block |
||
895 | 895 | { |
896 | 896 | $srcFile = $this->_tplFile; |
897 | 897 | |
898 | - if(($n = count($this->_includedFiles)) > 0) // need to adjust error row number and file name |
|
898 | + if (($n = count($this->_includedFiles)) > 0) // need to adjust error row number and file name |
|
899 | 899 | { |
900 | - for($i = $n - 1;$i >= 0;--$i) |
|
900 | + for ($i = $n - 1; $i >= 0; --$i) |
|
901 | 901 | { |
902 | - if($this->_includeAtLine[$i] <= $line) |
|
902 | + if ($this->_includeAtLine[$i] <= $line) |
|
903 | 903 | { |
904 | - if($line < $this->_includeAtLine[$i] + $this->_includeLines[$i]) |
|
904 | + if ($line < $this->_includeAtLine[$i] + $this->_includeLines[$i]) |
|
905 | 905 | { |
906 | 906 | $line = $line - $this->_includeAtLine[$i] + 1; |
907 | 907 | $srcFile = $this->_includedFiles[$i]; |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | } |
915 | 915 | $exception = new TTemplateException('template_format_invalid', $e->getMessage()); |
916 | 916 | $exception->setLineNumber($line); |
917 | - if(!empty($srcFile)) |
|
917 | + if (!empty($srcFile)) |
|
918 | 918 | $exception->setTemplateFile($srcFile); |
919 | 919 | else |
920 | 920 | $exception->setTemplateSource($input); |
@@ -928,12 +928,12 @@ discard block |
||
928 | 928 | */ |
929 | 929 | protected function preprocess($input) |
930 | 930 | { |
931 | - if($n = preg_match_all('/<%include(.*?)%>/', $input, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) |
|
931 | + if ($n = preg_match_all('/<%include(.*?)%>/', $input, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) |
|
932 | 932 | { |
933 | - for($i = 0;$i < $n;++$i) |
|
933 | + for ($i = 0; $i < $n; ++$i) |
|
934 | 934 | { |
935 | 935 | $filePath = Prado::getPathOfNamespace(trim($matches[$i][1][0]), TTemplateManager::TEMPLATE_FILE_EXT); |
936 | - if($filePath !== null && is_file($filePath)) |
|
936 | + if ($filePath !== null && is_file($filePath)) |
|
937 | 937 | $this->_includedFiles[] = $filePath; |
938 | 938 | else |
939 | 939 | { |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | } |
943 | 943 | } |
944 | 944 | $base = 0; |
945 | - for($i = 0;$i < $n;++$i) |
|
945 | + for ($i = 0; $i < $n; ++$i) |
|
946 | 946 | { |
947 | 947 | $ext = file_get_contents($this->_includedFiles[$i]); |
948 | 948 | $length = strlen($matches[$i][0][0]); |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | { |
968 | 968 | $component = new \ReflectionClass('\Prado\TComponent'); |
969 | 969 | $behaviors = $component->getStaticProperties(); |
970 | - if(!isset($behaviors['_um'])) |
|
970 | + if (!isset($behaviors['_um'])) |
|
971 | 971 | return false; |
972 | - foreach($behaviors['_um'] as $name => $list) |
|
972 | + foreach ($behaviors['_um'] as $name => $list) |
|
973 | 973 | { |
974 | - if(strtolower($class->getShortName()) !== $name && !$class->isSubclassOf($name)) continue; |
|
975 | - foreach($list as $param) |
|
974 | + if (strtolower($class->getShortName()) !== $name && !$class->isSubclassOf($name)) continue; |
|
975 | + foreach ($list as $param) |
|
976 | 976 | { |
977 | - if(method_exists($param->getBehavior(), $method)) |
|
977 | + if (method_exists($param->getBehavior(), $method)) |
|
978 | 978 | return true; |
979 | 979 | } |
980 | 980 | } |
@@ -192,96 +192,110 @@ discard block |
||
192 | 192 | public function instantiateIn($tplControl, $parentControl = null) |
193 | 193 | { |
194 | 194 | $this->_tplControl = $tplControl; |
195 | - if($parentControl === null) |
|
196 | - $parentControl = $tplControl; |
|
197 | - if(($page = $tplControl->getPage()) === null) |
|
198 | - $page = $this->getService()->getRequestedPage(); |
|
195 | + if($parentControl === null) { |
|
196 | + $parentControl = $tplControl; |
|
197 | + } |
|
198 | + if(($page = $tplControl->getPage()) === null) { |
|
199 | + $page = $this->getService()->getRequestedPage(); |
|
200 | + } |
|
199 | 201 | $controls = []; |
200 | 202 | $directChildren = []; |
201 | 203 | foreach($this->_tpl as $key => $object) |
202 | 204 | { |
203 | - if($object[0] === -1) |
|
204 | - $parent = $parentControl; |
|
205 | - elseif(isset($controls[$object[0]])) |
|
206 | - $parent = $controls[$object[0]]; |
|
207 | - else |
|
208 | - continue; |
|
209 | - if(isset($object[2])) // component |
|
205 | + if($object[0] === -1) { |
|
206 | + $parent = $parentControl; |
|
207 | + } elseif(isset($controls[$object[0]])) { |
|
208 | + $parent = $controls[$object[0]]; |
|
209 | + } else { |
|
210 | + continue; |
|
211 | + } |
|
212 | + if(isset($object[2])) { |
|
213 | + // component |
|
210 | 214 | { |
211 | 215 | $component = Prado::createComponent($object[1]); |
216 | + } |
|
212 | 217 | $properties = &$object[2]; |
213 | 218 | if($component instanceof TControl) |
214 | 219 | { |
215 | - if($component instanceof \Prado\Web\UI\WebControls\TOutputCache) |
|
216 | - $component->setCacheKeyPrefix($this->_hashCode . $key); |
|
220 | + if($component instanceof \Prado\Web\UI\WebControls\TOutputCache) { |
|
221 | + $component->setCacheKeyPrefix($this->_hashCode . $key); |
|
222 | + } |
|
217 | 223 | $component->setTemplateControl($tplControl); |
218 | 224 | if(isset($properties['id'])) |
219 | 225 | { |
220 | - if(is_array($properties['id'])) |
|
221 | - $properties['id'] = $component->evaluateExpression($properties['id'][1]); |
|
226 | + if(is_array($properties['id'])) { |
|
227 | + $properties['id'] = $component->evaluateExpression($properties['id'][1]); |
|
228 | + } |
|
222 | 229 | $tplControl->registerObject($properties['id'], $component); |
223 | 230 | } |
224 | 231 | if(isset($properties['skinid'])) |
225 | 232 | { |
226 | - if(is_array($properties['skinid'])) |
|
227 | - $component->setSkinID($component->evaluateExpression($properties['skinid'][1])); |
|
228 | - else |
|
229 | - $component->setSkinID($properties['skinid']); |
|
233 | + if(is_array($properties['skinid'])) { |
|
234 | + $component->setSkinID($component->evaluateExpression($properties['skinid'][1])); |
|
235 | + } else { |
|
236 | + $component->setSkinID($properties['skinid']); |
|
237 | + } |
|
230 | 238 | unset($properties['skinid']); |
231 | 239 | } |
232 | 240 | |
233 | 241 | $component->trackViewState(false); |
234 | 242 | |
235 | 243 | $component->applyStyleSheetSkin($page); |
236 | - foreach($properties as $name => $value) |
|
237 | - $this->configureControl($component, $name, $value); |
|
244 | + foreach($properties as $name => $value) { |
|
245 | + $this->configureControl($component, $name, $value); |
|
246 | + } |
|
238 | 247 | |
239 | 248 | $component->trackViewState(true); |
240 | 249 | |
241 | - if($parent === $parentControl) |
|
242 | - $directChildren[] = $component; |
|
243 | - else |
|
244 | - $component->createdOnTemplate($parent); |
|
245 | - if($component->getAllowChildControls()) |
|
246 | - $controls[$key] = $component; |
|
247 | - } |
|
248 | - elseif($component instanceof TComponent) |
|
250 | + if($parent === $parentControl) { |
|
251 | + $directChildren[] = $component; |
|
252 | + } else { |
|
253 | + $component->createdOnTemplate($parent); |
|
254 | + } |
|
255 | + if($component->getAllowChildControls()) { |
|
256 | + $controls[$key] = $component; |
|
257 | + } |
|
258 | + } elseif($component instanceof TComponent) |
|
249 | 259 | { |
250 | 260 | $controls[$key] = $component; |
251 | 261 | if(isset($properties['id'])) |
252 | 262 | { |
253 | - if(is_array($properties['id'])) |
|
254 | - $properties['id'] = $component->evaluateExpression($properties['id'][1]); |
|
263 | + if(is_array($properties['id'])) { |
|
264 | + $properties['id'] = $component->evaluateExpression($properties['id'][1]); |
|
265 | + } |
|
255 | 266 | $tplControl->registerObject($properties['id'], $component); |
256 | - if(!$component->hasProperty('id')) |
|
257 | - unset($properties['id']); |
|
258 | - } |
|
259 | - foreach($properties as $name => $value) |
|
260 | - $this->configureComponent($component, $name, $value); |
|
261 | - if($parent === $parentControl) |
|
262 | - $directChildren[] = $component; |
|
263 | - else |
|
264 | - $component->createdOnTemplate($parent); |
|
267 | + if(!$component->hasProperty('id')) { |
|
268 | + unset($properties['id']); |
|
269 | + } |
|
270 | + } |
|
271 | + foreach($properties as $name => $value) { |
|
272 | + $this->configureComponent($component, $name, $value); |
|
273 | + } |
|
274 | + if($parent === $parentControl) { |
|
275 | + $directChildren[] = $component; |
|
276 | + } else { |
|
277 | + $component->createdOnTemplate($parent); |
|
278 | + } |
|
265 | 279 | } |
266 | - } |
|
267 | - else |
|
280 | + } else |
|
268 | 281 | { |
269 | 282 | if($object[1] instanceof TCompositeLiteral) |
270 | 283 | { |
271 | 284 | // need to clone a new object because the one in template is reused |
272 | 285 | $o = clone $object[1]; |
273 | 286 | $o->setContainer($tplControl); |
274 | - if($parent === $parentControl) |
|
275 | - $directChildren[] = $o; |
|
276 | - else |
|
277 | - $parent->addParsedObject($o); |
|
278 | - } |
|
279 | - else |
|
287 | + if($parent === $parentControl) { |
|
288 | + $directChildren[] = $o; |
|
289 | + } else { |
|
290 | + $parent->addParsedObject($o); |
|
291 | + } |
|
292 | + } else |
|
280 | 293 | { |
281 | - if($parent === $parentControl) |
|
282 | - $directChildren[] = $object[1]; |
|
283 | - else |
|
284 | - $parent->addParsedObject($object[1]); |
|
294 | + if($parent === $parentControl) { |
|
295 | + $directChildren[] = $object[1]; |
|
296 | + } else { |
|
297 | + $parent->addParsedObject($object[1]); |
|
298 | + } |
|
285 | 299 | } |
286 | 300 | } |
287 | 301 | } |
@@ -290,10 +304,11 @@ discard block |
||
290 | 304 | // if the child needs its own child controls. |
291 | 305 | foreach($directChildren as $control) |
292 | 306 | { |
293 | - if($control instanceof TComponent) |
|
294 | - $control->createdOnTemplate($parentControl); |
|
295 | - else |
|
296 | - $parentControl->addParsedObject($control); |
|
307 | + if($control instanceof TComponent) { |
|
308 | + $control->createdOnTemplate($parentControl); |
|
309 | + } else { |
|
310 | + $parentControl->addParsedObject($control); |
|
311 | + } |
|
297 | 312 | } |
298 | 313 | } |
299 | 314 | |
@@ -305,12 +320,16 @@ discard block |
||
305 | 320 | */ |
306 | 321 | protected function configureControl($control, $name, $value) |
307 | 322 | { |
308 | - if(strncasecmp($name, 'on', 2) === 0) // is an event |
|
323 | + if(strncasecmp($name, 'on', 2) === 0) { |
|
324 | + // is an event |
|
309 | 325 | $this->configureEvent($control, $name, $value, $control); |
310 | - elseif(($pos = strrpos($name, '.')) === false) // is a simple property or custom attribute |
|
326 | + } elseif(($pos = strrpos($name, '.')) === false) { |
|
327 | + // is a simple property or custom attribute |
|
311 | 328 | $this->configureProperty($control, $name, $value); |
312 | - else // is a subproperty |
|
329 | + } else { |
|
330 | + // is a subproperty |
|
313 | 331 | $this->configureSubProperty($control, $name, $value); |
332 | + } |
|
314 | 333 | } |
315 | 334 | |
316 | 335 | /** |
@@ -321,10 +340,13 @@ discard block |
||
321 | 340 | */ |
322 | 341 | protected function configureComponent($component, $name, $value) |
323 | 342 | { |
324 | - if(strpos($name, '.') === false) // is a simple property or custom attribute |
|
343 | + if(strpos($name, '.') === false) { |
|
344 | + // is a simple property or custom attribute |
|
325 | 345 | $this->configureProperty($component, $name, $value); |
326 | - else // is a subproperty |
|
346 | + } else { |
|
347 | + // is a subproperty |
|
327 | 348 | $this->configureSubProperty($component, $name, $value); |
349 | + } |
|
328 | 350 | } |
329 | 351 | |
330 | 352 | /** |
@@ -336,10 +358,11 @@ discard block |
||
336 | 358 | */ |
337 | 359 | protected function configureEvent($control, $name, $value, $contextControl) |
338 | 360 | { |
339 | - if(strpos($value, '.') === false) |
|
340 | - $control->attachEventHandler($name, [$contextControl,'TemplateControl.' . $value]); |
|
341 | - else |
|
342 | - $control->attachEventHandler($name, [$contextControl,$value]); |
|
361 | + if(strpos($value, '.') === false) { |
|
362 | + $control->attachEventHandler($name, [$contextControl,'TemplateControl.' . $value]); |
|
363 | + } else { |
|
364 | + $control->attachEventHandler($name, [$contextControl,$value]); |
|
365 | + } |
|
343 | 366 | } |
344 | 367 | |
345 | 368 | /** |
@@ -358,9 +381,9 @@ discard block |
||
358 | 381 | $component->bindProperty($name, $value[1]); |
359 | 382 | break; |
360 | 383 | case self::CONFIG_EXPRESSION: |
361 | - if($component instanceof TControl) |
|
362 | - $component->autoBindProperty($name, $value[1]); |
|
363 | - else |
|
384 | + if($component instanceof TControl) { |
|
385 | + $component->autoBindProperty($name, $value[1]); |
|
386 | + } else |
|
364 | 387 | { |
365 | 388 | $setter = 'set' . $name; |
366 | 389 | $component->$setter($this->_tplControl->evaluateExpression($value[1])); |
@@ -387,12 +410,12 @@ discard block |
||
387 | 410 | throw new TConfigurationException('template_tag_unexpected', $name, $value[1]); |
388 | 411 | break; |
389 | 412 | } |
390 | - } |
|
391 | - else |
|
413 | + } else |
|
392 | 414 | { |
393 | - if (substr($name, 0, 2) == 'js') |
|
394 | - if ($value and !($value instanceof TJavaScriptLiteral)) |
|
415 | + if (substr($name, 0, 2) == 'js') { |
|
416 | + if ($value and !($value instanceof TJavaScriptLiteral)) |
|
395 | 417 | $value = new TJavaScriptLiteral($value); |
418 | + } |
|
396 | 419 | $setter = 'set' . $name; |
397 | 420 | $component->$setter($value); |
398 | 421 | } |
@@ -414,10 +437,11 @@ discard block |
||
414 | 437 | $component->bindProperty($name, $value[1]); |
415 | 438 | break; |
416 | 439 | case self::CONFIG_EXPRESSION: // expression |
417 | - if($component instanceof TControl) |
|
418 | - $component->autoBindProperty($name, $value[1]); |
|
419 | - else |
|
420 | - $component->setSubProperty($name, $this->_tplControl->evaluateExpression($value[1])); |
|
440 | + if($component instanceof TControl) { |
|
441 | + $component->autoBindProperty($name, $value[1]); |
|
442 | + } else { |
|
443 | + $component->setSubProperty($name, $this->_tplControl->evaluateExpression($value[1])); |
|
444 | + } |
|
421 | 445 | break; |
422 | 446 | case self::CONFIG_TEMPLATE: |
423 | 447 | $component->setSubProperty($name, $value[1]); |
@@ -436,9 +460,9 @@ discard block |
||
436 | 460 | throw new TConfigurationException('template_tag_unexpected', $name, $value[1]); |
437 | 461 | break; |
438 | 462 | } |
463 | + } else { |
|
464 | + $component->setSubProperty($name, $value); |
|
439 | 465 | } |
440 | - else |
|
441 | - $component->setSubProperty($name, $value); |
|
442 | 466 | } |
443 | 467 | |
444 | 468 | /** |
@@ -482,34 +506,42 @@ discard block |
||
482 | 506 | $str = $match[0][0]; |
483 | 507 | $matchStart = $match[0][1]; |
484 | 508 | $matchEnd = $matchStart + strlen($str) - 1; |
485 | - if(strpos($str, '<com:') === 0) // opening component tag |
|
509 | + if(strpos($str, '<com:') === 0) { |
|
510 | + // opening component tag |
|
486 | 511 | { |
487 | 512 | if($expectPropEnd) |
488 | 513 | continue; |
489 | - if($matchStart > $textStart) |
|
490 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
514 | + } |
|
515 | + if($matchStart > $textStart) { |
|
516 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
517 | + } |
|
491 | 518 | $textStart = $matchEnd + 1; |
492 | 519 | $type = $match[1][0]; |
493 | 520 | $attributes = $this->parseAttributes($match[2][0], $match[2][1]); |
494 | 521 | $class = $this->validateAttributes($type, $attributes); |
495 | 522 | $tpl[$c++] = [$container,$class,$attributes]; |
496 | - if($str[strlen($str) - 2] !== '/') // open tag |
|
523 | + if($str[strlen($str) - 2] !== '/') { |
|
524 | + // open tag |
|
497 | 525 | { |
498 | 526 | $stack[] = $type; |
527 | + } |
|
499 | 528 | $container = $c - 1; |
500 | 529 | } |
501 | - } |
|
502 | - elseif(strpos($str, '</com:') === 0) // closing component tag |
|
530 | + } elseif(strpos($str, '</com:') === 0) { |
|
531 | + // closing component tag |
|
503 | 532 | { |
504 | 533 | if($expectPropEnd) |
505 | 534 | continue; |
506 | - if($matchStart > $textStart) |
|
507 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
535 | + } |
|
536 | + if($matchStart > $textStart) { |
|
537 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
538 | + } |
|
508 | 539 | $textStart = $matchEnd + 1; |
509 | 540 | $type = $match[1][0]; |
510 | 541 | |
511 | - if(empty($stack)) |
|
512 | - throw new TConfigurationException('template_closingtag_unexpected', "</com:$type>"); |
|
542 | + if(empty($stack)) { |
|
543 | + throw new TConfigurationException('template_closingtag_unexpected', "</com:$type>"); |
|
544 | + } |
|
513 | 545 | |
514 | 546 | $name = array_pop($stack); |
515 | 547 | if($name !== $type) |
@@ -518,85 +550,98 @@ discard block |
||
518 | 550 | throw new TConfigurationException('template_closingtag_expected', $tag, "</com:$type>"); |
519 | 551 | } |
520 | 552 | $container = $tpl[$container][0]; |
521 | - } |
|
522 | - elseif(strpos($str, '<%@') === 0) // directive |
|
553 | + } elseif(strpos($str, '<%@') === 0) { |
|
554 | + // directive |
|
523 | 555 | { |
524 | 556 | if($expectPropEnd) |
525 | 557 | continue; |
526 | - if($matchStart > $textStart) |
|
527 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
558 | + } |
|
559 | + if($matchStart > $textStart) { |
|
560 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
561 | + } |
|
528 | 562 | $textStart = $matchEnd + 1; |
529 | - if(isset($tpl[0]) || $this->_directive !== null) |
|
530 | - throw new TConfigurationException('template_directive_nonunique'); |
|
563 | + if(isset($tpl[0]) || $this->_directive !== null) { |
|
564 | + throw new TConfigurationException('template_directive_nonunique'); |
|
565 | + } |
|
531 | 566 | $this->_directive = $this->parseAttributes($match[4][0], $match[4][1]); |
532 | - } |
|
533 | - elseif(strpos($str, '<%') === 0) // expression |
|
567 | + } elseif(strpos($str, '<%') === 0) { |
|
568 | + // expression |
|
534 | 569 | { |
535 | 570 | if($expectPropEnd) |
536 | 571 | continue; |
537 | - if($matchStart > $textStart) |
|
538 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
572 | + } |
|
573 | + if($matchStart > $textStart) { |
|
574 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
575 | + } |
|
539 | 576 | $textStart = $matchEnd + 1; |
540 | 577 | $literal = trim($match[5][0]); |
541 | - if($str[2] === '=') // expression |
|
578 | + if($str[2] === '=') { |
|
579 | + // expression |
|
542 | 580 | $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,$literal]]; |
543 | - elseif($str[2] === '%') // statements |
|
581 | + } elseif($str[2] === '%') { |
|
582 | + // statements |
|
544 | 583 | $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_STATEMENTS,$literal]]; |
545 | - elseif($str[2] === '#') |
|
546 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_DATABINDING,$literal]]; |
|
547 | - elseif($str[2] === '$') |
|
548 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"]]; |
|
549 | - elseif($str[2] === '~') |
|
550 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"]]; |
|
551 | - elseif($str[2] === '/') |
|
552 | - $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]]; |
|
553 | - elseif($str[2] === '[') |
|
584 | + } elseif($str[2] === '#') { |
|
585 | + $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_DATABINDING,$literal]]; |
|
586 | + } elseif($str[2] === '$') { |
|
587 | + $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"\$this->getApplication()->getParameters()->itemAt('$literal')"]]; |
|
588 | + } elseif($str[2] === '~') { |
|
589 | + $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"\$this->publishFilePath('$this->_contextPath/$literal')"]]; |
|
590 | + } elseif($str[2] === '/') { |
|
591 | + $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]]; |
|
592 | + } elseif($str[2] === '[') |
|
554 | 593 | { |
555 | 594 | $literal = strtr(trim(substr($literal, 0, strlen($literal) - 1)), ["'" => "\'","\\" => "\\\\"]); |
556 | 595 | $tpl[$c++] = [$container,[TCompositeLiteral::TYPE_EXPRESSION,"Prado::localize('$literal')"]]; |
557 | 596 | } |
558 | - } |
|
559 | - elseif(strpos($str, '<prop:') === 0) // opening property |
|
597 | + } elseif(strpos($str, '<prop:') === 0) { |
|
598 | + // opening property |
|
560 | 599 | { |
561 | 600 | if(strrpos($str, '/>') === strlen($str) - 2) //subproperties |
562 | 601 | { |
563 | 602 | if($expectPropEnd) |
564 | 603 | continue; |
565 | - if($matchStart > $textStart) |
|
566 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
604 | + } |
|
605 | + if($matchStart > $textStart) { |
|
606 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
607 | + } |
|
567 | 608 | $textStart = $matchEnd + 1; |
568 | 609 | $prop = strtolower($match[6][0]); |
569 | 610 | $attrs = $this->parseAttributes($match[7][0], $match[7][1]); |
570 | 611 | $attributes = []; |
571 | - foreach($attrs as $name => $value) |
|
572 | - $attributes[$prop . '.' . $name] = $value; |
|
612 | + foreach($attrs as $name => $value) { |
|
613 | + $attributes[$prop . '.' . $name] = $value; |
|
614 | + } |
|
573 | 615 | $type = $tpl[$container][1]; |
574 | 616 | $this->validateAttributes($type, $attributes); |
575 | 617 | foreach($attributes as $name => $value) |
576 | 618 | { |
577 | - if(isset($tpl[$container][2][$name])) |
|
578 | - throw new TConfigurationException('template_property_duplicated', $name); |
|
619 | + if(isset($tpl[$container][2][$name])) { |
|
620 | + throw new TConfigurationException('template_property_duplicated', $name); |
|
621 | + } |
|
579 | 622 | $tpl[$container][2][$name] = $value; |
580 | 623 | } |
581 | - } |
|
582 | - else // regular property |
|
624 | + } else // regular property |
|
583 | 625 | { |
584 | 626 | $prop = strtolower($match[3][0]); |
585 | 627 | $stack[] = '@' . $prop; |
586 | 628 | if(!$expectPropEnd) |
587 | 629 | { |
588 | - if($matchStart > $textStart) |
|
589 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
630 | + if($matchStart > $textStart) { |
|
631 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
632 | + } |
|
590 | 633 | $textStart = $matchEnd + 1; |
591 | 634 | $expectPropEnd = true; |
592 | 635 | } |
593 | 636 | } |
594 | - } |
|
595 | - elseif(strpos($str, '</prop:') === 0) // closing property |
|
637 | + } elseif(strpos($str, '</prop:') === 0) { |
|
638 | + // closing property |
|
596 | 639 | { |
597 | 640 | $prop = strtolower($match[3][0]); |
598 | - if(empty($stack)) |
|
599 | - throw new TConfigurationException('template_closingtag_unexpected', "</prop:$prop>"); |
|
641 | + } |
|
642 | + if(empty($stack)) { |
|
643 | + throw new TConfigurationException('template_closingtag_unexpected', "</prop:$prop>"); |
|
644 | + } |
|
600 | 645 | $name = array_pop($stack); |
601 | 646 | if($name !== '@' . $prop) |
602 | 647 | { |
@@ -608,35 +653,40 @@ discard block |
||
608 | 653 | if($matchStart > $textStart) |
609 | 654 | { |
610 | 655 | $value = substr($input, $textStart, $matchStart - $textStart); |
611 | - if(substr($prop, -8, 8) === 'template') |
|
612 | - $value = $this->parseTemplateProperty($value, $textStart); |
|
613 | - else |
|
614 | - $value = $this->parseAttribute($value); |
|
656 | + if(substr($prop, -8, 8) === 'template') { |
|
657 | + $value = $this->parseTemplateProperty($value, $textStart); |
|
658 | + } else { |
|
659 | + $value = $this->parseAttribute($value); |
|
660 | + } |
|
615 | 661 | if($container >= 0) |
616 | 662 | { |
617 | 663 | $type = $tpl[$container][1]; |
618 | 664 | $this->validateAttributes($type, [$prop => $value]); |
619 | - if(isset($tpl[$container][2][$prop])) |
|
620 | - throw new TConfigurationException('template_property_duplicated', $prop); |
|
665 | + if(isset($tpl[$container][2][$prop])) { |
|
666 | + throw new TConfigurationException('template_property_duplicated', $prop); |
|
667 | + } |
|
621 | 668 | $tpl[$container][2][$prop] = $value; |
622 | - } |
|
623 | - else // a property for the template control |
|
669 | + } else { |
|
670 | + // a property for the template control |
|
624 | 671 | $this->_directive[$prop] = $value; |
672 | + } |
|
625 | 673 | $textStart = $matchEnd + 1; |
626 | 674 | } |
627 | 675 | $expectPropEnd = false; |
628 | 676 | } |
629 | - } |
|
630 | - elseif(strpos($str, '<!--') === 0) // comments |
|
677 | + } elseif(strpos($str, '<!--') === 0) { |
|
678 | + // comments |
|
631 | 679 | { |
632 | 680 | if($expectPropEnd) |
633 | 681 | throw new TConfigurationException('template_comments_forbidden'); |
634 | - if($matchStart > $textStart) |
|
635 | - $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
682 | + } |
|
683 | + if($matchStart > $textStart) { |
|
684 | + $tpl[$c++] = [$container,substr($input, $textStart, $matchStart - $textStart)]; |
|
685 | + } |
|
636 | 686 | $textStart = $matchEnd + 1; |
687 | + } else { |
|
688 | + throw new TConfigurationException('template_matching_unexpected', $match); |
|
637 | 689 | } |
638 | - else |
|
639 | - throw new TConfigurationException('template_matching_unexpected', $match); |
|
640 | 690 | } |
641 | 691 | if(!empty($stack)) |
642 | 692 | { |
@@ -644,22 +694,25 @@ discard block |
||
644 | 694 | $tag = $name[0] === '@' ? '</prop:' . substr($name, 1) . '>' : "</com:$name>"; |
645 | 695 | throw new TConfigurationException('template_closingtag_expected', $tag, "nothing"); |
646 | 696 | } |
647 | - if($textStart < strlen($input)) |
|
648 | - $tpl[$c++] = [$container,substr($input, $textStart)]; |
|
649 | - } |
|
650 | - catch(\Exception $e) |
|
697 | + if($textStart < strlen($input)) { |
|
698 | + $tpl[$c++] = [$container,substr($input, $textStart)]; |
|
699 | + } |
|
700 | + } catch(\Exception $e) |
|
651 | 701 | { |
652 | - if(($e instanceof TException) && ($e instanceof TTemplateException)) |
|
653 | - throw $e; |
|
654 | - if($matchEnd === 0) |
|
655 | - $line = $this->_startingLine + 1; |
|
656 | - else |
|
657 | - $line = $this->_startingLine + count(explode("\n", substr($input, 0, $matchEnd + 1))); |
|
702 | + if(($e instanceof TException) && ($e instanceof TTemplateException)) { |
|
703 | + throw $e; |
|
704 | + } |
|
705 | + if($matchEnd === 0) { |
|
706 | + $line = $this->_startingLine + 1; |
|
707 | + } else { |
|
708 | + $line = $this->_startingLine + count(explode("\n", substr($input, 0, $matchEnd + 1))); |
|
709 | + } |
|
658 | 710 | $this->handleException($e, $line, $input); |
659 | 711 | } |
660 | 712 | |
661 | - if($this->_directive === null) |
|
662 | - $this->_directive = []; |
|
713 | + if($this->_directive === null) { |
|
714 | + $this->_directive = []; |
|
715 | + } |
|
663 | 716 | |
664 | 717 | // optimization by merging consecutive strings, expressions, statements and bindings |
665 | 718 | $objects = []; |
@@ -671,31 +724,32 @@ discard block |
||
671 | 724 | { |
672 | 725 | if($parent !== null) |
673 | 726 | { |
674 | - if(count($merged[1]) === 1 && is_string($merged[1][0])) |
|
675 | - $objects[$id - 1] = [$merged[0],$merged[1][0]]; |
|
676 | - else |
|
677 | - $objects[$id - 1] = [$merged[0],new TCompositeLiteral($merged[1])]; |
|
727 | + if(count($merged[1]) === 1 && is_string($merged[1][0])) { |
|
728 | + $objects[$id - 1] = [$merged[0],$merged[1][0]]; |
|
729 | + } else { |
|
730 | + $objects[$id - 1] = [$merged[0],new TCompositeLiteral($merged[1])]; |
|
731 | + } |
|
678 | 732 | } |
679 | 733 | if(isset($object[2])) |
680 | 734 | { |
681 | 735 | $parent = null; |
682 | 736 | $objects[$id] = $object; |
683 | - } |
|
684 | - else |
|
737 | + } else |
|
685 | 738 | { |
686 | 739 | $parent = $object[0]; |
687 | 740 | $merged = [$parent,[$object[1]]]; |
688 | 741 | } |
742 | + } else { |
|
743 | + $merged[1][] = $object[1]; |
|
689 | 744 | } |
690 | - else |
|
691 | - $merged[1][] = $object[1]; |
|
692 | 745 | } |
693 | 746 | if($parent !== null) |
694 | 747 | { |
695 | - if(count($merged[1]) === 1 && is_string($merged[1][0])) |
|
696 | - $objects[$id] = [$merged[0],$merged[1][0]]; |
|
697 | - else |
|
698 | - $objects[$id] = [$merged[0],new TCompositeLiteral($merged[1])]; |
|
748 | + if(count($merged[1]) === 1 && is_string($merged[1][0])) { |
|
749 | + $objects[$id] = [$merged[0],$merged[1][0]]; |
|
750 | + } else { |
|
751 | + $objects[$id] = [$merged[0],new TCompositeLiteral($merged[1])]; |
|
752 | + } |
|
699 | 753 | } |
700 | 754 | $tpl = $objects; |
701 | 755 | return $objects; |
@@ -708,8 +762,9 @@ discard block |
||
708 | 762 | */ |
709 | 763 | protected function parseAttributes($str, $offset) |
710 | 764 | { |
711 | - if($str === '') |
|
712 | - return []; |
|
765 | + if($str === '') { |
|
766 | + return []; |
|
767 | + } |
|
713 | 768 | $pattern = '/([\w\.\-]+)\s*=\s*(\'.*?\'|".*?"|<%.*?%>)/msS'; |
714 | 769 | $attributes = []; |
715 | 770 | $n = preg_match_all($pattern, $str, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE); |
@@ -717,22 +772,24 @@ discard block |
||
717 | 772 | { |
718 | 773 | $match = &$matches[$i]; |
719 | 774 | $name = strtolower($match[1][0]); |
720 | - if(isset($attributes[$name])) |
|
721 | - throw new TConfigurationException('template_property_duplicated', $name); |
|
775 | + if(isset($attributes[$name])) { |
|
776 | + throw new TConfigurationException('template_property_duplicated', $name); |
|
777 | + } |
|
722 | 778 | $value = $match[2][0]; |
723 | 779 | if(substr($name, -8, 8) === 'template') |
724 | 780 | { |
725 | - if($value[0] === '\'' || $value[0] === '"') |
|
726 | - $attributes[$name] = $this->parseTemplateProperty(substr($value, 1, strlen($value) - 2), $match[2][1] + 1); |
|
727 | - else |
|
728 | - $attributes[$name] = $this->parseTemplateProperty($value, $match[2][1]); |
|
729 | - } |
|
730 | - else |
|
781 | + if($value[0] === '\'' || $value[0] === '"') { |
|
782 | + $attributes[$name] = $this->parseTemplateProperty(substr($value, 1, strlen($value) - 2), $match[2][1] + 1); |
|
783 | + } else { |
|
784 | + $attributes[$name] = $this->parseTemplateProperty($value, $match[2][1]); |
|
785 | + } |
|
786 | + } else |
|
731 | 787 | { |
732 | - if($value[0] === '\'' || $value[0] === '"') |
|
733 | - $attributes[$name] = $this->parseAttribute(substr($value, 1, strlen($value) - 2)); |
|
734 | - else |
|
735 | - $attributes[$name] = $this->parseAttribute($value); |
|
788 | + if($value[0] === '\'' || $value[0] === '"') { |
|
789 | + $attributes[$name] = $this->parseAttribute(substr($value, 1, strlen($value) - 2)); |
|
790 | + } else { |
|
791 | + $attributes[$name] = $this->parseAttribute($value); |
|
792 | + } |
|
736 | 793 | } |
737 | 794 | } |
738 | 795 | return $attributes; |
@@ -762,46 +819,50 @@ discard block |
||
762 | 819 | $token = $match[0]; |
763 | 820 | $offset = $match[1]; |
764 | 821 | $length = strlen($token); |
765 | - if($token[2] === '#') |
|
766 | - $isDataBind = true; |
|
767 | - if($offset > $textStart) |
|
768 | - $expr .= ".'" . strtr(substr($value, $textStart, $offset - $textStart), ["'" => "\\'","\\" => "\\\\"]) . "'"; |
|
822 | + if($token[2] === '#') { |
|
823 | + $isDataBind = true; |
|
824 | + } |
|
825 | + if($offset > $textStart) { |
|
826 | + $expr .= ".'" . strtr(substr($value, $textStart, $offset - $textStart), ["'" => "\\'","\\" => "\\\\"]) . "'"; |
|
827 | + } |
|
769 | 828 | $expr .= '.(' . substr($token, 3, $length - 5) . ')'; |
770 | 829 | $textStart = $offset + $length; |
771 | 830 | } |
772 | 831 | $length = strlen($value); |
773 | - if($length > $textStart) |
|
774 | - $expr .= ".'" . strtr(substr($value, $textStart, $length - $textStart), ["'" => "\\'","\\" => "\\\\"]) . "'"; |
|
775 | - if($isDataBind) |
|
776 | - return [self::CONFIG_DATABIND,ltrim($expr, '.')]; |
|
777 | - else |
|
778 | - return [self::CONFIG_EXPRESSION,ltrim($expr, '.')]; |
|
779 | - } |
|
780 | - elseif(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS', $value, $matches) && $matches[0] === $value) |
|
832 | + if($length > $textStart) { |
|
833 | + $expr .= ".'" . strtr(substr($value, $textStart, $length - $textStart), ["'" => "\\'","\\" => "\\\\"]) . "'"; |
|
834 | + } |
|
835 | + if($isDataBind) { |
|
836 | + return [self::CONFIG_DATABIND,ltrim($expr, '.')]; |
|
837 | + } else { |
|
838 | + return [self::CONFIG_EXPRESSION,ltrim($expr, '.')]; |
|
839 | + } |
|
840 | + } elseif(preg_match('/\\s*(<%~.*?%>|<%\\$.*?%>|<%\\[.*?\\]%>|<%\/.*?%>)\\s*/msS', $value, $matches) && $matches[0] === $value) |
|
781 | 841 | { |
782 | 842 | $value = $matches[1]; |
783 | - if($value[2] === '~') |
|
784 | - return [self::CONFIG_ASSET,trim(substr($value, 3, strlen($value) - 5))]; |
|
785 | - elseif($value[2] === '[') |
|
786 | - return [self::CONFIG_LOCALIZATION,trim(substr($value, 3, strlen($value) - 6))]; |
|
787 | - elseif($value[2] === '$') |
|
788 | - return [self::CONFIG_PARAMETER,trim(substr($value, 3, strlen($value) - 5))]; |
|
789 | - elseif($value[2] === '/') { |
|
843 | + if($value[2] === '~') { |
|
844 | + return [self::CONFIG_ASSET,trim(substr($value, 3, strlen($value) - 5))]; |
|
845 | + } elseif($value[2] === '[') { |
|
846 | + return [self::CONFIG_LOCALIZATION,trim(substr($value, 3, strlen($value) - 6))]; |
|
847 | + } elseif($value[2] === '$') { |
|
848 | + return [self::CONFIG_PARAMETER,trim(substr($value, 3, strlen($value) - 5))]; |
|
849 | + } elseif($value[2] === '/') { |
|
790 | 850 | $literal = trim(substr($value, 3, strlen($value) - 5)); |
791 | 851 | return [self::CONFIG_EXPRESSION,"rtrim(dirname(\$this->getApplication()->getRequest()->getApplicationUrl()), '\/').'/$literal'"]; |
792 | 852 | } |
853 | + } else { |
|
854 | + return $value; |
|
793 | 855 | } |
794 | - else |
|
795 | - return $value; |
|
796 | 856 | } |
797 | 857 | |
798 | 858 | protected function validateAttributes($type, $attributes) |
799 | 859 | { |
800 | 860 | Prado::using($type); |
801 | - if(($pos = strrpos($type, '.')) !== false) |
|
802 | - $className = substr($type, $pos + 1); |
|
803 | - else |
|
804 | - $className = $type; |
|
861 | + if(($pos = strrpos($type, '.')) !== false) { |
|
862 | + $className = substr($type, $pos + 1); |
|
863 | + } else { |
|
864 | + $className = $type; |
|
865 | + } |
|
805 | 866 | $class = new \ReflectionClass($className); |
806 | 867 | if(is_subclass_of($className, '\Prado\Web\UI\TControl') || $className === '\Prado\Web\UI\TControl') |
807 | 868 | { |
@@ -811,67 +872,69 @@ discard block |
||
811 | 872 | { |
812 | 873 | // a subproperty, so the first segment must be readable |
813 | 874 | $subname = substr($name, 0, $pos); |
814 | - if(!$class->hasMethod('get' . $subname)) |
|
815 | - throw new TConfigurationException('template_property_unknown', $type, $subname); |
|
816 | - } |
|
817 | - elseif(strncasecmp($name, 'on', 2) === 0) |
|
875 | + if(!$class->hasMethod('get' . $subname)) { |
|
876 | + throw new TConfigurationException('template_property_unknown', $type, $subname); |
|
877 | + } |
|
878 | + } elseif(strncasecmp($name, 'on', 2) === 0) |
|
818 | 879 | { |
819 | 880 | // an event |
820 | - if(!$class->hasMethod($name)) |
|
821 | - throw new TConfigurationException('template_event_unknown', $type, $name); |
|
822 | - elseif(!is_string($att)) |
|
823 | - throw new TConfigurationException('template_eventhandler_invalid', $type, $name); |
|
824 | - } |
|
825 | - else |
|
881 | + if(!$class->hasMethod($name)) { |
|
882 | + throw new TConfigurationException('template_event_unknown', $type, $name); |
|
883 | + } elseif(!is_string($att)) { |
|
884 | + throw new TConfigurationException('template_eventhandler_invalid', $type, $name); |
|
885 | + } |
|
886 | + } else |
|
826 | 887 | { |
827 | 888 | // a simple property |
828 | 889 | if (! ($class->hasMethod('set' . $name) || $class->hasMethod('setjs' . $name) || $this->isClassBehaviorMethod($class, 'set' . $name))) |
829 | 890 | { |
830 | - if ($class->hasMethod('get' . $name) || $class->hasMethod('getjs' . $name)) |
|
831 | - throw new TConfigurationException('template_property_readonly', $type, $name); |
|
832 | - else |
|
833 | - throw new TConfigurationException('template_property_unknown', $type, $name); |
|
834 | - } |
|
835 | - elseif(is_array($att) && $att[0] !== self::CONFIG_EXPRESSION) |
|
891 | + if ($class->hasMethod('get' . $name) || $class->hasMethod('getjs' . $name)) { |
|
892 | + throw new TConfigurationException('template_property_readonly', $type, $name); |
|
893 | + } else { |
|
894 | + throw new TConfigurationException('template_property_unknown', $type, $name); |
|
895 | + } |
|
896 | + } elseif(is_array($att) && $att[0] !== self::CONFIG_EXPRESSION) |
|
836 | 897 | { |
837 | - if(strcasecmp($name, 'id') === 0) |
|
838 | - throw new TConfigurationException('template_controlid_invalid', $type); |
|
839 | - elseif(strcasecmp($name, 'skinid') === 0) |
|
840 | - throw new TConfigurationException('template_controlskinid_invalid', $type); |
|
898 | + if(strcasecmp($name, 'id') === 0) { |
|
899 | + throw new TConfigurationException('template_controlid_invalid', $type); |
|
900 | + } elseif(strcasecmp($name, 'skinid') === 0) { |
|
901 | + throw new TConfigurationException('template_controlskinid_invalid', $type); |
|
902 | + } |
|
841 | 903 | } |
842 | 904 | } |
843 | 905 | } |
844 | - } |
|
845 | - elseif(is_subclass_of($className, '\Prado\TComponent') || $className === '\Prado\TComponent') |
|
906 | + } elseif(is_subclass_of($className, '\Prado\TComponent') || $className === '\Prado\TComponent') |
|
846 | 907 | { |
847 | 908 | foreach($attributes as $name => $att) |
848 | 909 | { |
849 | - if(is_array($att) && ($att[0] === self::CONFIG_DATABIND)) |
|
850 | - throw new TConfigurationException('template_databind_forbidden', $type, $name); |
|
910 | + if(is_array($att) && ($att[0] === self::CONFIG_DATABIND)) { |
|
911 | + throw new TConfigurationException('template_databind_forbidden', $type, $name); |
|
912 | + } |
|
851 | 913 | if(($pos = strpos($name, '.')) !== false) |
852 | 914 | { |
853 | 915 | // a subproperty, so the first segment must be readable |
854 | 916 | $subname = substr($name, 0, $pos); |
855 | - if(!$class->hasMethod('get' . $subname)) |
|
856 | - throw new TConfigurationException('template_property_unknown', $type, $subname); |
|
857 | - } |
|
858 | - elseif(strncasecmp($name, 'on', 2) === 0) |
|
859 | - throw new TConfigurationException('template_event_forbidden', $type, $name); |
|
860 | - else |
|
917 | + if(!$class->hasMethod('get' . $subname)) { |
|
918 | + throw new TConfigurationException('template_property_unknown', $type, $subname); |
|
919 | + } |
|
920 | + } elseif(strncasecmp($name, 'on', 2) === 0) { |
|
921 | + throw new TConfigurationException('template_event_forbidden', $type, $name); |
|
922 | + } else |
|
861 | 923 | { |
862 | 924 | // id is still alowed for TComponent, even if id property doesn't exist |
863 | 925 | if(strcasecmp($name, 'id') !== 0 && !($class->hasMethod('set' . $name) || $this->isClassBehaviorMethod($class, 'set' . $name))) |
864 | 926 | { |
865 | - if($class->hasMethod('get' . $name)) |
|
866 | - throw new TConfigurationException('template_property_readonly', $type, $name); |
|
867 | - else |
|
868 | - throw new TConfigurationException('template_property_unknown', $type, $name); |
|
927 | + if($class->hasMethod('get' . $name)) { |
|
928 | + throw new TConfigurationException('template_property_readonly', $type, $name); |
|
929 | + } else { |
|
930 | + throw new TConfigurationException('template_property_unknown', $type, $name); |
|
931 | + } |
|
869 | 932 | } |
870 | 933 | } |
871 | 934 | } |
935 | + } else { |
|
936 | + throw new TConfigurationException('template_component_required', $type); |
|
872 | 937 | } |
873 | - else |
|
874 | - throw new TConfigurationException('template_component_required', $type); |
|
875 | 938 | return $class->getName(); |
876 | 939 | } |
877 | 940 | |
@@ -895,9 +958,12 @@ discard block |
||
895 | 958 | { |
896 | 959 | $srcFile = $this->_tplFile; |
897 | 960 | |
898 | - if(($n = count($this->_includedFiles)) > 0) // need to adjust error row number and file name |
|
961 | + if(($n = count($this->_includedFiles)) > 0) { |
|
962 | + // need to adjust error row number and file name |
|
899 | 963 | { |
900 | - for($i = $n - 1;$i >= 0;--$i) |
|
964 | + for($i = $n - 1; |
|
965 | + } |
|
966 | + $i >= 0;--$i) |
|
901 | 967 | { |
902 | 968 | if($this->_includeAtLine[$i] <= $line) |
903 | 969 | { |
@@ -906,18 +972,19 @@ discard block |
||
906 | 972 | $line = $line - $this->_includeAtLine[$i] + 1; |
907 | 973 | $srcFile = $this->_includedFiles[$i]; |
908 | 974 | break; |
975 | + } else { |
|
976 | + $line = $line - $this->_includeLines[$i] + 1; |
|
909 | 977 | } |
910 | - else |
|
911 | - $line = $line - $this->_includeLines[$i] + 1; |
|
912 | 978 | } |
913 | 979 | } |
914 | 980 | } |
915 | 981 | $exception = new TTemplateException('template_format_invalid', $e->getMessage()); |
916 | 982 | $exception->setLineNumber($line); |
917 | - if(!empty($srcFile)) |
|
918 | - $exception->setTemplateFile($srcFile); |
|
919 | - else |
|
920 | - $exception->setTemplateSource($input); |
|
983 | + if(!empty($srcFile)) { |
|
984 | + $exception->setTemplateFile($srcFile); |
|
985 | + } else { |
|
986 | + $exception->setTemplateSource($input); |
|
987 | + } |
|
921 | 988 | throw $exception; |
922 | 989 | } |
923 | 990 | |
@@ -933,9 +1000,9 @@ discard block |
||
933 | 1000 | for($i = 0;$i < $n;++$i) |
934 | 1001 | { |
935 | 1002 | $filePath = Prado::getPathOfNamespace(trim($matches[$i][1][0]), TTemplateManager::TEMPLATE_FILE_EXT); |
936 | - if($filePath !== null && is_file($filePath)) |
|
937 | - $this->_includedFiles[] = $filePath; |
|
938 | - else |
|
1003 | + if($filePath !== null && is_file($filePath)) { |
|
1004 | + $this->_includedFiles[] = $filePath; |
|
1005 | + } else |
|
939 | 1006 | { |
940 | 1007 | $errorLine = count(explode("\n", substr($input, 0, $matches[$i][0][1] + 1))); |
941 | 1008 | $this->handleException(new TConfigurationException('template_include_invalid', trim($matches[$i][1][0])), $errorLine, $input); |
@@ -967,15 +1034,19 @@ discard block |
||
967 | 1034 | { |
968 | 1035 | $component = new \ReflectionClass('\Prado\TComponent'); |
969 | 1036 | $behaviors = $component->getStaticProperties(); |
970 | - if(!isset($behaviors['_um'])) |
|
971 | - return false; |
|
1037 | + if(!isset($behaviors['_um'])) { |
|
1038 | + return false; |
|
1039 | + } |
|
972 | 1040 | foreach($behaviors['_um'] as $name => $list) |
973 | 1041 | { |
974 | - if(strtolower($class->getShortName()) !== $name && !$class->isSubclassOf($name)) continue; |
|
1042 | + if(strtolower($class->getShortName()) !== $name && !$class->isSubclassOf($name)) { |
|
1043 | + continue; |
|
1044 | + } |
|
975 | 1045 | foreach($list as $param) |
976 | 1046 | { |
977 | - if(method_exists($param->getBehavior(), $method)) |
|
978 | - return true; |
|
1047 | + if(method_exists($param->getBehavior(), $method)) { |
|
1048 | + return true; |
|
1049 | + } |
|
979 | 1050 | } |
980 | 1051 | } |
981 | 1052 | return false; |
@@ -110,15 +110,15 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getCache() |
112 | 112 | { |
113 | - if($this->_cache === null) |
|
113 | + if ($this->_cache === null) |
|
114 | 114 | { |
115 | - if($this->_cacheModuleID !== '') |
|
115 | + if ($this->_cacheModuleID !== '') |
|
116 | 116 | $cache = Prado::getApplication()->getModule($this->_cacheModuleID); |
117 | 117 | else |
118 | 118 | $cache = Prado::getApplication()->getCache(); |
119 | - if($cache === null || !($cache instanceof ICache)) |
|
119 | + if ($cache === null || !($cache instanceof ICache)) |
|
120 | 120 | { |
121 | - if($this->_cacheModuleID !== '') |
|
121 | + if ($this->_cacheModuleID !== '') |
|
122 | 122 | throw new TConfigurationException('cachepagestatepersister_cachemoduleid_invalid', $this->_cacheModuleID); |
123 | 123 | else |
124 | 124 | throw new TConfigurationException('cachepagestatepersister_cache_required'); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function setCacheTimeout($value) |
144 | 144 | { |
145 | - if(($value = TPropertyValue::ensureInteger($value)) >= 0) |
|
145 | + if (($value = TPropertyValue::ensureInteger($value)) >= 0) |
|
146 | 146 | $this->_timeout = $value; |
147 | 147 | else |
148 | 148 | throw new TInvalidDataValueException('cachepagestatepersister_timeout_invalid'); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | protected function calculateKey($timestamp) |
172 | 172 | { |
173 | - return $this->getKeyPrefix() . ':' |
|
173 | + return $this->getKeyPrefix().':' |
|
174 | 174 | . $this->_page->getRequest()->getUserHostAddress() |
175 | 175 | . $this->_page->getPagePath() |
176 | 176 | . $timestamp; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function save($data) |
184 | 184 | { |
185 | - $timestamp = (string)microtime(true); |
|
185 | + $timestamp = (string) microtime(true); |
|
186 | 186 | $key = $this->calculateKey($timestamp); |
187 | 187 | $this->getCache()->add($key, $data, $this->_timeout); |
188 | 188 | $this->_page->setClientState(TPageStateFormatter::serialize($this->_page, $timestamp)); |
@@ -195,10 +195,10 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function load() |
197 | 197 | { |
198 | - if(($timestamp = TPageStateFormatter::unserialize($this->_page, $this->_page->getRequestClientState())) !== null) |
|
198 | + if (($timestamp = TPageStateFormatter::unserialize($this->_page, $this->_page->getRequestClientState())) !== null) |
|
199 | 199 | { |
200 | 200 | $key = $this->calculateKey($timestamp); |
201 | - if(($data = $this->getCache()->get($key)) !== false) |
|
201 | + if (($data = $this->getCache()->get($key)) !== false) |
|
202 | 202 | return $data; |
203 | 203 | } |
204 | 204 | throw new THttpException(400, 'cachepagestatepersister_pagestate_corrupted'); |
@@ -112,16 +112,18 @@ discard block |
||
112 | 112 | { |
113 | 113 | if($this->_cache === null) |
114 | 114 | { |
115 | - if($this->_cacheModuleID !== '') |
|
116 | - $cache = Prado::getApplication()->getModule($this->_cacheModuleID); |
|
117 | - else |
|
118 | - $cache = Prado::getApplication()->getCache(); |
|
115 | + if($this->_cacheModuleID !== '') { |
|
116 | + $cache = Prado::getApplication()->getModule($this->_cacheModuleID); |
|
117 | + } else { |
|
118 | + $cache = Prado::getApplication()->getCache(); |
|
119 | + } |
|
119 | 120 | if($cache === null || !($cache instanceof ICache)) |
120 | 121 | { |
121 | - if($this->_cacheModuleID !== '') |
|
122 | - throw new TConfigurationException('cachepagestatepersister_cachemoduleid_invalid', $this->_cacheModuleID); |
|
123 | - else |
|
124 | - throw new TConfigurationException('cachepagestatepersister_cache_required'); |
|
122 | + if($this->_cacheModuleID !== '') { |
|
123 | + throw new TConfigurationException('cachepagestatepersister_cachemoduleid_invalid', $this->_cacheModuleID); |
|
124 | + } else { |
|
125 | + throw new TConfigurationException('cachepagestatepersister_cache_required'); |
|
126 | + } |
|
125 | 127 | } |
126 | 128 | $this->_cache = $cache; |
127 | 129 | } |
@@ -142,10 +144,11 @@ discard block |
||
142 | 144 | */ |
143 | 145 | public function setCacheTimeout($value) |
144 | 146 | { |
145 | - if(($value = TPropertyValue::ensureInteger($value)) >= 0) |
|
146 | - $this->_timeout = $value; |
|
147 | - else |
|
148 | - throw new TInvalidDataValueException('cachepagestatepersister_timeout_invalid'); |
|
147 | + if(($value = TPropertyValue::ensureInteger($value)) >= 0) { |
|
148 | + $this->_timeout = $value; |
|
149 | + } else { |
|
150 | + throw new TInvalidDataValueException('cachepagestatepersister_timeout_invalid'); |
|
151 | + } |
|
149 | 152 | } |
150 | 153 | |
151 | 154 | /** |
@@ -198,8 +201,9 @@ discard block |
||
198 | 201 | if(($timestamp = TPageStateFormatter::unserialize($this->_page, $this->_page->getRequestClientState())) !== null) |
199 | 202 | { |
200 | 203 | $key = $this->calculateKey($timestamp); |
201 | - if(($data = $this->getCache()->get($key)) !== false) |
|
202 | - return $data; |
|
204 | + if(($data = $this->getCache()->get($key)) !== false) { |
|
205 | + return $data; |
|
206 | + } |
|
203 | 207 | } |
204 | 208 | throw new THttpException(400, 'cachepagestatepersister_pagestate_corrupted'); |
205 | 209 | } |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | public static function serialize($page, $data) |
39 | 39 | { |
40 | 40 | $sm = $page->getApplication()->getSecurityManager(); |
41 | - if($page->getEnableStateValidation()) |
|
41 | + if ($page->getEnableStateValidation()) |
|
42 | 42 | $str = $sm->hashData(serialize($data)); |
43 | 43 | else |
44 | 44 | $str = serialize($data); |
45 | - if($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
45 | + if ($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
46 | 46 | $str = gzcompress($str); |
47 | - if($page->getEnableStateEncryption()) |
|
47 | + if ($page->getEnableStateEncryption()) |
|
48 | 48 | $str = $sm->encrypt($str); |
49 | 49 | return base64_encode($str); |
50 | 50 | } |
@@ -57,18 +57,18 @@ discard block |
||
57 | 57 | public static function unserialize($page, $data) |
58 | 58 | { |
59 | 59 | $str = base64_decode($data); |
60 | - if($str === '') |
|
60 | + if ($str === '') |
|
61 | 61 | return null; |
62 | - if($str !== false) |
|
62 | + if ($str !== false) |
|
63 | 63 | { |
64 | 64 | $sm = $page->getApplication()->getSecurityManager(); |
65 | - if($page->getEnableStateEncryption()) |
|
65 | + if ($page->getEnableStateEncryption()) |
|
66 | 66 | $str = $sm->decrypt($str); |
67 | - if($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
67 | + if ($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
68 | 68 | $str = @gzuncompress($str); |
69 | - if($page->getEnableStateValidation()) |
|
69 | + if ($page->getEnableStateValidation()) |
|
70 | 70 | { |
71 | - if(($str = $sm->validateData($str)) !== false) |
|
71 | + if (($str = $sm->validateData($str)) !== false) |
|
72 | 72 | return unserialize($str); |
73 | 73 | } |
74 | 74 | else |
@@ -38,14 +38,17 @@ discard block |
||
38 | 38 | public static function serialize($page, $data) |
39 | 39 | { |
40 | 40 | $sm = $page->getApplication()->getSecurityManager(); |
41 | - if($page->getEnableStateValidation()) |
|
42 | - $str = $sm->hashData(serialize($data)); |
|
43 | - else |
|
44 | - $str = serialize($data); |
|
45 | - if($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
46 | - $str = gzcompress($str); |
|
47 | - if($page->getEnableStateEncryption()) |
|
48 | - $str = $sm->encrypt($str); |
|
41 | + if($page->getEnableStateValidation()) { |
|
42 | + $str = $sm->hashData(serialize($data)); |
|
43 | + } else { |
|
44 | + $str = serialize($data); |
|
45 | + } |
|
46 | + if($page->getEnableStateCompression() && extension_loaded('zlib')) { |
|
47 | + $str = gzcompress($str); |
|
48 | + } |
|
49 | + if($page->getEnableStateEncryption()) { |
|
50 | + $str = $sm->encrypt($str); |
|
51 | + } |
|
49 | 52 | return base64_encode($str); |
50 | 53 | } |
51 | 54 | |
@@ -57,22 +60,26 @@ discard block |
||
57 | 60 | public static function unserialize($page, $data) |
58 | 61 | { |
59 | 62 | $str = base64_decode($data); |
60 | - if($str === '') |
|
61 | - return null; |
|
63 | + if($str === '') { |
|
64 | + return null; |
|
65 | + } |
|
62 | 66 | if($str !== false) |
63 | 67 | { |
64 | 68 | $sm = $page->getApplication()->getSecurityManager(); |
65 | - if($page->getEnableStateEncryption()) |
|
66 | - $str = $sm->decrypt($str); |
|
67 | - if($page->getEnableStateCompression() && extension_loaded('zlib')) |
|
68 | - $str = @gzuncompress($str); |
|
69 | + if($page->getEnableStateEncryption()) { |
|
70 | + $str = $sm->decrypt($str); |
|
71 | + } |
|
72 | + if($page->getEnableStateCompression() && extension_loaded('zlib')) { |
|
73 | + $str = @gzuncompress($str); |
|
74 | + } |
|
69 | 75 | if($page->getEnableStateValidation()) |
70 | 76 | { |
71 | - if(($str = $sm->validateData($str)) !== false) |
|
72 | - return unserialize($str); |
|
77 | + if(($str = $sm->validateData($str)) !== false) { |
|
78 | + return unserialize($str); |
|
79 | + } |
|
80 | + } else { |
|
81 | + return unserialize($str); |
|
73 | 82 | } |
74 | - else |
|
75 | - return unserialize($str); |
|
76 | 83 | } |
77 | 84 | return null; |
78 | 85 | } |