@@ -105,6 +105,9 @@ |
||
105 | 105 | * @param string RPC server URL |
106 | 106 | * @param array payload data |
107 | 107 | * @param string request mime type |
108 | + * @param string $serverUrl |
|
109 | + * @param string $mimeType |
|
110 | + * @return string |
|
108 | 111 | */ |
109 | 112 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 113 | { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function create($type, $serverUrl, $isNotification = false) |
80 | 80 | { |
81 | - if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) |
|
81 | + if (($_handler = constant('TRpcClientTypesEnumerable::' . strtoupper($type))) === null) |
|
82 | 82 | throw new TApplicationException('rpcclient_unsupported_handler'); |
83 | 83 | |
84 | 84 | return new $_handler($serverUrl, $isNotification); |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 110 | { |
111 | - if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
112 | - throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
|
111 | + if (($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
112 | + throw new TRpcClientRequestException('Request failed ("' . $http_response_header[0] . '")'); |
|
113 | 113 | |
114 | 114 | return $_response; |
115 | 115 | } |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'application/json'); |
243 | 243 | |
244 | 244 | // skip response handling if the request was just a notification request |
245 | - if($this->isNotification) |
|
245 | + if ($this->isNotification) |
|
246 | 246 | return true; |
247 | 247 | |
248 | 248 | // decode response |
249 | - if(($_response = json_decode($_response, true)) === null) |
|
249 | + if (($_response = json_decode($_response, true)) === null) |
|
250 | 250 | throw new TRpcClientResponseException('Empty response received'); |
251 | 251 | |
252 | 252 | // handle error response |
253 | - if(!is_null($_response['error'])) |
|
253 | + if (!is_null($_response['error'])) |
|
254 | 254 | throw new TRpcClientResponseException($_response['error']); |
255 | 255 | |
256 | 256 | return $_response['result']; |
@@ -320,15 +320,15 @@ discard block |
||
320 | 320 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml'); |
321 | 321 | |
322 | 322 | // skip response handling if the request was just a notification request |
323 | - if($this->isNotification) |
|
323 | + if ($this->isNotification) |
|
324 | 324 | return true; |
325 | 325 | |
326 | 326 | // decode response |
327 | - if(($_response = xmlrpc_decode($_response)) === null) |
|
327 | + if (($_response = xmlrpc_decode($_response)) === null) |
|
328 | 328 | throw new TRpcClientResponseException('Empty response received'); |
329 | 329 | |
330 | 330 | // handle error response |
331 | - if(xmlrpc_is_fault($_response)) |
|
331 | + if (xmlrpc_is_fault($_response)) |
|
332 | 332 | throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']); |
333 | 333 | |
334 | 334 | return $_response; |
@@ -78,8 +78,9 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function create($type, $serverUrl, $isNotification = false) |
80 | 80 | { |
81 | - if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) |
|
82 | - throw new TApplicationException('rpcclient_unsupported_handler'); |
|
81 | + if(($_handler = constant('TRpcClientTypesEnumerable::'.strtoupper($type))) === null) { |
|
82 | + throw new TApplicationException('rpcclient_unsupported_handler'); |
|
83 | + } |
|
83 | 84 | |
84 | 85 | return new $_handler($serverUrl, $isNotification); |
85 | 86 | } |
@@ -108,8 +109,9 @@ discard block |
||
108 | 109 | */ |
109 | 110 | protected function performRequest($serverUrl, $payload, $mimeType) |
110 | 111 | { |
111 | - if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) |
|
112 | - throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
|
112 | + if(($_response = @file_get_contents($serverUrl, false, $this->createStreamContext($payload, $mimeType))) === false) { |
|
113 | + throw new TRpcClientRequestException('Request failed ("'.$http_response_header[0].'")'); |
|
114 | + } |
|
113 | 115 | |
114 | 116 | return $_response; |
115 | 117 | } |
@@ -242,16 +244,19 @@ discard block |
||
242 | 244 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'application/json'); |
243 | 245 | |
244 | 246 | // skip response handling if the request was just a notification request |
245 | - if($this->isNotification) |
|
246 | - return true; |
|
247 | + if($this->isNotification) { |
|
248 | + return true; |
|
249 | + } |
|
247 | 250 | |
248 | 251 | // decode response |
249 | - if(($_response = json_decode($_response, true)) === null) |
|
250 | - throw new TRpcClientResponseException('Empty response received'); |
|
252 | + if(($_response = json_decode($_response, true)) === null) { |
|
253 | + throw new TRpcClientResponseException('Empty response received'); |
|
254 | + } |
|
251 | 255 | |
252 | 256 | // handle error response |
253 | - if(!is_null($_response['error'])) |
|
254 | - throw new TRpcClientResponseException($_response['error']); |
|
257 | + if(!is_null($_response['error'])) { |
|
258 | + throw new TRpcClientResponseException($_response['error']); |
|
259 | + } |
|
255 | 260 | |
256 | 261 | return $_response['result']; |
257 | 262 | } |
@@ -320,16 +325,19 @@ discard block |
||
320 | 325 | $_response = $this->performRequest($this->getServerUrl(), $this->encodeRequest($method, $parameters), 'text/xml'); |
321 | 326 | |
322 | 327 | // skip response handling if the request was just a notification request |
323 | - if($this->isNotification) |
|
324 | - return true; |
|
328 | + if($this->isNotification) { |
|
329 | + return true; |
|
330 | + } |
|
325 | 331 | |
326 | 332 | // decode response |
327 | - if(($_response = xmlrpc_decode($_response)) === null) |
|
328 | - throw new TRpcClientResponseException('Empty response received'); |
|
333 | + if(($_response = xmlrpc_decode($_response)) === null) { |
|
334 | + throw new TRpcClientResponseException('Empty response received'); |
|
335 | + } |
|
329 | 336 | |
330 | 337 | // handle error response |
331 | - if(xmlrpc_is_fault($_response)) |
|
332 | - throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']); |
|
338 | + if(xmlrpc_is_fault($_response)) { |
|
339 | + throw new TRpcClientResponseException($_response['faultString'], $_response['faultCode']); |
|
340 | + } |
|
333 | 341 | |
334 | 342 | return $_response; |
335 | 343 | } |
@@ -60,6 +60,7 @@ discard block |
||
60 | 60 | * Constructor, create a new date time formatter. |
61 | 61 | * @param string formatting pattern. |
62 | 62 | * @param string pattern and value charset |
63 | + * @param string $pattern |
|
63 | 64 | */ |
64 | 65 | public function __construct($pattern, $charset='UTF-8') |
65 | 66 | { |
@@ -93,6 +94,7 @@ discard block |
||
93 | 94 | |
94 | 95 | /** |
95 | 96 | * @param string formatting charset. |
97 | + * @param string $charset |
|
96 | 98 | */ |
97 | 99 | public function setCharset($charset) |
98 | 100 | { |
@@ -313,6 +315,7 @@ discard block |
||
313 | 315 | |
314 | 316 | /** |
315 | 317 | * Calculate the length of a string, may be consider iconv_strlen? |
318 | + * @param string $string |
|
316 | 319 | */ |
317 | 320 | private function length($string) |
318 | 321 | { |
@@ -338,6 +341,9 @@ discard block |
||
338 | 341 | |
339 | 342 | /** |
340 | 343 | * Returns true if char at position equals a particular char. |
344 | + * @param string $string |
|
345 | + * @param integer $pos |
|
346 | + * @param string $char |
|
341 | 347 | */ |
342 | 348 | private function charEqual($string, $pos, $char) |
343 | 349 | { |
@@ -350,6 +356,10 @@ discard block |
||
350 | 356 | * @param int starting position |
351 | 357 | * @param int minimum integer length |
352 | 358 | * @param int maximum integer length |
359 | + * @param string $str |
|
360 | + * @param integer $i |
|
361 | + * @param integer|null $minlength |
|
362 | + * @param integer|null $maxlength |
|
353 | 363 | * @return string integer portion of the string, null otherwise |
354 | 364 | */ |
355 | 365 | private function getInteger($str,$i,$minlength,$maxlength) |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param string formatting pattern. |
62 | 62 | * @param string pattern and value charset |
63 | 63 | */ |
64 | - public function __construct($pattern, $charset='UTF-8') |
|
64 | + public function __construct($pattern, $charset = 'UTF-8') |
|
65 | 65 | { |
66 | 66 | $this->setPattern($pattern); |
67 | 67 | $this->setCharset($charset); |
@@ -122,31 +122,31 @@ discard block |
||
122 | 122 | |
123 | 123 | public function getMonthPattern() |
124 | 124 | { |
125 | - if(is_int(strpos($this->pattern, 'MMMM'))) |
|
125 | + if (is_int(strpos($this->pattern, 'MMMM'))) |
|
126 | 126 | return 'MMMM'; |
127 | - if(is_int(strpos($this->pattern, 'MMM'))) |
|
127 | + if (is_int(strpos($this->pattern, 'MMM'))) |
|
128 | 128 | return 'MMM'; |
129 | - if(is_int(strpos($this->pattern, 'MM'))) |
|
129 | + if (is_int(strpos($this->pattern, 'MM'))) |
|
130 | 130 | return 'MM'; |
131 | - if(is_int(strpos($this->pattern, 'M'))) |
|
131 | + if (is_int(strpos($this->pattern, 'M'))) |
|
132 | 132 | return 'M'; |
133 | 133 | return false; |
134 | 134 | } |
135 | 135 | |
136 | 136 | public function getDayPattern() |
137 | 137 | { |
138 | - if(is_int(strpos($this->pattern, 'dd'))) |
|
138 | + if (is_int(strpos($this->pattern, 'dd'))) |
|
139 | 139 | return 'dd'; |
140 | - if(is_int(strpos($this->pattern, 'd'))) |
|
140 | + if (is_int(strpos($this->pattern, 'd'))) |
|
141 | 141 | return 'd'; |
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | 145 | public function getYearPattern() |
146 | 146 | { |
147 | - if(is_int(strpos($this->pattern, 'yyyy'))) |
|
147 | + if (is_int(strpos($this->pattern, 'yyyy'))) |
|
148 | 148 | return 'yyyy'; |
149 | - if(is_int(strpos($this->pattern, 'yy'))) |
|
149 | + if (is_int(strpos($this->pattern, 'yy'))) |
|
150 | 150 | return 'yy'; |
151 | 151 | return false; |
152 | 152 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | public function getDayMonthYearOrdering() |
155 | 155 | { |
156 | 156 | $ordering = array(); |
157 | - if(is_int($day= strpos($this->pattern, 'd'))) |
|
157 | + if (is_int($day = strpos($this->pattern, 'd'))) |
|
158 | 158 | $ordering['day'] = $day; |
159 | - if(is_int($month= strpos($this->pattern, 'M'))) |
|
159 | + if (is_int($month = strpos($this->pattern, 'M'))) |
|
160 | 160 | $ordering['month'] = $month; |
161 | - if(is_int($year= strpos($this->pattern, 'yy'))) |
|
161 | + if (is_int($year = strpos($this->pattern, 'yy'))) |
|
162 | 162 | $ordering['year'] = $year; |
163 | 163 | asort($ordering); |
164 | 164 | return array_keys($ordering); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | private function getDate($value) |
173 | 173 | { |
174 | 174 | $s = Prado::createComponent('System.Util.TDateTimeStamp'); |
175 | - if(is_numeric($value)) |
|
175 | + if (is_numeric($value)) |
|
176 | 176 | return $s->getDate($value); |
177 | 177 | else |
178 | 178 | return $s->parseDate($value); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function isValidDate($value) |
185 | 185 | { |
186 | - if($value === null) { |
|
186 | + if ($value === null) { |
|
187 | 187 | return false; |
188 | 188 | } else { |
189 | 189 | return $this->parse($value, false) !== null; |
@@ -196,18 +196,18 @@ discard block |
||
196 | 196 | * @return int date time stamp |
197 | 197 | * @throws TInvalidDataValueException if date string is malformed. |
198 | 198 | */ |
199 | - public function parse($value,$defaultToCurrentTime=true) |
|
199 | + public function parse($value, $defaultToCurrentTime = true) |
|
200 | 200 | { |
201 | - if(is_int($value) || is_float($value)) |
|
201 | + if (is_int($value) || is_float($value)) |
|
202 | 202 | return $value; |
203 | - else if(!is_string($value)) |
|
203 | + else if (!is_string($value)) |
|
204 | 204 | throw new TInvalidDataValueException('date_to_parse_must_be_string', $value); |
205 | 205 | |
206 | - if(empty($this->pattern)) return time(); |
|
206 | + if (empty($this->pattern)) return time(); |
|
207 | 207 | |
208 | 208 | $date = time(); |
209 | 209 | |
210 | - if($this->length(trim($value)) < 1) |
|
210 | + if ($this->length(trim($value)) < 1) |
|
211 | 211 | return $defaultToCurrentTime ? $date : null; |
212 | 212 | |
213 | 213 | $pattern = $this->pattern; |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | $i_format = 0; |
217 | 217 | $pattern_length = $this->length($pattern); |
218 | 218 | $c = ''; |
219 | - $token=''; |
|
220 | - $x=null; $y=null; |
|
219 | + $token = ''; |
|
220 | + $x = null; $y = null; |
|
221 | 221 | |
222 | 222 | |
223 | - if($defaultToCurrentTime) |
|
223 | + if ($defaultToCurrentTime) |
|
224 | 224 | { |
225 | 225 | $year = "{$date['year']}"; |
226 | 226 | $month = $date['mon']; |
@@ -235,51 +235,51 @@ discard block |
||
235 | 235 | |
236 | 236 | while ($i_format < $pattern_length) |
237 | 237 | { |
238 | - $c = $this->charAt($pattern,$i_format); |
|
239 | - $token=''; |
|
238 | + $c = $this->charAt($pattern, $i_format); |
|
239 | + $token = ''; |
|
240 | 240 | while ($this->charEqual($pattern, $i_format, $c) |
241 | 241 | && ($i_format < $pattern_length)) |
242 | 242 | { |
243 | 243 | $token .= $this->charAt($pattern, $i_format++); |
244 | 244 | } |
245 | 245 | |
246 | - if ($token=='yyyy' || $token=='yy' || $token=='y') |
|
246 | + if ($token == 'yyyy' || $token == 'yy' || $token == 'y') |
|
247 | 247 | { |
248 | - if ($token=='yyyy') { $x=4;$y=4; } |
|
249 | - if ($token=='yy') { $x=2;$y=2; } |
|
250 | - if ($token=='y') { $x=2;$y=4; } |
|
251 | - $year = $this->getInteger($value,$i_val,$x,$y); |
|
252 | - if($year === null) |
|
248 | + if ($token == 'yyyy') { $x = 4; $y = 4; } |
|
249 | + if ($token == 'yy') { $x = 2; $y = 2; } |
|
250 | + if ($token == 'y') { $x = 2; $y = 4; } |
|
251 | + $year = $this->getInteger($value, $i_val, $x, $y); |
|
252 | + if ($year === null) |
|
253 | 253 | return null; |
254 | 254 | //throw new TInvalidDataValueException('Invalid year', $value); |
255 | 255 | $i_val += strlen($year); |
256 | - if(strlen($year) == 2) |
|
256 | + if (strlen($year) == 2) |
|
257 | 257 | { |
258 | - $iYear = (int)$year; |
|
259 | - if($iYear > 70) |
|
258 | + $iYear = (int) $year; |
|
259 | + if ($iYear > 70) |
|
260 | 260 | $year = $iYear + 1900; |
261 | 261 | else |
262 | 262 | $year = $iYear + 2000; |
263 | 263 | } |
264 | - $year = (int)$year; |
|
264 | + $year = (int) $year; |
|
265 | 265 | } |
266 | - elseif($token=='MM' || $token=='M') |
|
266 | + elseif ($token == 'MM' || $token == 'M') |
|
267 | 267 | { |
268 | - $month=$this->getInteger($value,$i_val, |
|
269 | - $this->length($token),2); |
|
270 | - $iMonth = (int)$month; |
|
271 | - if($month === null || $iMonth < 1 || $iMonth > 12 ) |
|
268 | + $month = $this->getInteger($value, $i_val, |
|
269 | + $this->length($token), 2); |
|
270 | + $iMonth = (int) $month; |
|
271 | + if ($month === null || $iMonth < 1 || $iMonth > 12) |
|
272 | 272 | return null; |
273 | 273 | //throw new TInvalidDataValueException('Invalid month', $value); |
274 | 274 | $i_val += strlen($month); |
275 | 275 | $month = $iMonth; |
276 | 276 | } |
277 | - elseif ($token=='dd' || $token=='d') |
|
277 | + elseif ($token == 'dd' || $token == 'd') |
|
278 | 278 | { |
279 | - $day = $this->getInteger($value,$i_val, |
|
279 | + $day = $this->getInteger($value, $i_val, |
|
280 | 280 | $this->length($token), 2); |
281 | - $iDay = (int)$day; |
|
282 | - if($day === null || $iDay < 1 || $iDay >31) |
|
281 | + $iDay = (int) $day; |
|
282 | + if ($day === null || $iDay < 1 || $iDay > 31) |
|
283 | 283 | return null; |
284 | 284 | //throw new TInvalidDataValueException('Invalid day', $value); |
285 | 285 | $i_val += strlen($day); |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | else |
289 | 289 | { |
290 | - if($this->substring($value, $i_val, $this->length($token)) != $token) |
|
290 | + if ($this->substring($value, $i_val, $this->length($token)) != $token) |
|
291 | 291 | return null; |
292 | 292 | //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value); |
293 | 293 | else |
@@ -297,15 +297,15 @@ discard block |
||
297 | 297 | if ($i_val != $this->length($value)) |
298 | 298 | return null; |
299 | 299 | //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value); |
300 | - if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) |
|
300 | + if (!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) |
|
301 | 301 | return null; |
302 | 302 | else |
303 | 303 | { |
304 | - if(empty($year)) { |
|
304 | + if (empty($year)) { |
|
305 | 305 | $year = date('Y'); |
306 | 306 | } |
307 | - $day = (int)$day <= 0 ? 1 : (int)$day; |
|
308 | - $month = (int)$month <= 0 ? 1 : (int)$month; |
|
307 | + $day = (int) $day <= 0 ? 1 : (int) $day; |
|
308 | + $month = (int) $month <= 0 ? 1 : (int) $month; |
|
309 | 309 | $s = Prado::createComponent('System.Util.TDateTimeStamp'); |
310 | 310 | return $s->getTimeStamp(0, 0, 0, $month, $day, $year); |
311 | 311 | } |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @param int maximum integer length |
353 | 353 | * @return string integer portion of the string, null otherwise |
354 | 354 | */ |
355 | - private function getInteger($str,$i,$minlength,$maxlength) |
|
355 | + private function getInteger($str, $i, $minlength, $maxlength) |
|
356 | 356 | { |
357 | 357 | //match for digits backwards |
358 | 358 | for ($x = $maxlength; $x >= $minlength; $x--) |
359 | 359 | { |
360 | - $token= $this->substring($str, $i,$x); |
|
360 | + $token = $this->substring($str, $i, $x); |
|
361 | 361 | if ($this->length($token) < $minlength) |
362 | 362 | return null; |
363 | 363 | if (preg_match('/^\d+$/', $token)) |
@@ -122,44 +122,55 @@ discard block |
||
122 | 122 | |
123 | 123 | public function getMonthPattern() |
124 | 124 | { |
125 | - if(is_int(strpos($this->pattern, 'MMMM'))) |
|
126 | - return 'MMMM'; |
|
127 | - if(is_int(strpos($this->pattern, 'MMM'))) |
|
128 | - return 'MMM'; |
|
129 | - if(is_int(strpos($this->pattern, 'MM'))) |
|
130 | - return 'MM'; |
|
131 | - if(is_int(strpos($this->pattern, 'M'))) |
|
132 | - return 'M'; |
|
125 | + if(is_int(strpos($this->pattern, 'MMMM'))) { |
|
126 | + return 'MMMM'; |
|
127 | + } |
|
128 | + if(is_int(strpos($this->pattern, 'MMM'))) { |
|
129 | + return 'MMM'; |
|
130 | + } |
|
131 | + if(is_int(strpos($this->pattern, 'MM'))) { |
|
132 | + return 'MM'; |
|
133 | + } |
|
134 | + if(is_int(strpos($this->pattern, 'M'))) { |
|
135 | + return 'M'; |
|
136 | + } |
|
133 | 137 | return false; |
134 | 138 | } |
135 | 139 | |
136 | 140 | public function getDayPattern() |
137 | 141 | { |
138 | - if(is_int(strpos($this->pattern, 'dd'))) |
|
139 | - return 'dd'; |
|
140 | - if(is_int(strpos($this->pattern, 'd'))) |
|
141 | - return 'd'; |
|
142 | + if(is_int(strpos($this->pattern, 'dd'))) { |
|
143 | + return 'dd'; |
|
144 | + } |
|
145 | + if(is_int(strpos($this->pattern, 'd'))) { |
|
146 | + return 'd'; |
|
147 | + } |
|
142 | 148 | return false; |
143 | 149 | } |
144 | 150 | |
145 | 151 | public function getYearPattern() |
146 | 152 | { |
147 | - if(is_int(strpos($this->pattern, 'yyyy'))) |
|
148 | - return 'yyyy'; |
|
149 | - if(is_int(strpos($this->pattern, 'yy'))) |
|
150 | - return 'yy'; |
|
153 | + if(is_int(strpos($this->pattern, 'yyyy'))) { |
|
154 | + return 'yyyy'; |
|
155 | + } |
|
156 | + if(is_int(strpos($this->pattern, 'yy'))) { |
|
157 | + return 'yy'; |
|
158 | + } |
|
151 | 159 | return false; |
152 | 160 | } |
153 | 161 | |
154 | 162 | public function getDayMonthYearOrdering() |
155 | 163 | { |
156 | 164 | $ordering = array(); |
157 | - if(is_int($day= strpos($this->pattern, 'd'))) |
|
158 | - $ordering['day'] = $day; |
|
159 | - if(is_int($month= strpos($this->pattern, 'M'))) |
|
160 | - $ordering['month'] = $month; |
|
161 | - if(is_int($year= strpos($this->pattern, 'yy'))) |
|
162 | - $ordering['year'] = $year; |
|
165 | + if(is_int($day= strpos($this->pattern, 'd'))) { |
|
166 | + $ordering['day'] = $day; |
|
167 | + } |
|
168 | + if(is_int($month= strpos($this->pattern, 'M'))) { |
|
169 | + $ordering['month'] = $month; |
|
170 | + } |
|
171 | + if(is_int($year= strpos($this->pattern, 'yy'))) { |
|
172 | + $ordering['year'] = $year; |
|
173 | + } |
|
163 | 174 | asort($ordering); |
164 | 175 | return array_keys($ordering); |
165 | 176 | } |
@@ -172,10 +183,11 @@ discard block |
||
172 | 183 | private function getDate($value) |
173 | 184 | { |
174 | 185 | $s = Prado::createComponent('System.Util.TDateTimeStamp'); |
175 | - if(is_numeric($value)) |
|
176 | - return $s->getDate($value); |
|
177 | - else |
|
178 | - return $s->parseDate($value); |
|
186 | + if(is_numeric($value)) { |
|
187 | + return $s->getDate($value); |
|
188 | + } else { |
|
189 | + return $s->parseDate($value); |
|
190 | + } |
|
179 | 191 | } |
180 | 192 | |
181 | 193 | /** |
@@ -198,17 +210,21 @@ discard block |
||
198 | 210 | */ |
199 | 211 | public function parse($value,$defaultToCurrentTime=true) |
200 | 212 | { |
201 | - if(is_int($value) || is_float($value)) |
|
202 | - return $value; |
|
203 | - else if(!is_string($value)) |
|
204 | - throw new TInvalidDataValueException('date_to_parse_must_be_string', $value); |
|
213 | + if(is_int($value) || is_float($value)) { |
|
214 | + return $value; |
|
215 | + } else if(!is_string($value)) { |
|
216 | + throw new TInvalidDataValueException('date_to_parse_must_be_string', $value); |
|
217 | + } |
|
205 | 218 | |
206 | - if(empty($this->pattern)) return time(); |
|
219 | + if(empty($this->pattern)) { |
|
220 | + return time(); |
|
221 | + } |
|
207 | 222 | |
208 | 223 | $date = time(); |
209 | 224 | |
210 | - if($this->length(trim($value)) < 1) |
|
211 | - return $defaultToCurrentTime ? $date : null; |
|
225 | + if($this->length(trim($value)) < 1) { |
|
226 | + return $defaultToCurrentTime ? $date : null; |
|
227 | + } |
|
212 | 228 | |
213 | 229 | $pattern = $this->pattern; |
214 | 230 | |
@@ -225,8 +241,7 @@ discard block |
||
225 | 241 | $year = "{$date['year']}"; |
226 | 242 | $month = $date['mon']; |
227 | 243 | $day = $date['mday']; |
228 | - } |
|
229 | - else |
|
244 | + } else |
|
230 | 245 | { |
231 | 246 | $year = null; |
232 | 247 | $month = null; |
@@ -249,57 +264,61 @@ discard block |
||
249 | 264 | if ($token=='yy') { $x=2;$y=2; } |
250 | 265 | if ($token=='y') { $x=2;$y=4; } |
251 | 266 | $year = $this->getInteger($value,$i_val,$x,$y); |
252 | - if($year === null) |
|
253 | - return null; |
|
267 | + if($year === null) { |
|
268 | + return null; |
|
269 | + } |
|
254 | 270 | //throw new TInvalidDataValueException('Invalid year', $value); |
255 | 271 | $i_val += strlen($year); |
256 | 272 | if(strlen($year) == 2) |
257 | 273 | { |
258 | 274 | $iYear = (int)$year; |
259 | - if($iYear > 70) |
|
260 | - $year = $iYear + 1900; |
|
261 | - else |
|
262 | - $year = $iYear + 2000; |
|
275 | + if($iYear > 70) { |
|
276 | + $year = $iYear + 1900; |
|
277 | + } else { |
|
278 | + $year = $iYear + 2000; |
|
279 | + } |
|
263 | 280 | } |
264 | 281 | $year = (int)$year; |
265 | - } |
|
266 | - elseif($token=='MM' || $token=='M') |
|
282 | + } elseif($token=='MM' || $token=='M') |
|
267 | 283 | { |
268 | 284 | $month=$this->getInteger($value,$i_val, |
269 | 285 | $this->length($token),2); |
270 | 286 | $iMonth = (int)$month; |
271 | - if($month === null || $iMonth < 1 || $iMonth > 12 ) |
|
272 | - return null; |
|
287 | + if($month === null || $iMonth < 1 || $iMonth > 12 ) { |
|
288 | + return null; |
|
289 | + } |
|
273 | 290 | //throw new TInvalidDataValueException('Invalid month', $value); |
274 | 291 | $i_val += strlen($month); |
275 | 292 | $month = $iMonth; |
276 | - } |
|
277 | - elseif ($token=='dd' || $token=='d') |
|
293 | + } elseif ($token=='dd' || $token=='d') |
|
278 | 294 | { |
279 | 295 | $day = $this->getInteger($value,$i_val, |
280 | 296 | $this->length($token), 2); |
281 | 297 | $iDay = (int)$day; |
282 | - if($day === null || $iDay < 1 || $iDay >31) |
|
283 | - return null; |
|
298 | + if($day === null || $iDay < 1 || $iDay >31) { |
|
299 | + return null; |
|
300 | + } |
|
284 | 301 | //throw new TInvalidDataValueException('Invalid day', $value); |
285 | 302 | $i_val += strlen($day); |
286 | 303 | $day = $iDay; |
287 | - } |
|
288 | - else |
|
304 | + } else |
|
289 | 305 | { |
290 | - if($this->substring($value, $i_val, $this->length($token)) != $token) |
|
291 | - return null; |
|
306 | + if($this->substring($value, $i_val, $this->length($token)) != $token) { |
|
307 | + return null; |
|
308 | + } |
|
292 | 309 | //throw new TInvalidDataValueException("Subpattern '{$this->pattern}' mismatch", $value); |
293 | - else |
|
294 | - $i_val += $this->length($token); |
|
310 | + else { |
|
311 | + $i_val += $this->length($token); |
|
312 | + } |
|
295 | 313 | } |
296 | 314 | } |
297 | - if ($i_val != $this->length($value)) |
|
298 | - return null; |
|
315 | + if ($i_val != $this->length($value)) { |
|
316 | + return null; |
|
317 | + } |
|
299 | 318 | //throw new TInvalidDataValueException("Pattern '{$this->pattern}' mismatch", $value); |
300 | - if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) |
|
301 | - return null; |
|
302 | - else |
|
319 | + if(!$defaultToCurrentTime && ($month === null || $day === null || $year === null)) { |
|
320 | + return null; |
|
321 | + } else |
|
303 | 322 | { |
304 | 323 | if(empty($year)) { |
305 | 324 | $year = date('Y'); |
@@ -358,10 +377,12 @@ discard block |
||
358 | 377 | for ($x = $maxlength; $x >= $minlength; $x--) |
359 | 378 | { |
360 | 379 | $token= $this->substring($str, $i,$x); |
361 | - if ($this->length($token) < $minlength) |
|
362 | - return null; |
|
363 | - if (preg_match('/^\d+$/', $token)) |
|
364 | - return $token; |
|
380 | + if ($this->length($token) < $minlength) { |
|
381 | + return null; |
|
382 | + } |
|
383 | + if (preg_match('/^\d+$/', $token)) { |
|
384 | + return $token; |
|
385 | + } |
|
365 | 386 | } |
366 | 387 | return null; |
367 | 388 | } |
@@ -55,6 +55,9 @@ |
||
55 | 55 | return self::$_output; |
56 | 56 | } |
57 | 57 | |
58 | + /** |
|
59 | + * @param integer $level |
|
60 | + */ |
|
58 | 61 | private static function dumpInternal($var,$level) |
59 | 62 | { |
60 | 63 | switch(gettype($var)) |
@@ -40,84 +40,84 @@ |
||
40 | 40 | * @param integer maximum depth that the dumper should go into the variable. Defaults to 10. |
41 | 41 | * @return string the string representation of the variable |
42 | 42 | */ |
43 | - public static function dump($var,$depth=10,$highlight=false) |
|
43 | + public static function dump($var, $depth = 10, $highlight = false) |
|
44 | 44 | { |
45 | - self::$_output=''; |
|
46 | - self::$_objects=array(); |
|
47 | - self::$_depth=$depth; |
|
48 | - self::dumpInternal($var,0); |
|
49 | - if($highlight) |
|
45 | + self::$_output = ''; |
|
46 | + self::$_objects = array(); |
|
47 | + self::$_depth = $depth; |
|
48 | + self::dumpInternal($var, 0); |
|
49 | + if ($highlight) |
|
50 | 50 | { |
51 | - $result=highlight_string("<?php\n".self::$_output,true); |
|
52 | - return preg_replace('/<\\?php<br \\/>/','',$result,1); |
|
51 | + $result = highlight_string("<?php\n" . self::$_output, true); |
|
52 | + return preg_replace('/<\\?php<br \\/>/', '', $result, 1); |
|
53 | 53 | } |
54 | 54 | else |
55 | 55 | return self::$_output; |
56 | 56 | } |
57 | 57 | |
58 | - private static function dumpInternal($var,$level) |
|
58 | + private static function dumpInternal($var, $level) |
|
59 | 59 | { |
60 | - switch(gettype($var)) |
|
60 | + switch (gettype($var)) |
|
61 | 61 | { |
62 | 62 | case 'boolean': |
63 | - self::$_output.=$var?'true':'false'; |
|
63 | + self::$_output .= $var ? 'true' : 'false'; |
|
64 | 64 | break; |
65 | 65 | case 'integer': |
66 | - self::$_output.="$var"; |
|
66 | + self::$_output .= "$var"; |
|
67 | 67 | break; |
68 | 68 | case 'double': |
69 | - self::$_output.="$var"; |
|
69 | + self::$_output .= "$var"; |
|
70 | 70 | break; |
71 | 71 | case 'string': |
72 | - self::$_output.="'$var'"; |
|
72 | + self::$_output .= "'$var'"; |
|
73 | 73 | break; |
74 | 74 | case 'resource': |
75 | - self::$_output.='{resource}'; |
|
75 | + self::$_output .= '{resource}'; |
|
76 | 76 | break; |
77 | 77 | case 'NULL': |
78 | - self::$_output.="null"; |
|
78 | + self::$_output .= "null"; |
|
79 | 79 | break; |
80 | 80 | case 'unknown type': |
81 | - self::$_output.='{unknown}'; |
|
81 | + self::$_output .= '{unknown}'; |
|
82 | 82 | break; |
83 | 83 | case 'array': |
84 | - if(self::$_depth<=$level) |
|
85 | - self::$_output.='array(...)'; |
|
86 | - else if(empty($var)) |
|
87 | - self::$_output.='array()'; |
|
84 | + if (self::$_depth <= $level) |
|
85 | + self::$_output .= 'array(...)'; |
|
86 | + else if (empty($var)) |
|
87 | + self::$_output .= 'array()'; |
|
88 | 88 | else |
89 | 89 | { |
90 | - $keys=array_keys($var); |
|
91 | - $spaces=str_repeat(' ',$level*4); |
|
92 | - self::$_output.="array\n".$spaces.'('; |
|
93 | - foreach($keys as $key) |
|
90 | + $keys = array_keys($var); |
|
91 | + $spaces = str_repeat(' ', $level * 4); |
|
92 | + self::$_output .= "array\n" . $spaces . '('; |
|
93 | + foreach ($keys as $key) |
|
94 | 94 | { |
95 | - self::$_output.="\n".$spaces." [$key] => "; |
|
96 | - self::$_output.=self::dumpInternal($var[$key],$level+1); |
|
95 | + self::$_output .= "\n" . $spaces . " [$key] => "; |
|
96 | + self::$_output .= self::dumpInternal($var[$key], $level + 1); |
|
97 | 97 | } |
98 | - self::$_output.="\n".$spaces.')'; |
|
98 | + self::$_output .= "\n" . $spaces . ')'; |
|
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 'object': |
102 | - if(($id=array_search($var,self::$_objects,true))!==false) |
|
103 | - self::$_output.=get_class($var).'#'.($id+1).'(...)'; |
|
104 | - else if(self::$_depth<=$level) |
|
105 | - self::$_output.=get_class($var).'(...)'; |
|
102 | + if (($id = array_search($var, self::$_objects, true)) !== false) |
|
103 | + self::$_output .= get_class($var) . '#' . ($id + 1) . '(...)'; |
|
104 | + else if (self::$_depth <= $level) |
|
105 | + self::$_output .= get_class($var) . '(...)'; |
|
106 | 106 | else |
107 | 107 | { |
108 | - $id=array_push(self::$_objects,$var); |
|
109 | - $className=get_class($var); |
|
110 | - $members=(array)$var; |
|
111 | - $keys=array_keys($members); |
|
112 | - $spaces=str_repeat(' ',$level*4); |
|
113 | - self::$_output.="$className#$id\n".$spaces.'('; |
|
114 | - foreach($keys as $key) |
|
108 | + $id = array_push(self::$_objects, $var); |
|
109 | + $className = get_class($var); |
|
110 | + $members = (array) $var; |
|
111 | + $keys = array_keys($members); |
|
112 | + $spaces = str_repeat(' ', $level * 4); |
|
113 | + self::$_output .= "$className#$id\n" . $spaces . '('; |
|
114 | + foreach ($keys as $key) |
|
115 | 115 | { |
116 | - $keyDisplay=strtr(trim($key),array("\0"=>':')); |
|
117 | - self::$_output.="\n".$spaces." [$keyDisplay] => "; |
|
118 | - self::$_output.=self::dumpInternal($members[$key],$level+1); |
|
116 | + $keyDisplay = strtr(trim($key), array("\0"=>':')); |
|
117 | + self::$_output .= "\n" . $spaces . " [$keyDisplay] => "; |
|
118 | + self::$_output .= self::dumpInternal($members[$key], $level + 1); |
|
119 | 119 | } |
120 | - self::$_output.="\n".$spaces.')'; |
|
120 | + self::$_output .= "\n" . $spaces . ')'; |
|
121 | 121 | } |
122 | 122 | break; |
123 | 123 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | { |
51 | 51 | $result=highlight_string("<?php\n".self::$_output,true); |
52 | 52 | return preg_replace('/<\\?php<br \\/>/','',$result,1); |
53 | + } else { |
|
54 | + return self::$_output; |
|
53 | 55 | } |
54 | - else |
|
55 | - return self::$_output; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | private static function dumpInternal($var,$level) |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | self::$_output.='{unknown}'; |
82 | 82 | break; |
83 | 83 | case 'array': |
84 | - if(self::$_depth<=$level) |
|
85 | - self::$_output.='array(...)'; |
|
86 | - else if(empty($var)) |
|
87 | - self::$_output.='array()'; |
|
88 | - else |
|
84 | + if(self::$_depth<=$level) { |
|
85 | + self::$_output.='array(...)'; |
|
86 | + } else if(empty($var)) { |
|
87 | + self::$_output.='array()'; |
|
88 | + } else |
|
89 | 89 | { |
90 | 90 | $keys=array_keys($var); |
91 | 91 | $spaces=str_repeat(' ',$level*4); |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 'object': |
102 | - if(($id=array_search($var,self::$_objects,true))!==false) |
|
103 | - self::$_output.=get_class($var).'#'.($id+1).'(...)'; |
|
104 | - else if(self::$_depth<=$level) |
|
105 | - self::$_output.=get_class($var).'(...)'; |
|
106 | - else |
|
102 | + if(($id=array_search($var,self::$_objects,true))!==false) { |
|
103 | + self::$_output.=get_class($var).'#'.($id+1).'(...)'; |
|
104 | + } else if(self::$_depth<=$level) { |
|
105 | + self::$_output.=get_class($var).'(...)'; |
|
106 | + } else |
|
107 | 107 | { |
108 | 108 | $id=array_push(self::$_objects,$var); |
109 | 109 | $className=get_class($var); |
@@ -73,6 +73,9 @@ discard block |
||
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | + /** |
|
77 | + * @param integer $d |
|
78 | + */ |
|
76 | 79 | protected function action($d) { |
77 | 80 | switch($d) { |
78 | 81 | case 1: |
@@ -132,6 +135,9 @@ discard block |
||
132 | 135 | } |
133 | 136 | } |
134 | 137 | |
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
135 | 141 | protected function get() { |
136 | 142 | $c = $this->lookAhead; |
137 | 143 | $this->lookAhead = null; |
@@ -156,6 +162,9 @@ discard block |
||
156 | 162 | return ' '; |
157 | 163 | } |
158 | 164 | |
165 | + /** |
|
166 | + * @param string $c |
|
167 | + */ |
|
159 | 168 | protected function isAlphaNum($c) { |
160 | 169 | return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
161 | 170 | } |
@@ -60,229 +60,229 @@ |
||
60 | 60 | // -- Public Static Methods -------------------------------------------------- |
61 | 61 | |
62 | 62 | public static function minify($js) { |
63 | - $jsmin = new JSMin($js); |
|
64 | - return $jsmin->min(); |
|
63 | + $jsmin = new JSMin($js); |
|
64 | + return $jsmin->min(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // -- Public Instance Methods ------------------------------------------------ |
68 | 68 | |
69 | 69 | public function __construct($input) { |
70 | - $this->input = str_replace("\r\n", "\n", $input); |
|
71 | - $this->inputLength = strlen($this->input); |
|
70 | + $this->input = str_replace("\r\n", "\n", $input); |
|
71 | + $this->inputLength = strlen($this->input); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | 76 | protected function action($d) { |
77 | - switch($d) { |
|
78 | - case 1: |
|
79 | - $this->output .= $this->a; |
|
80 | - |
|
81 | - case 2: |
|
82 | - $this->a = $this->b; |
|
83 | - |
|
84 | - if ($this->a === "'" || $this->a === '"') { |
|
85 | - for (;;) { |
|
86 | - $this->output .= $this->a; |
|
87 | - $this->a = $this->get(); |
|
88 | - |
|
89 | - if ($this->a === $this->b) { |
|
90 | - break; |
|
91 | - } |
|
92 | - |
|
93 | - if (ord($this->a) <= self::ORD_LF) { |
|
94 | - throw new JSMinException('Unterminated string literal.'); |
|
95 | - } |
|
96 | - |
|
97 | - if ($this->a === '\\') { |
|
98 | - $this->output .= $this->a; |
|
99 | - $this->a = $this->get(); |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - case 3: |
|
105 | - $this->b = $this->next(); |
|
106 | - |
|
107 | - if ($this->b === '/' && ( |
|
108 | - $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | - $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | - $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
111 | - |
|
112 | - $this->output .= $this->a . $this->b; |
|
113 | - |
|
114 | - for (;;) { |
|
115 | - $this->a = $this->get(); |
|
116 | - |
|
117 | - if ($this->a === '/') { |
|
118 | - break; |
|
119 | - } elseif ($this->a === '\\') { |
|
120 | - $this->output .= $this->a; |
|
121 | - $this->a = $this->get(); |
|
122 | - } elseif (ord($this->a) <= self::ORD_LF) { |
|
123 | - throw new JSMinException('Unterminated regular expression '. |
|
124 | - 'literal.'); |
|
125 | - } |
|
126 | - |
|
127 | - $this->output .= $this->a; |
|
128 | - } |
|
129 | - |
|
130 | - $this->b = $this->next(); |
|
131 | - } |
|
132 | - } |
|
77 | + switch($d) { |
|
78 | + case 1: |
|
79 | + $this->output .= $this->a; |
|
80 | + |
|
81 | + case 2: |
|
82 | + $this->a = $this->b; |
|
83 | + |
|
84 | + if ($this->a === "'" || $this->a === '"') { |
|
85 | + for (;;) { |
|
86 | + $this->output .= $this->a; |
|
87 | + $this->a = $this->get(); |
|
88 | + |
|
89 | + if ($this->a === $this->b) { |
|
90 | + break; |
|
91 | + } |
|
92 | + |
|
93 | + if (ord($this->a) <= self::ORD_LF) { |
|
94 | + throw new JSMinException('Unterminated string literal.'); |
|
95 | + } |
|
96 | + |
|
97 | + if ($this->a === '\\') { |
|
98 | + $this->output .= $this->a; |
|
99 | + $this->a = $this->get(); |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + case 3: |
|
105 | + $this->b = $this->next(); |
|
106 | + |
|
107 | + if ($this->b === '/' && ( |
|
108 | + $this->a === '(' || $this->a === ',' || $this->a === '=' || |
|
109 | + $this->a === ':' || $this->a === '[' || $this->a === '!' || |
|
110 | + $this->a === '&' || $this->a === '|' || $this->a === '?')) { |
|
111 | + |
|
112 | + $this->output .= $this->a . $this->b; |
|
113 | + |
|
114 | + for (;;) { |
|
115 | + $this->a = $this->get(); |
|
116 | + |
|
117 | + if ($this->a === '/') { |
|
118 | + break; |
|
119 | + } elseif ($this->a === '\\') { |
|
120 | + $this->output .= $this->a; |
|
121 | + $this->a = $this->get(); |
|
122 | + } elseif (ord($this->a) <= self::ORD_LF) { |
|
123 | + throw new JSMinException('Unterminated regular expression '. |
|
124 | + 'literal.'); |
|
125 | + } |
|
126 | + |
|
127 | + $this->output .= $this->a; |
|
128 | + } |
|
129 | + |
|
130 | + $this->b = $this->next(); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | protected function get() { |
136 | - $c = $this->lookAhead; |
|
137 | - $this->lookAhead = null; |
|
138 | - |
|
139 | - if ($c === null) { |
|
140 | - if ($this->inputIndex < $this->inputLength) { |
|
141 | - $c = $this->input[$this->inputIndex]; |
|
142 | - $this->inputIndex += 1; |
|
143 | - } else { |
|
144 | - $c = null; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ($c === "\r") { |
|
149 | - return "\n"; |
|
150 | - } |
|
151 | - |
|
152 | - if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | - return $c; |
|
154 | - } |
|
155 | - |
|
156 | - return ' '; |
|
136 | + $c = $this->lookAhead; |
|
137 | + $this->lookAhead = null; |
|
138 | + |
|
139 | + if ($c === null) { |
|
140 | + if ($this->inputIndex < $this->inputLength) { |
|
141 | + $c = $this->input[$this->inputIndex]; |
|
142 | + $this->inputIndex += 1; |
|
143 | + } else { |
|
144 | + $c = null; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ($c === "\r") { |
|
149 | + return "\n"; |
|
150 | + } |
|
151 | + |
|
152 | + if ($c === null || $c === "\n" || ord($c) >= self::ORD_SPACE) { |
|
153 | + return $c; |
|
154 | + } |
|
155 | + |
|
156 | + return ' '; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | protected function isAlphaNum($c) { |
160 | - return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
160 | + return ord($c) > 126 || $c === '\\' || preg_match('/^[\w\$]$/', $c) === 1; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | protected function min() { |
164 | - $this->a = "\n"; |
|
165 | - $this->action(3); |
|
166 | - |
|
167 | - while ($this->a !== null) { |
|
168 | - switch ($this->a) { |
|
169 | - case ' ': |
|
170 | - if ($this->isAlphaNum($this->b)) { |
|
171 | - $this->action(1); |
|
172 | - } else { |
|
173 | - $this->action(2); |
|
174 | - } |
|
175 | - break; |
|
176 | - |
|
177 | - case "\n": |
|
178 | - switch ($this->b) { |
|
179 | - case '{': |
|
180 | - case '[': |
|
181 | - case '(': |
|
182 | - case '+': |
|
183 | - case '-': |
|
184 | - $this->action(1); |
|
185 | - break; |
|
186 | - |
|
187 | - case ' ': |
|
188 | - $this->action(3); |
|
189 | - break; |
|
190 | - |
|
191 | - default: |
|
192 | - if ($this->isAlphaNum($this->b)) { |
|
193 | - $this->action(1); |
|
194 | - } |
|
195 | - else { |
|
196 | - $this->action(2); |
|
197 | - } |
|
198 | - } |
|
199 | - break; |
|
200 | - |
|
201 | - default: |
|
202 | - switch ($this->b) { |
|
203 | - case ' ': |
|
204 | - if ($this->isAlphaNum($this->a)) { |
|
205 | - $this->action(1); |
|
206 | - break; |
|
207 | - } |
|
208 | - |
|
209 | - $this->action(3); |
|
210 | - break; |
|
211 | - |
|
212 | - case "\n": |
|
213 | - switch ($this->a) { |
|
214 | - case '}': |
|
215 | - case ']': |
|
216 | - case ')': |
|
217 | - case '+': |
|
218 | - case '-': |
|
219 | - case '"': |
|
220 | - case "'": |
|
221 | - $this->action(1); |
|
222 | - break; |
|
223 | - |
|
224 | - default: |
|
225 | - if ($this->isAlphaNum($this->a)) { |
|
226 | - $this->action(1); |
|
227 | - } |
|
228 | - else { |
|
229 | - $this->action(3); |
|
230 | - } |
|
231 | - } |
|
232 | - break; |
|
233 | - |
|
234 | - default: |
|
235 | - $this->action(1); |
|
236 | - break; |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - return $this->output; |
|
164 | + $this->a = "\n"; |
|
165 | + $this->action(3); |
|
166 | + |
|
167 | + while ($this->a !== null) { |
|
168 | + switch ($this->a) { |
|
169 | + case ' ': |
|
170 | + if ($this->isAlphaNum($this->b)) { |
|
171 | + $this->action(1); |
|
172 | + } else { |
|
173 | + $this->action(2); |
|
174 | + } |
|
175 | + break; |
|
176 | + |
|
177 | + case "\n": |
|
178 | + switch ($this->b) { |
|
179 | + case '{': |
|
180 | + case '[': |
|
181 | + case '(': |
|
182 | + case '+': |
|
183 | + case '-': |
|
184 | + $this->action(1); |
|
185 | + break; |
|
186 | + |
|
187 | + case ' ': |
|
188 | + $this->action(3); |
|
189 | + break; |
|
190 | + |
|
191 | + default: |
|
192 | + if ($this->isAlphaNum($this->b)) { |
|
193 | + $this->action(1); |
|
194 | + } |
|
195 | + else { |
|
196 | + $this->action(2); |
|
197 | + } |
|
198 | + } |
|
199 | + break; |
|
200 | + |
|
201 | + default: |
|
202 | + switch ($this->b) { |
|
203 | + case ' ': |
|
204 | + if ($this->isAlphaNum($this->a)) { |
|
205 | + $this->action(1); |
|
206 | + break; |
|
207 | + } |
|
208 | + |
|
209 | + $this->action(3); |
|
210 | + break; |
|
211 | + |
|
212 | + case "\n": |
|
213 | + switch ($this->a) { |
|
214 | + case '}': |
|
215 | + case ']': |
|
216 | + case ')': |
|
217 | + case '+': |
|
218 | + case '-': |
|
219 | + case '"': |
|
220 | + case "'": |
|
221 | + $this->action(1); |
|
222 | + break; |
|
223 | + |
|
224 | + default: |
|
225 | + if ($this->isAlphaNum($this->a)) { |
|
226 | + $this->action(1); |
|
227 | + } |
|
228 | + else { |
|
229 | + $this->action(3); |
|
230 | + } |
|
231 | + } |
|
232 | + break; |
|
233 | + |
|
234 | + default: |
|
235 | + $this->action(1); |
|
236 | + break; |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + return $this->output; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | protected function next() { |
245 | - $c = $this->get(); |
|
246 | - |
|
247 | - if ($c === '/') { |
|
248 | - switch($this->peek()) { |
|
249 | - case '/': |
|
250 | - for (;;) { |
|
251 | - $c = $this->get(); |
|
252 | - |
|
253 | - if (ord($c) <= self::ORD_LF) { |
|
254 | - return $c; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - case '*': |
|
259 | - $this->get(); |
|
260 | - |
|
261 | - for (;;) { |
|
262 | - switch($this->get()) { |
|
263 | - case '*': |
|
264 | - if ($this->peek() === '/') { |
|
265 | - $this->get(); |
|
266 | - return ' '; |
|
267 | - } |
|
268 | - break; |
|
269 | - |
|
270 | - case null: |
|
271 | - throw new JSMinException('Unterminated comment.'); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - default: |
|
276 | - return $c; |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - return $c; |
|
245 | + $c = $this->get(); |
|
246 | + |
|
247 | + if ($c === '/') { |
|
248 | + switch($this->peek()) { |
|
249 | + case '/': |
|
250 | + for (;;) { |
|
251 | + $c = $this->get(); |
|
252 | + |
|
253 | + if (ord($c) <= self::ORD_LF) { |
|
254 | + return $c; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + case '*': |
|
259 | + $this->get(); |
|
260 | + |
|
261 | + for (;;) { |
|
262 | + switch($this->get()) { |
|
263 | + case '*': |
|
264 | + if ($this->peek() === '/') { |
|
265 | + $this->get(); |
|
266 | + return ' '; |
|
267 | + } |
|
268 | + break; |
|
269 | + |
|
270 | + case null: |
|
271 | + throw new JSMinException('Unterminated comment.'); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + default: |
|
276 | + return $c; |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + return $c; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | protected function peek() { |
284 | - $this->lookAhead = $this->get(); |
|
285 | - return $this->lookAhead; |
|
284 | + $this->lookAhead = $this->get(); |
|
285 | + return $this->lookAhead; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | // -- Protected Instance Methods --------------------------------------------- |
75 | 75 | |
76 | 76 | protected function action($d) { |
77 | - switch($d) { |
|
77 | + switch ($d) { |
|
78 | 78 | case 1: |
79 | 79 | $this->output .= $this->a; |
80 | 80 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->output .= $this->a; |
121 | 121 | $this->a = $this->get(); |
122 | 122 | } elseif (ord($this->a) <= self::ORD_LF) { |
123 | - throw new JSMinException('Unterminated regular expression '. |
|
123 | + throw new JSMinException('Unterminated regular expression ' . |
|
124 | 124 | 'literal.'); |
125 | 125 | } |
126 | 126 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $c = $this->get(); |
246 | 246 | |
247 | 247 | if ($c === '/') { |
248 | - switch($this->peek()) { |
|
248 | + switch ($this->peek()) { |
|
249 | 249 | case '/': |
250 | 250 | for (;;) { |
251 | 251 | $c = $this->get(); |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $this->get(); |
260 | 260 | |
261 | 261 | for (;;) { |
262 | - switch($this->get()) { |
|
262 | + switch ($this->get()) { |
|
263 | 263 | case '*': |
264 | 264 | if ($this->peek() === '/') { |
265 | 265 | $this->get(); |
@@ -191,8 +191,7 @@ discard block |
||
191 | 191 | default: |
192 | 192 | if ($this->isAlphaNum($this->b)) { |
193 | 193 | $this->action(1); |
194 | - } |
|
195 | - else { |
|
194 | + } else { |
|
196 | 195 | $this->action(2); |
197 | 196 | } |
198 | 197 | } |
@@ -224,8 +223,7 @@ discard block |
||
224 | 223 | default: |
225 | 224 | if ($this->isAlphaNum($this->a)) { |
226 | 225 | $this->action(1); |
227 | - } |
|
228 | - else { |
|
226 | + } else { |
|
229 | 227 | $this->action(3); |
230 | 228 | } |
231 | 229 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | - * @return Marks a string as a javascript function. Once marke, the string is considered as a |
|
96 | + * @return TJavaScriptLiteral a string as a javascript function. Once marke, the string is considered as a |
|
97 | 97 | * raw javascript function that is not supposed to be encoded by {@link encode} |
98 | 98 | */ |
99 | 99 | public static function quoteJsLiteral($js) |
@@ -256,6 +256,7 @@ discard block |
||
256 | 256 | * @param string string to be decoded |
257 | 257 | * @param bool whether to convert returned objects to associative arrays |
258 | 258 | * @param int recursion depth |
259 | + * @param string $value |
|
259 | 260 | * @return mixed decoded variable |
260 | 261 | */ |
261 | 262 | public static function jsonDecode($value, $assoc = false, $depth = 512) |
@@ -298,7 +299,8 @@ discard block |
||
298 | 299 | * Minimize the size of a javascript script. |
299 | 300 | * This method is based on Douglas Crockford's JSMin. |
300 | 301 | * @param string code that you want to minimzie |
301 | - * @return minimized version of the code |
|
302 | + * @param string $code |
|
303 | + * @return string version of the code |
|
302 | 304 | */ |
303 | 305 | public static function JSMin($code) |
304 | 306 | { |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public static function renderScriptFiles($files) |
30 | 30 | { |
31 | - $str=''; |
|
32 | - foreach($files as $file) |
|
33 | - $str.= self::renderScriptFile($file); |
|
31 | + $str = ''; |
|
32 | + foreach ($files as $file) |
|
33 | + $str .= self::renderScriptFile($file); |
|
34 | 34 | return $str; |
35 | 35 | } |
36 | 36 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function renderScriptFile($file) |
43 | 43 | { |
44 | - return '<script type="text/javascript" src="'.THttpUtility::htmlEncode($file)."\"></script>\n"; |
|
44 | + return '<script type="text/javascript" src="' . THttpUtility::htmlEncode($file) . "\"></script>\n"; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public static function renderScriptBlocks($scripts) |
53 | 53 | { |
54 | - if(count($scripts)) |
|
55 | - return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
54 | + if (count($scripts)) |
|
55 | + return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n" . implode("\n", $scripts) . "\n/*]]>*/\n</script>\n"; |
|
56 | 56 | else |
57 | 57 | return ''; |
58 | 58 | } |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public static function renderScriptBlocksCallback($scripts) |
66 | 66 | { |
67 | - if(count($scripts)) |
|
68 | - return implode("\n",$scripts)."\n"; |
|
67 | + if (count($scripts)) |
|
68 | + return implode("\n", $scripts) . "\n"; |
|
69 | 69 | else |
70 | 70 | return ''; |
71 | 71 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public static function quoteString($js) |
91 | 91 | { |
92 | - return self::jsonEncode($js,JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); |
|
92 | + return self::jsonEncode($js, JSON_HEX_QUOT | JSON_HEX_APOS | JSON_HEX_TAG); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public static function quoteJsLiteral($js) |
100 | 100 | { |
101 | - if($js instanceof TJavaScriptLiteral) |
|
101 | + if ($js instanceof TJavaScriptLiteral) |
|
102 | 102 | return $js; |
103 | 103 | else |
104 | 104 | return new TJavaScriptLiteral($js); |
@@ -150,47 +150,47 @@ discard block |
||
150 | 150 | * @param boolean wether to encode empty strings too. Default to false for BC. |
151 | 151 | * @return string the encoded string |
152 | 152 | */ |
153 | - public static function encode($value,$toMap=true,$encodeEmptyStrings=false) |
|
153 | + public static function encode($value, $toMap = true, $encodeEmptyStrings = false) |
|
154 | 154 | { |
155 | - if(is_string($value)) |
|
155 | + if (is_string($value)) |
|
156 | 156 | return self::quoteString($value); |
157 | - else if(is_bool($value)) |
|
158 | - return $value?'true':'false'; |
|
159 | - else if(is_array($value)) |
|
157 | + else if (is_bool($value)) |
|
158 | + return $value ? 'true' : 'false'; |
|
159 | + else if (is_array($value)) |
|
160 | 160 | { |
161 | - $results=''; |
|
162 | - if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1)) |
|
161 | + $results = ''; |
|
162 | + if (($n = count($value)) > 0 && array_keys($value) !== range(0, $n - 1)) |
|
163 | 163 | { |
164 | - foreach($value as $k=>$v) |
|
164 | + foreach ($value as $k=>$v) |
|
165 | 165 | { |
166 | - if($v!=='' || $encodeEmptyStrings) |
|
166 | + if ($v !== '' || $encodeEmptyStrings) |
|
167 | 167 | { |
168 | - if($results!=='') |
|
169 | - $results.=','; |
|
170 | - $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings); |
|
168 | + if ($results !== '') |
|
169 | + $results .= ','; |
|
170 | + $results .= "'$k':" . self::encode($v, $toMap, $encodeEmptyStrings); |
|
171 | 171 | } |
172 | 172 | } |
173 | - return '{'.$results.'}'; |
|
173 | + return '{' . $results . '}'; |
|
174 | 174 | } |
175 | 175 | else |
176 | 176 | { |
177 | - foreach($value as $v) |
|
177 | + foreach ($value as $v) |
|
178 | 178 | { |
179 | - if($v!=='' || $encodeEmptyStrings) |
|
179 | + if ($v !== '' || $encodeEmptyStrings) |
|
180 | 180 | { |
181 | - if($results!=='') |
|
182 | - $results.=','; |
|
183 | - $results.=self::encode($v,$toMap, $encodeEmptyStrings); |
|
181 | + if ($results !== '') |
|
182 | + $results .= ','; |
|
183 | + $results .= self::encode($v, $toMap, $encodeEmptyStrings); |
|
184 | 184 | } |
185 | 185 | } |
186 | - return '['.$results.']'; |
|
186 | + return '[' . $results . ']'; |
|
187 | 187 | } |
188 | 188 | } |
189 | - else if(is_integer($value)) |
|
189 | + else if (is_integer($value)) |
|
190 | 190 | return "$value"; |
191 | - else if(is_float($value)) |
|
191 | + else if (is_float($value)) |
|
192 | 192 | { |
193 | - switch($value) |
|
193 | + switch ($value) |
|
194 | 194 | { |
195 | 195 | case -INF: |
196 | 196 | return 'Number.NEGATIVE_INFINITY'; |
@@ -199,20 +199,20 @@ discard block |
||
199 | 199 | return 'Number.POSITIVE_INFINITY'; |
200 | 200 | break; |
201 | 201 | default: |
202 | - $locale=localeConv(); |
|
203 | - if($locale['decimal_point']=='.') |
|
202 | + $locale = localeConv(); |
|
203 | + if ($locale['decimal_point'] == '.') |
|
204 | 204 | return "$value"; |
205 | 205 | else |
206 | 206 | return str_replace($locale['decimal_point'], '.', "$value"); |
207 | 207 | break; |
208 | 208 | } |
209 | 209 | } |
210 | - else if(is_object($value)) |
|
210 | + else if (is_object($value)) |
|
211 | 211 | if ($value instanceof TJavaScriptLiteral) |
212 | 212 | return $value->toJavaScriptLiteral(); |
213 | 213 | else |
214 | - return self::encode(get_object_vars($value),$toMap); |
|
215 | - else if($value===null) |
|
214 | + return self::encode(get_object_vars($value), $toMap); |
|
215 | + else if ($value === null) |
|
216 | 216 | return 'null'; |
217 | 217 | else |
218 | 218 | return ''; |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public static function jsonEncode($value, $options = 0) |
227 | 227 | { |
228 | - if (($g=Prado::getApplication()->getGlobalization(false))!==null && |
|
229 | - strtoupper($enc=$g->getCharset())!='UTF-8') { |
|
228 | + if (($g = Prado::getApplication()->getGlobalization(false)) !== null && |
|
229 | + strtoupper($enc = $g->getCharset()) != 'UTF-8') { |
|
230 | 230 | self::convertToUtf8($value, $enc); |
231 | 231 | } |
232 | 232 | |
233 | - $s = @json_encode($value,$options); |
|
233 | + $s = @json_encode($value, $options); |
|
234 | 234 | self::checkJsonError(); |
235 | 235 | return $s; |
236 | 236 | } |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | * @param string $sourceEncoding |
242 | 242 | */ |
243 | 243 | private static function convertToUtf8(&$value, $sourceEncoding) { |
244 | - if(is_string($value)) |
|
245 | - $value=iconv($sourceEncoding, 'UTF-8', $value); |
|
244 | + if (is_string($value)) |
|
245 | + $value = iconv($sourceEncoding, 'UTF-8', $value); |
|
246 | 246 | else if (is_array($value)) |
247 | 247 | { |
248 | - foreach($value as &$element) |
|
248 | + foreach ($value as &$element) |
|
249 | 249 | self::convertToUtf8($element, $sourceEncoding); |
250 | 250 | } |
251 | 251 | } |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public static function jsonDecode($value, $assoc = false, $depth = 512) |
262 | 262 | { |
263 | - $s= @json_decode($value, $assoc, $depth); |
|
263 | + $s = @json_decode($value, $assoc, $depth); |
|
264 | 264 | self::checkJsonError(); |
265 | 265 | return $s; |
266 | 266 | } |
@@ -29,8 +29,9 @@ discard block |
||
29 | 29 | public static function renderScriptFiles($files) |
30 | 30 | { |
31 | 31 | $str=''; |
32 | - foreach($files as $file) |
|
33 | - $str.= self::renderScriptFile($file); |
|
32 | + foreach($files as $file) { |
|
33 | + $str.= self::renderScriptFile($file); |
|
34 | + } |
|
34 | 35 | return $str; |
35 | 36 | } |
36 | 37 | |
@@ -51,10 +52,11 @@ discard block |
||
51 | 52 | */ |
52 | 53 | public static function renderScriptBlocks($scripts) |
53 | 54 | { |
54 | - if(count($scripts)) |
|
55 | - return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
56 | - else |
|
57 | - return ''; |
|
55 | + if(count($scripts)) { |
|
56 | + return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n".implode("\n",$scripts)."\n/*]]>*/\n</script>\n"; |
|
57 | + } else { |
|
58 | + return ''; |
|
59 | + } |
|
58 | 60 | } |
59 | 61 | |
60 | 62 | /** |
@@ -64,10 +66,11 @@ discard block |
||
64 | 66 | */ |
65 | 67 | public static function renderScriptBlocksCallback($scripts) |
66 | 68 | { |
67 | - if(count($scripts)) |
|
68 | - return implode("\n",$scripts)."\n"; |
|
69 | - else |
|
70 | - return ''; |
|
69 | + if(count($scripts)) { |
|
70 | + return implode("\n",$scripts)."\n"; |
|
71 | + } else { |
|
72 | + return ''; |
|
73 | + } |
|
71 | 74 | } |
72 | 75 | |
73 | 76 | /** |
@@ -98,10 +101,11 @@ discard block |
||
98 | 101 | */ |
99 | 102 | public static function quoteJsLiteral($js) |
100 | 103 | { |
101 | - if($js instanceof TJavaScriptLiteral) |
|
102 | - return $js; |
|
103 | - else |
|
104 | - return new TJavaScriptLiteral($js); |
|
104 | + if($js instanceof TJavaScriptLiteral) { |
|
105 | + return $js; |
|
106 | + } else { |
|
107 | + return new TJavaScriptLiteral($js); |
|
108 | + } |
|
105 | 109 | } |
106 | 110 | |
107 | 111 | /** |
@@ -152,11 +156,11 @@ discard block |
||
152 | 156 | */ |
153 | 157 | public static function encode($value,$toMap=true,$encodeEmptyStrings=false) |
154 | 158 | { |
155 | - if(is_string($value)) |
|
156 | - return self::quoteString($value); |
|
157 | - else if(is_bool($value)) |
|
158 | - return $value?'true':'false'; |
|
159 | - else if(is_array($value)) |
|
159 | + if(is_string($value)) { |
|
160 | + return self::quoteString($value); |
|
161 | + } else if(is_bool($value)) { |
|
162 | + return $value?'true':'false'; |
|
163 | + } else if(is_array($value)) |
|
160 | 164 | { |
161 | 165 | $results=''; |
162 | 166 | if(($n=count($value))>0 && array_keys($value)!==range(0,$n-1)) |
@@ -165,30 +169,30 @@ discard block |
||
165 | 169 | { |
166 | 170 | if($v!=='' || $encodeEmptyStrings) |
167 | 171 | { |
168 | - if($results!=='') |
|
169 | - $results.=','; |
|
172 | + if($results!=='') { |
|
173 | + $results.=','; |
|
174 | + } |
|
170 | 175 | $results.="'$k':".self::encode($v,$toMap,$encodeEmptyStrings); |
171 | 176 | } |
172 | 177 | } |
173 | 178 | return '{'.$results.'}'; |
174 | - } |
|
175 | - else |
|
179 | + } else |
|
176 | 180 | { |
177 | 181 | foreach($value as $v) |
178 | 182 | { |
179 | 183 | if($v!=='' || $encodeEmptyStrings) |
180 | 184 | { |
181 | - if($results!=='') |
|
182 | - $results.=','; |
|
185 | + if($results!=='') { |
|
186 | + $results.=','; |
|
187 | + } |
|
183 | 188 | $results.=self::encode($v,$toMap, $encodeEmptyStrings); |
184 | 189 | } |
185 | 190 | } |
186 | 191 | return '['.$results.']'; |
187 | 192 | } |
188 | - } |
|
189 | - else if(is_integer($value)) |
|
190 | - return "$value"; |
|
191 | - else if(is_float($value)) |
|
193 | + } else if(is_integer($value)) { |
|
194 | + return "$value"; |
|
195 | + } else if(is_float($value)) |
|
192 | 196 | { |
193 | 197 | switch($value) |
194 | 198 | { |
@@ -200,22 +204,24 @@ discard block |
||
200 | 204 | break; |
201 | 205 | default: |
202 | 206 | $locale=localeConv(); |
203 | - if($locale['decimal_point']=='.') |
|
204 | - return "$value"; |
|
205 | - else |
|
206 | - return str_replace($locale['decimal_point'], '.', "$value"); |
|
207 | + if($locale['decimal_point']=='.') { |
|
208 | + return "$value"; |
|
209 | + } else { |
|
210 | + return str_replace($locale['decimal_point'], '.', "$value"); |
|
211 | + } |
|
207 | 212 | break; |
208 | 213 | } |
209 | - } |
|
210 | - else if(is_object($value)) |
|
211 | - if ($value instanceof TJavaScriptLiteral) |
|
214 | + } else if(is_object($value)) { |
|
215 | + if ($value instanceof TJavaScriptLiteral) |
|
212 | 216 | return $value->toJavaScriptLiteral(); |
213 | - else |
|
214 | - return self::encode(get_object_vars($value),$toMap); |
|
215 | - else if($value===null) |
|
216 | - return 'null'; |
|
217 | - else |
|
218 | - return ''; |
|
217 | + } else { |
|
218 | + return self::encode(get_object_vars($value),$toMap); |
|
219 | + } |
|
220 | + else if($value===null) { |
|
221 | + return 'null'; |
|
222 | + } else { |
|
223 | + return ''; |
|
224 | + } |
|
219 | 225 | } |
220 | 226 | /** |
221 | 227 | * Encodes a PHP variable into javascript string. |
@@ -241,12 +247,13 @@ discard block |
||
241 | 247 | * @param string $sourceEncoding |
242 | 248 | */ |
243 | 249 | private static function convertToUtf8(&$value, $sourceEncoding) { |
244 | - if(is_string($value)) |
|
245 | - $value=iconv($sourceEncoding, 'UTF-8', $value); |
|
246 | - else if (is_array($value)) |
|
250 | + if(is_string($value)) { |
|
251 | + $value=iconv($sourceEncoding, 'UTF-8', $value); |
|
252 | + } else if (is_array($value)) |
|
247 | 253 | { |
248 | - foreach($value as &$element) |
|
249 | - self::convertToUtf8($element, $sourceEncoding); |
|
254 | + foreach($value as &$element) { |
|
255 | + self::convertToUtf8($element, $sourceEncoding); |
|
256 | + } |
|
250 | 257 | } |
251 | 258 | } |
252 | 259 |
@@ -140,6 +140,7 @@ |
||
140 | 140 | /** |
141 | 141 | * Renders content provided by TJsonResponse::getJsonContent() as |
142 | 142 | * javascript in JSON format. |
143 | + * @param TJsonResponse $service |
|
143 | 144 | */ |
144 | 145 | protected function createJsonResponse($service,$properties,$config) |
145 | 146 | { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * @var array registered services |
56 | 56 | */ |
57 | - private $_services=array(); |
|
57 | + private $_services = array(); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Initializes this module. |
@@ -72,20 +72,20 @@ discard block |
||
72 | 72 | */ |
73 | 73 | protected function loadJsonServices($config) |
74 | 74 | { |
75 | - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
75 | + if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
76 | 76 | { |
77 | - if(is_array($config)) |
|
77 | + if (is_array($config)) |
|
78 | 78 | { |
79 | - foreach($config['json'] as $id => $json) |
|
79 | + foreach ($config['json'] as $id => $json) |
|
80 | 80 | $this->_services[$id] = $json; |
81 | 81 | } |
82 | 82 | } |
83 | 83 | else |
84 | 84 | { |
85 | - foreach($config->getElementsByTagName('json') as $json) |
|
85 | + foreach ($config->getElementsByTagName('json') as $json) |
|
86 | 86 | { |
87 | - if(($id=$json->getAttribute('id'))!==null) |
|
88 | - $this->_services[$id]=$json; |
|
87 | + if (($id = $json->getAttribute('id')) !== null) |
|
88 | + $this->_services[$id] = $json; |
|
89 | 89 | else |
90 | 90 | throw new TConfigurationException('jsonservice_id_required'); |
91 | 91 | } |
@@ -98,58 +98,58 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function run() |
100 | 100 | { |
101 | - $id=$this->getRequest()->getServiceParameter(); |
|
102 | - if(isset($this->_services[$id])) |
|
101 | + $id = $this->getRequest()->getServiceParameter(); |
|
102 | + if (isset($this->_services[$id])) |
|
103 | 103 | { |
104 | - $serviceConfig=$this->_services[$id]; |
|
105 | - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
104 | + $serviceConfig = $this->_services[$id]; |
|
105 | + if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
106 | 106 | { |
107 | - if(isset($serviceConfig['class'])) |
|
107 | + if (isset($serviceConfig['class'])) |
|
108 | 108 | { |
109 | - $service=Prado::createComponent($serviceConfig['class']); |
|
110 | - if($service instanceof TJsonResponse) |
|
109 | + $service = Prado::createComponent($serviceConfig['class']); |
|
110 | + if ($service instanceof TJsonResponse) |
|
111 | 111 | { |
112 | - $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); |
|
113 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
112 | + $properties = isset($serviceConfig['properties']) ? $serviceConfig['properties'] : array(); |
|
113 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
114 | 114 | } |
115 | 115 | else |
116 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
116 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
117 | 117 | } |
118 | 118 | else |
119 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
119 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
120 | 120 | } |
121 | 121 | else |
122 | 122 | { |
123 | - $properties=$serviceConfig->getAttributes(); |
|
124 | - if(($class=$properties->remove('class'))!==null) |
|
123 | + $properties = $serviceConfig->getAttributes(); |
|
124 | + if (($class = $properties->remove('class')) !== null) |
|
125 | 125 | { |
126 | - $service=Prado::createComponent($class); |
|
127 | - if($service instanceof TJsonResponse) |
|
128 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
126 | + $service = Prado::createComponent($class); |
|
127 | + if ($service instanceof TJsonResponse) |
|
128 | + $this->createJsonResponse($service, $properties, $serviceConfig); |
|
129 | 129 | else |
130 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
130 | + throw new TConfigurationException('jsonservice_response_type_invalid', $id); |
|
131 | 131 | } |
132 | 132 | else |
133 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
133 | + throw new TConfigurationException('jsonservice_class_required', $id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | else |
137 | - throw new THttpException(404,'jsonservice_provider_unknown',$id); |
|
137 | + throw new THttpException(404, 'jsonservice_provider_unknown', $id); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Renders content provided by TJsonResponse::getJsonContent() as |
142 | 142 | * javascript in JSON format. |
143 | 143 | */ |
144 | - protected function createJsonResponse($service,$properties,$config) |
|
144 | + protected function createJsonResponse($service, $properties, $config) |
|
145 | 145 | { |
146 | 146 | // init service properties |
147 | - foreach($properties as $name=>$value) |
|
148 | - $service->setSubproperty($name,$value); |
|
147 | + foreach ($properties as $name=>$value) |
|
148 | + $service->setSubproperty($name, $value); |
|
149 | 149 | $service->init($config); |
150 | 150 | |
151 | 151 | //send content if not null |
152 | - if(($content=$service->getJsonContent())!==null) |
|
152 | + if (($content = $service->getJsonContent()) !== null) |
|
153 | 153 | { |
154 | 154 | $response = $this->getResponse(); |
155 | 155 | $response->setContentType('application/json'); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | abstract class TJsonResponse extends TApplicationComponent |
177 | 177 | { |
178 | - private $_id=''; |
|
178 | + private $_id = ''; |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Initializes the feed. |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function setID($value) |
200 | 200 | { |
201 | - $this->_id=$value; |
|
201 | + $this->_id = $value; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -76,18 +76,19 @@ discard block |
||
76 | 76 | { |
77 | 77 | if(is_array($config)) |
78 | 78 | { |
79 | - foreach($config['json'] as $id => $json) |
|
80 | - $this->_services[$id] = $json; |
|
79 | + foreach($config['json'] as $id => $json) { |
|
80 | + $this->_services[$id] = $json; |
|
81 | + } |
|
81 | 82 | } |
82 | - } |
|
83 | - else |
|
83 | + } else |
|
84 | 84 | { |
85 | 85 | foreach($config->getElementsByTagName('json') as $json) |
86 | 86 | { |
87 | - if(($id=$json->getAttribute('id'))!==null) |
|
88 | - $this->_services[$id]=$json; |
|
89 | - else |
|
90 | - throw new TConfigurationException('jsonservice_id_required'); |
|
87 | + if(($id=$json->getAttribute('id'))!==null) { |
|
88 | + $this->_services[$id]=$json; |
|
89 | + } else { |
|
90 | + throw new TConfigurationException('jsonservice_id_required'); |
|
91 | + } |
|
91 | 92 | } |
92 | 93 | } |
93 | 94 | } |
@@ -111,30 +112,30 @@ discard block |
||
111 | 112 | { |
112 | 113 | $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); |
113 | 114 | $this->createJsonResponse($service,$properties,$serviceConfig); |
115 | + } else { |
|
116 | + throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
114 | 117 | } |
115 | - else |
|
116 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
118 | + } else { |
|
119 | + throw new TConfigurationException('jsonservice_class_required',$id); |
|
117 | 120 | } |
118 | - else |
|
119 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
120 | - } |
|
121 | - else |
|
121 | + } else |
|
122 | 122 | { |
123 | 123 | $properties=$serviceConfig->getAttributes(); |
124 | 124 | if(($class=$properties->remove('class'))!==null) |
125 | 125 | { |
126 | 126 | $service=Prado::createComponent($class); |
127 | - if($service instanceof TJsonResponse) |
|
128 | - $this->createJsonResponse($service,$properties,$serviceConfig); |
|
129 | - else |
|
130 | - throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
127 | + if($service instanceof TJsonResponse) { |
|
128 | + $this->createJsonResponse($service,$properties,$serviceConfig); |
|
129 | + } else { |
|
130 | + throw new TConfigurationException('jsonservice_response_type_invalid',$id); |
|
131 | + } |
|
132 | + } else { |
|
133 | + throw new TConfigurationException('jsonservice_class_required',$id); |
|
131 | 134 | } |
132 | - else |
|
133 | - throw new TConfigurationException('jsonservice_class_required',$id); |
|
134 | 135 | } |
136 | + } else { |
|
137 | + throw new THttpException(404,'jsonservice_provider_unknown',$id); |
|
135 | 138 | } |
136 | - else |
|
137 | - throw new THttpException(404,'jsonservice_provider_unknown',$id); |
|
138 | 139 | } |
139 | 140 | |
140 | 141 | /** |
@@ -144,8 +145,9 @@ discard block |
||
144 | 145 | protected function createJsonResponse($service,$properties,$config) |
145 | 146 | { |
146 | 147 | // init service properties |
147 | - foreach($properties as $name=>$value) |
|
148 | - $service->setSubproperty($name,$value); |
|
148 | + foreach($properties as $name=>$value) { |
|
149 | + $service->setSubproperty($name,$value); |
|
150 | + } |
|
149 | 151 | $service->init($config); |
150 | 152 | |
151 | 153 | //send content if not null |
@@ -369,6 +369,7 @@ discard block |
||
369 | 369 | |
370 | 370 | /** |
371 | 371 | * @param string default page path to be served if no explicit page is request |
372 | + * @param string $value |
|
372 | 373 | * @throws TInvalidOperationException if the page service is initialized |
373 | 374 | */ |
374 | 375 | public function setDefaultPage($value) |
@@ -528,6 +529,7 @@ discard block |
||
528 | 529 | * @param array list of GET parameters, null if no GET parameters required |
529 | 530 | * @param boolean whether to encode the ampersand in URL, defaults to true. |
530 | 531 | * @param boolean whether to encode the GET parameters (their names and values), defaults to true. |
532 | + * @param string $pagePath |
|
531 | 533 | * @return string URL for the page and GET parameters |
532 | 534 | */ |
533 | 535 | public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true) |
@@ -670,6 +672,9 @@ discard block |
||
670 | 672 | } |
671 | 673 | } |
672 | 674 | |
675 | + /** |
|
676 | + * @param string $configPath |
|
677 | + */ |
|
673 | 678 | public function loadFromPhp($config,$configPath,$configPagePath) |
674 | 679 | { |
675 | 680 | $this->loadApplicationConfigurationFromPhp($config,$configPath); |
@@ -683,6 +688,8 @@ discard block |
||
683 | 688 | * @param TXmlElement config xml element |
684 | 689 | * @param string the directory containing this configuration |
685 | 690 | * @param string the page path that the config XML is associated with. The page path doesn't include the page name. |
691 | + * @param TXmlDocument $dom |
|
692 | + * @param string $configPath |
|
686 | 693 | */ |
687 | 694 | public function loadFromXml($dom,$configPath,$configPagePath) |
688 | 695 | { |
@@ -77,68 +77,68 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * Configuration file name |
79 | 79 | */ |
80 | - const CONFIG_FILE_XML='config.xml'; |
|
80 | + const CONFIG_FILE_XML = 'config.xml'; |
|
81 | 81 | /** |
82 | 82 | * Configuration file name |
83 | 83 | */ |
84 | - const CONFIG_FILE_PHP='config.php'; |
|
84 | + const CONFIG_FILE_PHP = 'config.php'; |
|
85 | 85 | /** |
86 | 86 | * Default base path |
87 | 87 | */ |
88 | - const DEFAULT_BASEPATH='Pages'; |
|
88 | + const DEFAULT_BASEPATH = 'Pages'; |
|
89 | 89 | /** |
90 | 90 | * Fallback base path - used to be the default up to Prado < 3.2 |
91 | 91 | */ |
92 | - const FALLBACK_BASEPATH='pages'; |
|
92 | + const FALLBACK_BASEPATH = 'pages'; |
|
93 | 93 | /** |
94 | 94 | * Prefix of ID used for storing parsed configuration in cache |
95 | 95 | */ |
96 | - const CONFIG_CACHE_PREFIX='prado:pageservice:'; |
|
96 | + const CONFIG_CACHE_PREFIX = 'prado:pageservice:'; |
|
97 | 97 | /** |
98 | 98 | * Page template file extension |
99 | 99 | */ |
100 | - const PAGE_FILE_EXT='.page'; |
|
100 | + const PAGE_FILE_EXT = '.page'; |
|
101 | 101 | /** |
102 | 102 | * @var string root path of pages |
103 | 103 | */ |
104 | - private $_basePath=null; |
|
104 | + private $_basePath = null; |
|
105 | 105 | /** |
106 | 106 | * @var string base path class in namespace format |
107 | 107 | */ |
108 | - private $_basePageClass='TPage'; |
|
108 | + private $_basePageClass = 'TPage'; |
|
109 | 109 | /** |
110 | 110 | * @var string clientscript manager class in namespace format |
111 | 111 | * @since 3.1.7 |
112 | 112 | */ |
113 | - private $_clientScriptManagerClass='System.Web.UI.TClientScriptManager'; |
|
113 | + private $_clientScriptManagerClass = 'System.Web.UI.TClientScriptManager'; |
|
114 | 114 | /** |
115 | 115 | * @var string default page |
116 | 116 | */ |
117 | - private $_defaultPage='Home'; |
|
117 | + private $_defaultPage = 'Home'; |
|
118 | 118 | /** |
119 | 119 | * @var string requested page (path) |
120 | 120 | */ |
121 | - private $_pagePath=null; |
|
121 | + private $_pagePath = null; |
|
122 | 122 | /** |
123 | 123 | * @var TPage the requested page |
124 | 124 | */ |
125 | - private $_page=null; |
|
125 | + private $_page = null; |
|
126 | 126 | /** |
127 | 127 | * @var array list of initial page property values |
128 | 128 | */ |
129 | - private $_properties=array(); |
|
129 | + private $_properties = array(); |
|
130 | 130 | /** |
131 | 131 | * @var boolean whether service is initialized |
132 | 132 | */ |
133 | - private $_initialized=false; |
|
133 | + private $_initialized = false; |
|
134 | 134 | /** |
135 | 135 | * @var TThemeManager theme manager |
136 | 136 | */ |
137 | - private $_themeManager=null; |
|
137 | + private $_themeManager = null; |
|
138 | 138 | /** |
139 | 139 | * @var TTemplateManager template manager |
140 | 140 | */ |
141 | - private $_templateManager=null; |
|
141 | + private $_templateManager = null; |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Initializes the service. |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function init($config) |
149 | 149 | { |
150 | - Prado::trace("Initializing TPageService",'System.Web.Services.TPageService'); |
|
150 | + Prado::trace("Initializing TPageService", 'System.Web.Services.TPageService'); |
|
151 | 151 | |
152 | - $pageConfig=$this->loadPageConfig($config); |
|
152 | + $pageConfig = $this->loadPageConfig($config); |
|
153 | 153 | |
154 | 154 | $this->initPageContext($pageConfig); |
155 | 155 | |
156 | - $this->_initialized=true; |
|
156 | + $this->_initialized = true; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected function initPageContext($pageConfig) |
167 | 167 | { |
168 | - $application=$this->getApplication(); |
|
169 | - foreach($pageConfig->getApplicationConfigurations() as $appConfig) |
|
168 | + $application = $this->getApplication(); |
|
169 | + foreach ($pageConfig->getApplicationConfigurations() as $appConfig) |
|
170 | 170 | $application->applyConfiguration($appConfig); |
171 | 171 | |
172 | 172 | $this->applyConfiguration($pageConfig); |
@@ -179,21 +179,21 @@ discard block |
||
179 | 179 | protected function applyConfiguration($config) |
180 | 180 | { |
181 | 181 | // initial page properties (to be set when page runs) |
182 | - $this->_properties=array_merge($this->_properties, $config->getProperties()); |
|
182 | + $this->_properties = array_merge($this->_properties, $config->getProperties()); |
|
183 | 183 | $this->getApplication()->getAuthorizationRules()->mergeWith($config->getRules()); |
184 | - $pagePath=$this->getRequestedPagePath(); |
|
184 | + $pagePath = $this->getRequestedPagePath(); |
|
185 | 185 | // external configurations |
186 | - foreach($config->getExternalConfigurations() as $filePath=>$params) |
|
186 | + foreach ($config->getExternalConfigurations() as $filePath=>$params) |
|
187 | 187 | { |
188 | - list($configPagePath,$condition)=$params; |
|
189 | - if($condition!==true) |
|
190 | - $condition=$this->evaluateExpression($condition); |
|
191 | - if($condition) |
|
188 | + list($configPagePath, $condition) = $params; |
|
189 | + if ($condition !== true) |
|
190 | + $condition = $this->evaluateExpression($condition); |
|
191 | + if ($condition) |
|
192 | 192 | { |
193 | - if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) |
|
194 | - throw new TConfigurationException('pageservice_includefile_invalid',$filePath); |
|
195 | - $c=new TPageConfiguration($pagePath); |
|
196 | - $c->loadFromFile($path,$configPagePath); |
|
193 | + if (($path = Prado::getPathOfNamespace($filePath, Prado::getApplication()->getConfigurationFileExt())) === null || !is_file($path)) |
|
194 | + throw new TConfigurationException('pageservice_includefile_invalid', $filePath); |
|
195 | + $c = new TPageConfiguration($pagePath); |
|
196 | + $c->loadFromFile($path, $configPagePath); |
|
197 | 197 | $this->applyConfiguration($c); |
198 | 198 | } |
199 | 199 | } |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | */ |
207 | 207 | protected function determineRequestedPagePath() |
208 | 208 | { |
209 | - $pagePath=$this->getRequest()->getServiceParameter(); |
|
210 | - if(empty($pagePath)) |
|
211 | - $pagePath=$this->getDefaultPage(); |
|
209 | + $pagePath = $this->getRequest()->getServiceParameter(); |
|
210 | + if (empty($pagePath)) |
|
211 | + $pagePath = $this->getDefaultPage(); |
|
212 | 212 | return $pagePath; |
213 | 213 | } |
214 | 214 | |
@@ -219,77 +219,77 @@ discard block |
||
219 | 219 | */ |
220 | 220 | protected function loadPageConfig($config) |
221 | 221 | { |
222 | - $application=$this->getApplication(); |
|
223 | - $pagePath=$this->getRequestedPagePath(); |
|
224 | - if(($cache=$application->getCache())===null) |
|
222 | + $application = $this->getApplication(); |
|
223 | + $pagePath = $this->getRequestedPagePath(); |
|
224 | + if (($cache = $application->getCache()) === null) |
|
225 | 225 | { |
226 | - $pageConfig=new TPageConfiguration($pagePath); |
|
227 | - if($config!==null) |
|
226 | + $pageConfig = new TPageConfiguration($pagePath); |
|
227 | + if ($config !== null) |
|
228 | 228 | { |
229 | - if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
230 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
229 | + if ($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
230 | + $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
231 | 231 | else |
232 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
232 | + $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
233 | 233 | } |
234 | 234 | $pageConfig->loadFromFiles($this->getBasePath()); |
235 | 235 | } |
236 | 236 | else |
237 | 237 | { |
238 | - $configCached=true; |
|
239 | - $currentTimestamp=array(); |
|
240 | - $arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath); |
|
241 | - if(is_array($arr)) |
|
238 | + $configCached = true; |
|
239 | + $currentTimestamp = array(); |
|
240 | + $arr = $cache->get(self::CONFIG_CACHE_PREFIX . $this->getID() . $pagePath); |
|
241 | + if (is_array($arr)) |
|
242 | 242 | { |
243 | - list($pageConfig,$timestamps)=$arr; |
|
244 | - if($application->getMode()!==TApplicationMode::Performance) |
|
243 | + list($pageConfig, $timestamps) = $arr; |
|
244 | + if ($application->getMode() !== TApplicationMode::Performance) |
|
245 | 245 | { |
246 | - foreach($timestamps as $fileName=>$timestamp) |
|
246 | + foreach ($timestamps as $fileName=>$timestamp) |
|
247 | 247 | { |
248 | - if($fileName===0) // application config file |
|
248 | + if ($fileName === 0) // application config file |
|
249 | 249 | { |
250 | - $appConfigFile=$application->getConfigurationFile(); |
|
251 | - $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
|
252 | - if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) |
|
253 | - $configCached=false; |
|
250 | + $appConfigFile = $application->getConfigurationFile(); |
|
251 | + $currentTimestamp[0] = $appConfigFile === null ? 0 : @filemtime($appConfigFile); |
|
252 | + if ($currentTimestamp[0] > $timestamp || ($timestamp > 0 && !$currentTimestamp[0])) |
|
253 | + $configCached = false; |
|
254 | 254 | } |
255 | 255 | else |
256 | 256 | { |
257 | - $currentTimestamp[$fileName]=@filemtime($fileName); |
|
258 | - if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) |
|
259 | - $configCached=false; |
|
257 | + $currentTimestamp[$fileName] = @filemtime($fileName); |
|
258 | + if ($currentTimestamp[$fileName] > $timestamp || ($timestamp > 0 && !$currentTimestamp[$fileName])) |
|
259 | + $configCached = false; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
263 | 263 | } |
264 | 264 | else |
265 | 265 | { |
266 | - $configCached=false; |
|
267 | - $paths=explode('.',$pagePath); |
|
268 | - $configPath=$this->getBasePath(); |
|
269 | - $fileName = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP |
|
266 | + $configCached = false; |
|
267 | + $paths = explode('.', $pagePath); |
|
268 | + $configPath = $this->getBasePath(); |
|
269 | + $fileName = $this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP |
|
270 | 270 | ? self::CONFIG_FILE_PHP |
271 | 271 | : self::CONFIG_FILE_XML; |
272 | - foreach($paths as $path) |
|
272 | + foreach ($paths as $path) |
|
273 | 273 | { |
274 | - $configFile=$configPath.DIRECTORY_SEPARATOR.$fileName; |
|
275 | - $currentTimestamp[$configFile]=@filemtime($configFile); |
|
276 | - $configPath.=DIRECTORY_SEPARATOR.$path; |
|
274 | + $configFile = $configPath . DIRECTORY_SEPARATOR . $fileName; |
|
275 | + $currentTimestamp[$configFile] = @filemtime($configFile); |
|
276 | + $configPath .= DIRECTORY_SEPARATOR . $path; |
|
277 | 277 | } |
278 | - $appConfigFile=$application->getConfigurationFile(); |
|
279 | - $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
|
278 | + $appConfigFile = $application->getConfigurationFile(); |
|
279 | + $currentTimestamp[0] = $appConfigFile === null ? 0 : @filemtime($appConfigFile); |
|
280 | 280 | } |
281 | - if(!$configCached) |
|
281 | + if (!$configCached) |
|
282 | 282 | { |
283 | - $pageConfig=new TPageConfiguration($pagePath); |
|
284 | - if($config!==null) |
|
283 | + $pageConfig = new TPageConfiguration($pagePath); |
|
284 | + if ($config !== null) |
|
285 | 285 | { |
286 | - if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
287 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
286 | + if ($application->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
287 | + $pageConfig->loadPageConfigurationFromPhp($config, $application->getBasePath(), ''); |
|
288 | 288 | else |
289 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
289 | + $pageConfig->loadPageConfigurationFromXml($config, $application->getBasePath(), ''); |
|
290 | 290 | } |
291 | 291 | $pageConfig->loadFromFiles($this->getBasePath()); |
292 | - $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp)); |
|
292 | + $cache->set(self::CONFIG_CACHE_PREFIX . $this->getID() . $pagePath, array($pageConfig, $currentTimestamp)); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | return $pageConfig; |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function getTemplateManager() |
302 | 302 | { |
303 | - if(!$this->_templateManager) |
|
303 | + if (!$this->_templateManager) |
|
304 | 304 | { |
305 | - $this->_templateManager=new TTemplateManager; |
|
305 | + $this->_templateManager = new TTemplateManager; |
|
306 | 306 | $this->_templateManager->init(null); |
307 | 307 | } |
308 | 308 | return $this->_templateManager; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function setTemplateManager(TTemplateManager $value) |
315 | 315 | { |
316 | - $this->_templateManager=$value; |
|
316 | + $this->_templateManager = $value; |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function getThemeManager() |
323 | 323 | { |
324 | - if(!$this->_themeManager) |
|
324 | + if (!$this->_themeManager) |
|
325 | 325 | { |
326 | - $this->_themeManager=new TThemeManager; |
|
326 | + $this->_themeManager = new TThemeManager; |
|
327 | 327 | $this->_themeManager->init(null); |
328 | 328 | } |
329 | 329 | return $this->_themeManager; |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | */ |
335 | 335 | public function setThemeManager(TThemeManager $value) |
336 | 336 | { |
337 | - $this->_themeManager=$value; |
|
337 | + $this->_themeManager = $value; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -342,11 +342,11 @@ discard block |
||
342 | 342 | */ |
343 | 343 | public function getRequestedPagePath() |
344 | 344 | { |
345 | - if($this->_pagePath===null) |
|
345 | + if ($this->_pagePath === null) |
|
346 | 346 | { |
347 | - $this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..'); |
|
348 | - if(empty($this->_pagePath)) |
|
349 | - throw new THttpException(404,'pageservice_page_required'); |
|
347 | + $this->_pagePath = strtr($this->determineRequestedPagePath(), '/\\', '..'); |
|
348 | + if (empty($this->_pagePath)) |
|
349 | + throw new THttpException(404, 'pageservice_page_required'); |
|
350 | 350 | } |
351 | 351 | return $this->_pagePath; |
352 | 352 | } |
@@ -373,10 +373,10 @@ discard block |
||
373 | 373 | */ |
374 | 374 | public function setDefaultPage($value) |
375 | 375 | { |
376 | - if($this->_initialized) |
|
376 | + if ($this->_initialized) |
|
377 | 377 | throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
378 | 378 | else |
379 | - $this->_defaultPage=$value; |
|
379 | + $this->_defaultPage = $value; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -392,14 +392,14 @@ discard block |
||
392 | 392 | */ |
393 | 393 | public function getBasePath() |
394 | 394 | { |
395 | - if($this->_basePath===null) |
|
395 | + if ($this->_basePath === null) |
|
396 | 396 | { |
397 | - $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
398 | - if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
|
397 | + $basePath = $this->getApplication()->getBasePath() . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
398 | + if (($this->_basePath = realpath($basePath)) === false || !is_dir($this->_basePath)) |
|
399 | 399 | { |
400 | - $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH; |
|
401 | - if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
|
402 | - throw new TConfigurationException('pageservice_basepath_invalid',$basePath); |
|
400 | + $basePath = $this->getApplication()->getBasePath() . DIRECTORY_SEPARATOR . self::FALLBACK_BASEPATH; |
|
401 | + if (($this->_basePath = realpath($basePath)) === false || !is_dir($this->_basePath)) |
|
402 | + throw new TConfigurationException('pageservice_basepath_invalid', $basePath); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | return $this->_basePath; |
@@ -411,11 +411,11 @@ discard block |
||
411 | 411 | */ |
412 | 412 | public function setBasePath($value) |
413 | 413 | { |
414 | - if($this->_initialized) |
|
414 | + if ($this->_initialized) |
|
415 | 415 | throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
416 | - else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path)) |
|
417 | - throw new TConfigurationException('pageservice_basepath_invalid',$value); |
|
418 | - $this->_basePath=realpath($path); |
|
416 | + else if (($path = Prado::getPathOfNamespace($value)) === null || !is_dir($path)) |
|
417 | + throw new TConfigurationException('pageservice_basepath_invalid', $value); |
|
418 | + $this->_basePath = realpath($path); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | */ |
427 | 427 | public function setBasePageClass($value) |
428 | 428 | { |
429 | - $this->_basePageClass=$value; |
|
429 | + $this->_basePageClass = $value; |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | */ |
445 | 445 | public function setClientScriptManagerClass($value) |
446 | 446 | { |
447 | - $this->_clientScriptManagerClass=$value; |
|
447 | + $this->_clientScriptManagerClass = $value; |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -463,9 +463,9 @@ discard block |
||
463 | 463 | */ |
464 | 464 | public function run() |
465 | 465 | { |
466 | - Prado::trace("Running page service",'System.Web.Services.TPageService'); |
|
467 | - $this->_page=$this->createPage($this->getRequestedPagePath()); |
|
468 | - $this->runPage($this->_page,$this->_properties); |
|
466 | + Prado::trace("Running page service", 'System.Web.Services.TPageService'); |
|
467 | + $this->_page = $this->createPage($this->getRequestedPagePath()); |
|
468 | + $this->runPage($this->_page, $this->_properties); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -477,35 +477,35 @@ discard block |
||
477 | 477 | */ |
478 | 478 | protected function createPage($pagePath) |
479 | 479 | { |
480 | - $path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR); |
|
481 | - $hasTemplateFile=is_file($path.self::PAGE_FILE_EXT); |
|
482 | - $hasClassFile=is_file($path.Prado::CLASS_FILE_EXT); |
|
480 | + $path = $this->getBasePath() . DIRECTORY_SEPARATOR . strtr($pagePath, '.', DIRECTORY_SEPARATOR); |
|
481 | + $hasTemplateFile = is_file($path . self::PAGE_FILE_EXT); |
|
482 | + $hasClassFile = is_file($path . Prado::CLASS_FILE_EXT); |
|
483 | 483 | |
484 | - if(!$hasTemplateFile && !$hasClassFile) |
|
485 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
484 | + if (!$hasTemplateFile && !$hasClassFile) |
|
485 | + throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
486 | 486 | |
487 | - if($hasClassFile) |
|
487 | + if ($hasClassFile) |
|
488 | 488 | { |
489 | - $className=basename($path); |
|
490 | - if(!class_exists($className,false)) |
|
491 | - include_once($path.Prado::CLASS_FILE_EXT); |
|
489 | + $className = basename($path); |
|
490 | + if (!class_exists($className, false)) |
|
491 | + include_once($path . Prado::CLASS_FILE_EXT); |
|
492 | 492 | } |
493 | 493 | else |
494 | 494 | { |
495 | - $className=$this->getBasePageClass(); |
|
495 | + $className = $this->getBasePageClass(); |
|
496 | 496 | Prado::using($className); |
497 | - if(($pos=strrpos($className,'.'))!==false) |
|
498 | - $className=substr($className,$pos+1); |
|
497 | + if (($pos = strrpos($className, '.')) !== false) |
|
498 | + $className = substr($className, $pos + 1); |
|
499 | 499 | } |
500 | 500 | |
501 | - if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) |
|
502 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
501 | + if (!class_exists($className, false) || ($className !== 'TPage' && !is_subclass_of($className, 'TPage'))) |
|
502 | + throw new THttpException(404, 'pageservice_page_unknown', $pagePath); |
|
503 | 503 | |
504 | - $page=Prado::createComponent($className); |
|
504 | + $page = Prado::createComponent($className); |
|
505 | 505 | $page->setPagePath($pagePath); |
506 | 506 | |
507 | - if($hasTemplateFile) |
|
508 | - $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT)); |
|
507 | + if ($hasTemplateFile) |
|
508 | + $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path . self::PAGE_FILE_EXT)); |
|
509 | 509 | |
510 | 510 | return $page; |
511 | 511 | } |
@@ -515,10 +515,10 @@ discard block |
||
515 | 515 | * @param TPage the page instance to be run |
516 | 516 | * @param array list of initial page properties |
517 | 517 | */ |
518 | - protected function runPage($page,$properties) |
|
518 | + protected function runPage($page, $properties) |
|
519 | 519 | { |
520 | - foreach($properties as $name=>$value) |
|
521 | - $page->setSubProperty($name,$value); |
|
520 | + foreach ($properties as $name=>$value) |
|
521 | + $page->setSubProperty($name, $value); |
|
522 | 522 | $page->run($this->getResponse()->createHtmlWriter()); |
523 | 523 | } |
524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
530 | 530 | * @param boolean whether to encode the GET parameters (their names and values), defaults to true. |
531 | 531 | * @return string URL for the page and GET parameters |
532 | 532 | */ |
533 | - public function constructUrl($pagePath,$getParams=null,$encodeAmpersand=true,$encodeGetItems=true) |
|
533 | + public function constructUrl($pagePath, $getParams = null, $encodeAmpersand = true, $encodeGetItems = true) |
|
534 | 534 | { |
535 | - return $this->getRequest()->constructUrl($this->getID(),$pagePath,$getParams,$encodeAmpersand,$encodeGetItems); |
|
535 | + return $this->getRequest()->constructUrl($this->getID(), $pagePath, $getParams, $encodeAmpersand, $encodeGetItems); |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
@@ -553,23 +553,23 @@ discard block |
||
553 | 553 | /** |
554 | 554 | * @var array list of application configurations |
555 | 555 | */ |
556 | - private $_appConfigs=array(); |
|
556 | + private $_appConfigs = array(); |
|
557 | 557 | /** |
558 | 558 | * @var array list of page initial property values |
559 | 559 | */ |
560 | - private $_properties=array(); |
|
560 | + private $_properties = array(); |
|
561 | 561 | /** |
562 | 562 | * @var TAuthorizationRuleCollection list of authorization rules |
563 | 563 | */ |
564 | - private $_rules=array(); |
|
564 | + private $_rules = array(); |
|
565 | 565 | /** |
566 | 566 | * @var array list of included configurations |
567 | 567 | */ |
568 | - private $_includes=array(); |
|
568 | + private $_includes = array(); |
|
569 | 569 | /** |
570 | 570 | * @var string the currently request page in the format of Path.To.PageName |
571 | 571 | */ |
572 | - private $_pagePath=''; |
|
572 | + private $_pagePath = ''; |
|
573 | 573 | |
574 | 574 | /** |
575 | 575 | * Constructor. |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | */ |
578 | 578 | public function __construct($pagePath) |
579 | 579 | { |
580 | - $this->_pagePath=$pagePath; |
|
580 | + $this->_pagePath = $pagePath; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -624,24 +624,24 @@ discard block |
||
624 | 624 | */ |
625 | 625 | public function loadFromFiles($basePath) |
626 | 626 | { |
627 | - $paths=explode('.',$this->_pagePath); |
|
628 | - $page=array_pop($paths); |
|
629 | - $path=$basePath; |
|
630 | - $configPagePath=''; |
|
631 | - $fileName = Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP |
|
627 | + $paths = explode('.', $this->_pagePath); |
|
628 | + $page = array_pop($paths); |
|
629 | + $path = $basePath; |
|
630 | + $configPagePath = ''; |
|
631 | + $fileName = Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP |
|
632 | 632 | ? TPageService::CONFIG_FILE_PHP |
633 | 633 | : TPageService::CONFIG_FILE_XML; |
634 | - foreach($paths as $p) |
|
634 | + foreach ($paths as $p) |
|
635 | 635 | { |
636 | - $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
|
637 | - $path.=DIRECTORY_SEPARATOR.$p; |
|
638 | - if($configPagePath==='') |
|
639 | - $configPagePath=$p; |
|
636 | + $this->loadFromFile($path . DIRECTORY_SEPARATOR . $fileName, $configPagePath); |
|
637 | + $path .= DIRECTORY_SEPARATOR . $p; |
|
638 | + if ($configPagePath === '') |
|
639 | + $configPagePath = $p; |
|
640 | 640 | else |
641 | - $configPagePath.='.'.$p; |
|
641 | + $configPagePath .= '.' . $p; |
|
642 | 642 | } |
643 | - $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
|
644 | - $this->_rules=new TAuthorizationRuleCollection($this->_rules); |
|
643 | + $this->loadFromFile($path . DIRECTORY_SEPARATOR . $fileName, $configPagePath); |
|
644 | + $this->_rules = new TAuthorizationRuleCollection($this->_rules); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -649,31 +649,31 @@ discard block |
||
649 | 649 | * @param string config file name |
650 | 650 | * @param string the page path that the config file is associated with. The page path doesn't include the page name. |
651 | 651 | */ |
652 | - public function loadFromFile($fname,$configPagePath) |
|
652 | + public function loadFromFile($fname, $configPagePath) |
|
653 | 653 | { |
654 | - Prado::trace("Loading page configuration file $fname",'System.Web.Services.TPageService'); |
|
655 | - if(empty($fname) || !is_file($fname)) |
|
654 | + Prado::trace("Loading page configuration file $fname", 'System.Web.Services.TPageService'); |
|
655 | + if (empty($fname) || !is_file($fname)) |
|
656 | 656 | return; |
657 | 657 | |
658 | - if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
658 | + if (Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) |
|
659 | 659 | { |
660 | 660 | $fcontent = include $fname; |
661 | - $this->loadFromPhp($fcontent,dirname($fname),$configPagePath); |
|
661 | + $this->loadFromPhp($fcontent, dirname($fname), $configPagePath); |
|
662 | 662 | } |
663 | 663 | else |
664 | 664 | { |
665 | - $dom=new TXmlDocument; |
|
666 | - if($dom->loadFromFile($fname)) |
|
667 | - $this->loadFromXml($dom,dirname($fname),$configPagePath); |
|
665 | + $dom = new TXmlDocument; |
|
666 | + if ($dom->loadFromFile($fname)) |
|
667 | + $this->loadFromXml($dom, dirname($fname), $configPagePath); |
|
668 | 668 | else |
669 | - throw new TConfigurationException('pageserviceconf_file_invalid',$fname); |
|
669 | + throw new TConfigurationException('pageserviceconf_file_invalid', $fname); |
|
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
673 | - public function loadFromPhp($config,$configPath,$configPagePath) |
|
673 | + public function loadFromPhp($config, $configPath, $configPagePath) |
|
674 | 674 | { |
675 | - $this->loadApplicationConfigurationFromPhp($config,$configPath); |
|
676 | - $this->loadPageConfigurationFromPhp($config,$configPath,$configPagePath); |
|
675 | + $this->loadApplicationConfigurationFromPhp($config, $configPath); |
|
676 | + $this->loadPageConfigurationFromPhp($config, $configPath, $configPagePath); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | /** |
@@ -684,17 +684,17 @@ discard block |
||
684 | 684 | * @param string the directory containing this configuration |
685 | 685 | * @param string the page path that the config XML is associated with. The page path doesn't include the page name. |
686 | 686 | */ |
687 | - public function loadFromXml($dom,$configPath,$configPagePath) |
|
687 | + public function loadFromXml($dom, $configPath, $configPagePath) |
|
688 | 688 | { |
689 | - $this->loadApplicationConfigurationFromXml($dom,$configPath); |
|
690 | - $this->loadPageConfigurationFromXml($dom,$configPath,$configPagePath); |
|
689 | + $this->loadApplicationConfigurationFromXml($dom, $configPath); |
|
690 | + $this->loadPageConfigurationFromXml($dom, $configPath, $configPagePath); |
|
691 | 691 | } |
692 | 692 | |
693 | - public function loadApplicationConfigurationFromPhp($config,$configPath) |
|
693 | + public function loadApplicationConfigurationFromPhp($config, $configPath) |
|
694 | 694 | { |
695 | - $appConfig=new TApplicationConfiguration; |
|
696 | - $appConfig->loadFromPhp($config,$configPath); |
|
697 | - $this->_appConfigs[]=$appConfig; |
|
695 | + $appConfig = new TApplicationConfiguration; |
|
696 | + $appConfig->loadFromPhp($config, $configPath); |
|
697 | + $this->_appConfigs[] = $appConfig; |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -702,102 +702,102 @@ discard block |
||
702 | 702 | * @param TXmlElement config xml element |
703 | 703 | * @param string base path corresponding to this xml element |
704 | 704 | */ |
705 | - public function loadApplicationConfigurationFromXml($dom,$configPath) |
|
705 | + public function loadApplicationConfigurationFromXml($dom, $configPath) |
|
706 | 706 | { |
707 | - $appConfig=new TApplicationConfiguration; |
|
708 | - $appConfig->loadFromXml($dom,$configPath); |
|
709 | - $this->_appConfigs[]=$appConfig; |
|
707 | + $appConfig = new TApplicationConfiguration; |
|
708 | + $appConfig->loadFromXml($dom, $configPath); |
|
709 | + $this->_appConfigs[] = $appConfig; |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | public function loadPageConfigurationFromPhp($config, $configPath, $configPagePath) |
713 | 713 | { |
714 | 714 | // authorization |
715 | - if(isset($config['authorization']) && is_array($config['authorization'])) |
|
715 | + if (isset($config['authorization']) && is_array($config['authorization'])) |
|
716 | 716 | { |
717 | 717 | $rules = array(); |
718 | - foreach($config['authorization'] as $authorization) |
|
718 | + foreach ($config['authorization'] as $authorization) |
|
719 | 719 | { |
720 | - $patterns=isset($authorization['pages'])?$authorization['pages']:''; |
|
721 | - $ruleApplies=false; |
|
722 | - if(empty($patterns) || trim($patterns)==='*') // null or empty string |
|
723 | - $ruleApplies=true; |
|
720 | + $patterns = isset($authorization['pages']) ? $authorization['pages'] : ''; |
|
721 | + $ruleApplies = false; |
|
722 | + if (empty($patterns) || trim($patterns) === '*') // null or empty string |
|
723 | + $ruleApplies = true; |
|
724 | 724 | else |
725 | 725 | { |
726 | - foreach(explode(',',$patterns) as $pattern) |
|
726 | + foreach (explode(',', $patterns) as $pattern) |
|
727 | 727 | { |
728 | - if(($pattern=trim($pattern))!=='') |
|
728 | + if (($pattern = trim($pattern)) !== '') |
|
729 | 729 | { |
730 | 730 | // we know $configPagePath and $this->_pagePath |
731 | - if($configPagePath!=='') // prepend the pattern with ConfigPagePath |
|
732 | - $pattern=$configPagePath.'.'.$pattern; |
|
733 | - if(strcasecmp($pattern,$this->_pagePath)===0) |
|
731 | + if ($configPagePath !== '') // prepend the pattern with ConfigPagePath |
|
732 | + $pattern = $configPagePath . '.' . $pattern; |
|
733 | + if (strcasecmp($pattern, $this->_pagePath) === 0) |
|
734 | 734 | { |
735 | - $ruleApplies=true; |
|
735 | + $ruleApplies = true; |
|
736 | 736 | break; |
737 | 737 | } |
738 | - if($pattern[strlen($pattern)-1]==='*') // try wildcard matching |
|
738 | + if ($pattern[strlen($pattern) - 1] === '*') // try wildcard matching |
|
739 | 739 | { |
740 | - if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0) |
|
740 | + if (strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1) === 0) |
|
741 | 741 | { |
742 | - $ruleApplies=true; |
|
742 | + $ruleApplies = true; |
|
743 | 743 | break; |
744 | 744 | } |
745 | 745 | } |
746 | 746 | } |
747 | 747 | } |
748 | 748 | } |
749 | - if($ruleApplies) |
|
749 | + if ($ruleApplies) |
|
750 | 750 | { |
751 | - $action = isset($authorization['action'])?$authorization['action']:''; |
|
752 | - $users = isset($authorization['users'])?$authorization['users']:''; |
|
753 | - $roles = isset($authorization['roles'])?$authorization['roles']:''; |
|
754 | - $verb = isset($authorization['verb'])?$authorization['verb']:''; |
|
755 | - $ips = isset($authorization['ips'])?$authorization['ips']:''; |
|
756 | - $rules[]=new TAuthorizationRule($action,$users,$roles,$verb,$ips); |
|
751 | + $action = isset($authorization['action']) ? $authorization['action'] : ''; |
|
752 | + $users = isset($authorization['users']) ? $authorization['users'] : ''; |
|
753 | + $roles = isset($authorization['roles']) ? $authorization['roles'] : ''; |
|
754 | + $verb = isset($authorization['verb']) ? $authorization['verb'] : ''; |
|
755 | + $ips = isset($authorization['ips']) ? $authorization['ips'] : ''; |
|
756 | + $rules[] = new TAuthorizationRule($action, $users, $roles, $verb, $ips); |
|
757 | 757 | } |
758 | 758 | } |
759 | - $this->_rules=array_merge($rules,$this->_rules); |
|
759 | + $this->_rules = array_merge($rules, $this->_rules); |
|
760 | 760 | } |
761 | 761 | // pages |
762 | - if(isset($config['pages']) && is_array($config['pages'])) |
|
762 | + if (isset($config['pages']) && is_array($config['pages'])) |
|
763 | 763 | { |
764 | - if(isset($config['pages']['properties'])) |
|
764 | + if (isset($config['pages']['properties'])) |
|
765 | 765 | { |
766 | 766 | $this->_properties = array_merge($this->_properties, $config['pages']['properties']); |
767 | 767 | unset($config['pages']['properties']); |
768 | 768 | } |
769 | - foreach($config['pages'] as $id => $page) |
|
769 | + foreach ($config['pages'] as $id => $page) |
|
770 | 770 | { |
771 | 771 | $properties = array(); |
772 | - if(isset($page['properties'])) |
|
772 | + if (isset($page['properties'])) |
|
773 | 773 | { |
774 | - $properties=$page['properties']; |
|
774 | + $properties = $page['properties']; |
|
775 | 775 | unset($page['properties']); |
776 | 776 | } |
777 | - $matching=false; |
|
778 | - $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
|
779 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
780 | - $matching=true; |
|
781 | - else if($id[strlen($id)-1]==='*') // try wildcard matching |
|
782 | - $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
783 | - if($matching) |
|
784 | - $this->_properties=array_merge($this->_properties,$properties); |
|
777 | + $matching = false; |
|
778 | + $id = ($configPagePath === '') ? $id : $configPagePath . '.' . $id; |
|
779 | + if (strcasecmp($id, $this->_pagePath) === 0) |
|
780 | + $matching = true; |
|
781 | + else if ($id[strlen($id) - 1] === '*') // try wildcard matching |
|
782 | + $matching = strncasecmp($this->_pagePath, $id, strlen($id) - 1) === 0; |
|
783 | + if ($matching) |
|
784 | + $this->_properties = array_merge($this->_properties, $properties); |
|
785 | 785 | } |
786 | 786 | } |
787 | 787 | |
788 | 788 | // external configurations |
789 | - if(isset($config['includes']) && is_array($config['includes'])) |
|
789 | + if (isset($config['includes']) && is_array($config['includes'])) |
|
790 | 790 | { |
791 | - foreach($config['includes'] as $include) |
|
791 | + foreach ($config['includes'] as $include) |
|
792 | 792 | { |
793 | - $when = isset($include['when'])?true:false; |
|
794 | - if(!isset($include['file'])) |
|
793 | + $when = isset($include['when']) ? true : false; |
|
794 | + if (!isset($include['file'])) |
|
795 | 795 | throw new TConfigurationException('pageserviceconf_includefile_required'); |
796 | 796 | $filePath = $include['file']; |
797 | - if(isset($this->_includes[$filePath])) |
|
798 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
797 | + if (isset($this->_includes[$filePath])) |
|
798 | + $this->_includes[$filePath] = array($configPagePath, '(' . $this->_includes[$filePath][1] . ') || (' . $when . ')'); |
|
799 | 799 | else |
800 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
800 | + $this->_includes[$filePath] = array($configPagePath, $when); |
|
801 | 801 | } |
802 | 802 | } |
803 | 803 | } |
@@ -808,82 +808,82 @@ discard block |
||
808 | 808 | * @param string base path corresponding to this xml element |
809 | 809 | * @param string the page path that the config XML is associated with. The page path doesn't include the page name. |
810 | 810 | */ |
811 | - public function loadPageConfigurationFromXml($dom,$configPath,$configPagePath) |
|
811 | + public function loadPageConfigurationFromXml($dom, $configPath, $configPagePath) |
|
812 | 812 | { |
813 | 813 | // authorization |
814 | - if(($authorizationNode=$dom->getElementByTagName('authorization'))!==null) |
|
814 | + if (($authorizationNode = $dom->getElementByTagName('authorization')) !== null) |
|
815 | 815 | { |
816 | - $rules=array(); |
|
817 | - foreach($authorizationNode->getElements() as $node) |
|
816 | + $rules = array(); |
|
817 | + foreach ($authorizationNode->getElements() as $node) |
|
818 | 818 | { |
819 | - $patterns=$node->getAttribute('pages'); |
|
820 | - $ruleApplies=false; |
|
821 | - if(empty($patterns) || trim($patterns)==='*') // null or empty string |
|
822 | - $ruleApplies=true; |
|
819 | + $patterns = $node->getAttribute('pages'); |
|
820 | + $ruleApplies = false; |
|
821 | + if (empty($patterns) || trim($patterns) === '*') // null or empty string |
|
822 | + $ruleApplies = true; |
|
823 | 823 | else |
824 | 824 | { |
825 | - foreach(explode(',',$patterns) as $pattern) |
|
825 | + foreach (explode(',', $patterns) as $pattern) |
|
826 | 826 | { |
827 | - if(($pattern=trim($pattern))!=='') |
|
827 | + if (($pattern = trim($pattern)) !== '') |
|
828 | 828 | { |
829 | 829 | // we know $configPagePath and $this->_pagePath |
830 | - if($configPagePath!=='') // prepend the pattern with ConfigPagePath |
|
831 | - $pattern=$configPagePath.'.'.$pattern; |
|
832 | - if(strcasecmp($pattern,$this->_pagePath)===0) |
|
830 | + if ($configPagePath !== '') // prepend the pattern with ConfigPagePath |
|
831 | + $pattern = $configPagePath . '.' . $pattern; |
|
832 | + if (strcasecmp($pattern, $this->_pagePath) === 0) |
|
833 | 833 | { |
834 | - $ruleApplies=true; |
|
834 | + $ruleApplies = true; |
|
835 | 835 | break; |
836 | 836 | } |
837 | - if($pattern[strlen($pattern)-1]==='*') // try wildcard matching |
|
837 | + if ($pattern[strlen($pattern) - 1] === '*') // try wildcard matching |
|
838 | 838 | { |
839 | - if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0) |
|
839 | + if (strncasecmp($this->_pagePath, $pattern, strlen($pattern) - 1) === 0) |
|
840 | 840 | { |
841 | - $ruleApplies=true; |
|
841 | + $ruleApplies = true; |
|
842 | 842 | break; |
843 | 843 | } |
844 | 844 | } |
845 | 845 | } |
846 | 846 | } |
847 | 847 | } |
848 | - if($ruleApplies) |
|
849 | - $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips')); |
|
848 | + if ($ruleApplies) |
|
849 | + $rules[] = new TAuthorizationRule($node->getTagName(), $node->getAttribute('users'), $node->getAttribute('roles'), $node->getAttribute('verb'), $node->getAttribute('ips')); |
|
850 | 850 | } |
851 | - $this->_rules=array_merge($rules,$this->_rules); |
|
851 | + $this->_rules = array_merge($rules, $this->_rules); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | // pages |
855 | - if(($pagesNode=$dom->getElementByTagName('pages'))!==null) |
|
855 | + if (($pagesNode = $dom->getElementByTagName('pages')) !== null) |
|
856 | 856 | { |
857 | - $this->_properties=array_merge($this->_properties,$pagesNode->getAttributes()->toArray()); |
|
857 | + $this->_properties = array_merge($this->_properties, $pagesNode->getAttributes()->toArray()); |
|
858 | 858 | // at the page folder |
859 | - foreach($pagesNode->getElementsByTagName('page') as $node) |
|
859 | + foreach ($pagesNode->getElementsByTagName('page') as $node) |
|
860 | 860 | { |
861 | - $properties=$node->getAttributes(); |
|
862 | - $id=$properties->remove('id'); |
|
863 | - if(empty($id)) |
|
864 | - throw new TConfigurationException('pageserviceconf_page_invalid',$configPath); |
|
865 | - $matching=false; |
|
866 | - $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
|
867 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
868 | - $matching=true; |
|
869 | - else if($id[strlen($id)-1]==='*') // try wildcard matching |
|
870 | - $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
|
871 | - if($matching) |
|
872 | - $this->_properties=array_merge($this->_properties,$properties->toArray()); |
|
861 | + $properties = $node->getAttributes(); |
|
862 | + $id = $properties->remove('id'); |
|
863 | + if (empty($id)) |
|
864 | + throw new TConfigurationException('pageserviceconf_page_invalid', $configPath); |
|
865 | + $matching = false; |
|
866 | + $id = ($configPagePath === '') ? $id : $configPagePath . '.' . $id; |
|
867 | + if (strcasecmp($id, $this->_pagePath) === 0) |
|
868 | + $matching = true; |
|
869 | + else if ($id[strlen($id) - 1] === '*') // try wildcard matching |
|
870 | + $matching = strncasecmp($this->_pagePath, $id, strlen($id) - 1) === 0; |
|
871 | + if ($matching) |
|
872 | + $this->_properties = array_merge($this->_properties, $properties->toArray()); |
|
873 | 873 | } |
874 | 874 | } |
875 | 875 | |
876 | 876 | // external configurations |
877 | - foreach($dom->getElementsByTagName('include') as $node) |
|
877 | + foreach ($dom->getElementsByTagName('include') as $node) |
|
878 | 878 | { |
879 | - if(($when=$node->getAttribute('when'))===null) |
|
880 | - $when=true; |
|
881 | - if(($filePath=$node->getAttribute('file'))===null) |
|
879 | + if (($when = $node->getAttribute('when')) === null) |
|
880 | + $when = true; |
|
881 | + if (($filePath = $node->getAttribute('file')) === null) |
|
882 | 882 | throw new TConfigurationException('pageserviceconf_includefile_required'); |
883 | - if(isset($this->_includes[$filePath])) |
|
884 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
883 | + if (isset($this->_includes[$filePath])) |
|
884 | + $this->_includes[$filePath] = array($configPagePath, '(' . $this->_includes[$filePath][1] . ') || (' . $when . ')'); |
|
885 | 885 | else |
886 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
886 | + $this->_includes[$filePath] = array($configPagePath, $when); |
|
887 | 887 | } |
888 | 888 | } |
889 | 889 | } |
@@ -166,8 +166,9 @@ discard block |
||
166 | 166 | protected function initPageContext($pageConfig) |
167 | 167 | { |
168 | 168 | $application=$this->getApplication(); |
169 | - foreach($pageConfig->getApplicationConfigurations() as $appConfig) |
|
170 | - $application->applyConfiguration($appConfig); |
|
169 | + foreach($pageConfig->getApplicationConfigurations() as $appConfig) { |
|
170 | + $application->applyConfiguration($appConfig); |
|
171 | + } |
|
171 | 172 | |
172 | 173 | $this->applyConfiguration($pageConfig); |
173 | 174 | } |
@@ -186,12 +187,14 @@ discard block |
||
186 | 187 | foreach($config->getExternalConfigurations() as $filePath=>$params) |
187 | 188 | { |
188 | 189 | list($configPagePath,$condition)=$params; |
189 | - if($condition!==true) |
|
190 | - $condition=$this->evaluateExpression($condition); |
|
190 | + if($condition!==true) { |
|
191 | + $condition=$this->evaluateExpression($condition); |
|
192 | + } |
|
191 | 193 | if($condition) |
192 | 194 | { |
193 | - if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) |
|
194 | - throw new TConfigurationException('pageservice_includefile_invalid',$filePath); |
|
195 | + if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path)) { |
|
196 | + throw new TConfigurationException('pageservice_includefile_invalid',$filePath); |
|
197 | + } |
|
195 | 198 | $c=new TPageConfiguration($pagePath); |
196 | 199 | $c->loadFromFile($path,$configPagePath); |
197 | 200 | $this->applyConfiguration($c); |
@@ -207,8 +210,9 @@ discard block |
||
207 | 210 | protected function determineRequestedPagePath() |
208 | 211 | { |
209 | 212 | $pagePath=$this->getRequest()->getServiceParameter(); |
210 | - if(empty($pagePath)) |
|
211 | - $pagePath=$this->getDefaultPage(); |
|
213 | + if(empty($pagePath)) { |
|
214 | + $pagePath=$this->getDefaultPage(); |
|
215 | + } |
|
212 | 216 | return $pagePath; |
213 | 217 | } |
214 | 218 | |
@@ -226,14 +230,14 @@ discard block |
||
226 | 230 | $pageConfig=new TPageConfiguration($pagePath); |
227 | 231 | if($config!==null) |
228 | 232 | { |
229 | - if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
230 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
231 | - else |
|
232 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
233 | + if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) { |
|
234 | + $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
235 | + } else { |
|
236 | + $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
237 | + } |
|
233 | 238 | } |
234 | 239 | $pageConfig->loadFromFiles($this->getBasePath()); |
235 | - } |
|
236 | - else |
|
240 | + } else |
|
237 | 241 | { |
238 | 242 | $configCached=true; |
239 | 243 | $currentTimestamp=array(); |
@@ -245,23 +249,25 @@ discard block |
||
245 | 249 | { |
246 | 250 | foreach($timestamps as $fileName=>$timestamp) |
247 | 251 | { |
248 | - if($fileName===0) // application config file |
|
252 | + if($fileName===0) { |
|
253 | + // application config file |
|
249 | 254 | { |
250 | 255 | $appConfigFile=$application->getConfigurationFile(); |
251 | - $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
|
252 | - if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) |
|
253 | - $configCached=false; |
|
254 | 256 | } |
255 | - else |
|
257 | + $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); |
|
258 | + if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) { |
|
259 | + $configCached=false; |
|
260 | + } |
|
261 | + } else |
|
256 | 262 | { |
257 | 263 | $currentTimestamp[$fileName]=@filemtime($fileName); |
258 | - if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) |
|
259 | - $configCached=false; |
|
264 | + if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) { |
|
265 | + $configCached=false; |
|
266 | + } |
|
260 | 267 | } |
261 | 268 | } |
262 | 269 | } |
263 | - } |
|
264 | - else |
|
270 | + } else |
|
265 | 271 | { |
266 | 272 | $configCached=false; |
267 | 273 | $paths=explode('.',$pagePath); |
@@ -283,10 +289,11 @@ discard block |
||
283 | 289 | $pageConfig=new TPageConfiguration($pagePath); |
284 | 290 | if($config!==null) |
285 | 291 | { |
286 | - if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
|
287 | - $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
288 | - else |
|
289 | - $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
292 | + if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) { |
|
293 | + $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),''); |
|
294 | + } else { |
|
295 | + $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),''); |
|
296 | + } |
|
290 | 297 | } |
291 | 298 | $pageConfig->loadFromFiles($this->getBasePath()); |
292 | 299 | $cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp)); |
@@ -345,8 +352,9 @@ discard block |
||
345 | 352 | if($this->_pagePath===null) |
346 | 353 | { |
347 | 354 | $this->_pagePath=strtr($this->determineRequestedPagePath(),'/\\','..'); |
348 | - if(empty($this->_pagePath)) |
|
349 | - throw new THttpException(404,'pageservice_page_required'); |
|
355 | + if(empty($this->_pagePath)) { |
|
356 | + throw new THttpException(404,'pageservice_page_required'); |
|
357 | + } |
|
350 | 358 | } |
351 | 359 | return $this->_pagePath; |
352 | 360 | } |
@@ -373,10 +381,11 @@ discard block |
||
373 | 381 | */ |
374 | 382 | public function setDefaultPage($value) |
375 | 383 | { |
376 | - if($this->_initialized) |
|
377 | - throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
|
378 | - else |
|
379 | - $this->_defaultPage=$value; |
|
384 | + if($this->_initialized) { |
|
385 | + throw new TInvalidOperationException('pageservice_defaultpage_unchangeable'); |
|
386 | + } else { |
|
387 | + $this->_defaultPage=$value; |
|
388 | + } |
|
380 | 389 | } |
381 | 390 | |
382 | 391 | /** |
@@ -398,8 +407,9 @@ discard block |
||
398 | 407 | if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
399 | 408 | { |
400 | 409 | $basePath=$this->getApplication()->getBasePath().DIRECTORY_SEPARATOR.self::FALLBACK_BASEPATH; |
401 | - if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) |
|
402 | - throw new TConfigurationException('pageservice_basepath_invalid',$basePath); |
|
410 | + if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) { |
|
411 | + throw new TConfigurationException('pageservice_basepath_invalid',$basePath); |
|
412 | + } |
|
403 | 413 | } |
404 | 414 | } |
405 | 415 | return $this->_basePath; |
@@ -411,10 +421,11 @@ discard block |
||
411 | 421 | */ |
412 | 422 | public function setBasePath($value) |
413 | 423 | { |
414 | - if($this->_initialized) |
|
415 | - throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
|
416 | - else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path)) |
|
417 | - throw new TConfigurationException('pageservice_basepath_invalid',$value); |
|
424 | + if($this->_initialized) { |
|
425 | + throw new TInvalidOperationException('pageservice_basepath_unchangeable'); |
|
426 | + } else if(($path=Prado::getPathOfNamespace($value))===null || !is_dir($path)) { |
|
427 | + throw new TConfigurationException('pageservice_basepath_invalid',$value); |
|
428 | + } |
|
418 | 429 | $this->_basePath=realpath($path); |
419 | 430 | } |
420 | 431 | |
@@ -481,31 +492,35 @@ discard block |
||
481 | 492 | $hasTemplateFile=is_file($path.self::PAGE_FILE_EXT); |
482 | 493 | $hasClassFile=is_file($path.Prado::CLASS_FILE_EXT); |
483 | 494 | |
484 | - if(!$hasTemplateFile && !$hasClassFile) |
|
485 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
495 | + if(!$hasTemplateFile && !$hasClassFile) { |
|
496 | + throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
497 | + } |
|
486 | 498 | |
487 | 499 | if($hasClassFile) |
488 | 500 | { |
489 | 501 | $className=basename($path); |
490 | - if(!class_exists($className,false)) |
|
491 | - include_once($path.Prado::CLASS_FILE_EXT); |
|
492 | - } |
|
493 | - else |
|
502 | + if(!class_exists($className,false)) { |
|
503 | + include_once($path.Prado::CLASS_FILE_EXT); |
|
504 | + } |
|
505 | + } else |
|
494 | 506 | { |
495 | 507 | $className=$this->getBasePageClass(); |
496 | 508 | Prado::using($className); |
497 | - if(($pos=strrpos($className,'.'))!==false) |
|
498 | - $className=substr($className,$pos+1); |
|
509 | + if(($pos=strrpos($className,'.'))!==false) { |
|
510 | + $className=substr($className,$pos+1); |
|
511 | + } |
|
499 | 512 | } |
500 | 513 | |
501 | - if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) |
|
502 | - throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
514 | + if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) { |
|
515 | + throw new THttpException(404,'pageservice_page_unknown',$pagePath); |
|
516 | + } |
|
503 | 517 | |
504 | 518 | $page=Prado::createComponent($className); |
505 | 519 | $page->setPagePath($pagePath); |
506 | 520 | |
507 | - if($hasTemplateFile) |
|
508 | - $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT)); |
|
521 | + if($hasTemplateFile) { |
|
522 | + $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT)); |
|
523 | + } |
|
509 | 524 | |
510 | 525 | return $page; |
511 | 526 | } |
@@ -517,8 +532,9 @@ discard block |
||
517 | 532 | */ |
518 | 533 | protected function runPage($page,$properties) |
519 | 534 | { |
520 | - foreach($properties as $name=>$value) |
|
521 | - $page->setSubProperty($name,$value); |
|
535 | + foreach($properties as $name=>$value) { |
|
536 | + $page->setSubProperty($name,$value); |
|
537 | + } |
|
522 | 538 | $page->run($this->getResponse()->createHtmlWriter()); |
523 | 539 | } |
524 | 540 | |
@@ -635,10 +651,11 @@ discard block |
||
635 | 651 | { |
636 | 652 | $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
637 | 653 | $path.=DIRECTORY_SEPARATOR.$p; |
638 | - if($configPagePath==='') |
|
639 | - $configPagePath=$p; |
|
640 | - else |
|
641 | - $configPagePath.='.'.$p; |
|
654 | + if($configPagePath==='') { |
|
655 | + $configPagePath=$p; |
|
656 | + } else { |
|
657 | + $configPagePath.='.'.$p; |
|
658 | + } |
|
642 | 659 | } |
643 | 660 | $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath); |
644 | 661 | $this->_rules=new TAuthorizationRuleCollection($this->_rules); |
@@ -652,21 +669,22 @@ discard block |
||
652 | 669 | public function loadFromFile($fname,$configPagePath) |
653 | 670 | { |
654 | 671 | Prado::trace("Loading page configuration file $fname",'System.Web.Services.TPageService'); |
655 | - if(empty($fname) || !is_file($fname)) |
|
656 | - return; |
|
672 | + if(empty($fname) || !is_file($fname)) { |
|
673 | + return; |
|
674 | + } |
|
657 | 675 | |
658 | 676 | if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
659 | 677 | { |
660 | 678 | $fcontent = include $fname; |
661 | 679 | $this->loadFromPhp($fcontent,dirname($fname),$configPagePath); |
662 | - } |
|
663 | - else |
|
680 | + } else |
|
664 | 681 | { |
665 | 682 | $dom=new TXmlDocument; |
666 | - if($dom->loadFromFile($fname)) |
|
667 | - $this->loadFromXml($dom,dirname($fname),$configPagePath); |
|
668 | - else |
|
669 | - throw new TConfigurationException('pageserviceconf_file_invalid',$fname); |
|
683 | + if($dom->loadFromFile($fname)) { |
|
684 | + $this->loadFromXml($dom,dirname($fname),$configPagePath); |
|
685 | + } else { |
|
686 | + throw new TConfigurationException('pageserviceconf_file_invalid',$fname); |
|
687 | + } |
|
670 | 688 | } |
671 | 689 | } |
672 | 690 | |
@@ -719,27 +737,32 @@ discard block |
||
719 | 737 | { |
720 | 738 | $patterns=isset($authorization['pages'])?$authorization['pages']:''; |
721 | 739 | $ruleApplies=false; |
722 | - if(empty($patterns) || trim($patterns)==='*') // null or empty string |
|
740 | + if(empty($patterns) || trim($patterns)==='*') { |
|
741 | + // null or empty string |
|
723 | 742 | $ruleApplies=true; |
724 | - else |
|
743 | + } else |
|
725 | 744 | { |
726 | 745 | foreach(explode(',',$patterns) as $pattern) |
727 | 746 | { |
728 | 747 | if(($pattern=trim($pattern))!=='') |
729 | 748 | { |
730 | 749 | // we know $configPagePath and $this->_pagePath |
731 | - if($configPagePath!=='') // prepend the pattern with ConfigPagePath |
|
750 | + if($configPagePath!=='') { |
|
751 | + // prepend the pattern with ConfigPagePath |
|
732 | 752 | $pattern=$configPagePath.'.'.$pattern; |
753 | + } |
|
733 | 754 | if(strcasecmp($pattern,$this->_pagePath)===0) |
734 | 755 | { |
735 | 756 | $ruleApplies=true; |
736 | 757 | break; |
737 | 758 | } |
738 | - if($pattern[strlen($pattern)-1]==='*') // try wildcard matching |
|
759 | + if($pattern[strlen($pattern)-1]==='*') { |
|
760 | + // try wildcard matching |
|
739 | 761 | { |
740 | 762 | if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0) |
741 | 763 | { |
742 | 764 | $ruleApplies=true; |
765 | + } |
|
743 | 766 | break; |
744 | 767 | } |
745 | 768 | } |
@@ -776,12 +799,15 @@ discard block |
||
776 | 799 | } |
777 | 800 | $matching=false; |
778 | 801 | $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
779 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
780 | - $matching=true; |
|
781 | - else if($id[strlen($id)-1]==='*') // try wildcard matching |
|
802 | + if(strcasecmp($id,$this->_pagePath)===0) { |
|
803 | + $matching=true; |
|
804 | + } else if($id[strlen($id)-1]==='*') { |
|
805 | + // try wildcard matching |
|
782 | 806 | $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
783 | - if($matching) |
|
784 | - $this->_properties=array_merge($this->_properties,$properties); |
|
807 | + } |
|
808 | + if($matching) { |
|
809 | + $this->_properties=array_merge($this->_properties,$properties); |
|
810 | + } |
|
785 | 811 | } |
786 | 812 | } |
787 | 813 | |
@@ -791,13 +817,15 @@ discard block |
||
791 | 817 | foreach($config['includes'] as $include) |
792 | 818 | { |
793 | 819 | $when = isset($include['when'])?true:false; |
794 | - if(!isset($include['file'])) |
|
795 | - throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
820 | + if(!isset($include['file'])) { |
|
821 | + throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
822 | + } |
|
796 | 823 | $filePath = $include['file']; |
797 | - if(isset($this->_includes[$filePath])) |
|
798 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
799 | - else |
|
800 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
824 | + if(isset($this->_includes[$filePath])) { |
|
825 | + $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
826 | + } else { |
|
827 | + $this->_includes[$filePath]=array($configPagePath,$when); |
|
828 | + } |
|
801 | 829 | } |
802 | 830 | } |
803 | 831 | } |
@@ -818,35 +846,41 @@ discard block |
||
818 | 846 | { |
819 | 847 | $patterns=$node->getAttribute('pages'); |
820 | 848 | $ruleApplies=false; |
821 | - if(empty($patterns) || trim($patterns)==='*') // null or empty string |
|
849 | + if(empty($patterns) || trim($patterns)==='*') { |
|
850 | + // null or empty string |
|
822 | 851 | $ruleApplies=true; |
823 | - else |
|
852 | + } else |
|
824 | 853 | { |
825 | 854 | foreach(explode(',',$patterns) as $pattern) |
826 | 855 | { |
827 | 856 | if(($pattern=trim($pattern))!=='') |
828 | 857 | { |
829 | 858 | // we know $configPagePath and $this->_pagePath |
830 | - if($configPagePath!=='') // prepend the pattern with ConfigPagePath |
|
859 | + if($configPagePath!=='') { |
|
860 | + // prepend the pattern with ConfigPagePath |
|
831 | 861 | $pattern=$configPagePath.'.'.$pattern; |
862 | + } |
|
832 | 863 | if(strcasecmp($pattern,$this->_pagePath)===0) |
833 | 864 | { |
834 | 865 | $ruleApplies=true; |
835 | 866 | break; |
836 | 867 | } |
837 | - if($pattern[strlen($pattern)-1]==='*') // try wildcard matching |
|
868 | + if($pattern[strlen($pattern)-1]==='*') { |
|
869 | + // try wildcard matching |
|
838 | 870 | { |
839 | 871 | if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0) |
840 | 872 | { |
841 | 873 | $ruleApplies=true; |
874 | + } |
|
842 | 875 | break; |
843 | 876 | } |
844 | 877 | } |
845 | 878 | } |
846 | 879 | } |
847 | 880 | } |
848 | - if($ruleApplies) |
|
849 | - $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips')); |
|
881 | + if($ruleApplies) { |
|
882 | + $rules[]=new TAuthorizationRule($node->getTagName(),$node->getAttribute('users'),$node->getAttribute('roles'),$node->getAttribute('verb'),$node->getAttribute('ips')); |
|
883 | + } |
|
850 | 884 | } |
851 | 885 | $this->_rules=array_merge($rules,$this->_rules); |
852 | 886 | } |
@@ -860,30 +894,37 @@ discard block |
||
860 | 894 | { |
861 | 895 | $properties=$node->getAttributes(); |
862 | 896 | $id=$properties->remove('id'); |
863 | - if(empty($id)) |
|
864 | - throw new TConfigurationException('pageserviceconf_page_invalid',$configPath); |
|
897 | + if(empty($id)) { |
|
898 | + throw new TConfigurationException('pageserviceconf_page_invalid',$configPath); |
|
899 | + } |
|
865 | 900 | $matching=false; |
866 | 901 | $id=($configPagePath==='')?$id:$configPagePath.'.'.$id; |
867 | - if(strcasecmp($id,$this->_pagePath)===0) |
|
868 | - $matching=true; |
|
869 | - else if($id[strlen($id)-1]==='*') // try wildcard matching |
|
902 | + if(strcasecmp($id,$this->_pagePath)===0) { |
|
903 | + $matching=true; |
|
904 | + } else if($id[strlen($id)-1]==='*') { |
|
905 | + // try wildcard matching |
|
870 | 906 | $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0; |
871 | - if($matching) |
|
872 | - $this->_properties=array_merge($this->_properties,$properties->toArray()); |
|
907 | + } |
|
908 | + if($matching) { |
|
909 | + $this->_properties=array_merge($this->_properties,$properties->toArray()); |
|
910 | + } |
|
873 | 911 | } |
874 | 912 | } |
875 | 913 | |
876 | 914 | // external configurations |
877 | 915 | foreach($dom->getElementsByTagName('include') as $node) |
878 | 916 | { |
879 | - if(($when=$node->getAttribute('when'))===null) |
|
880 | - $when=true; |
|
881 | - if(($filePath=$node->getAttribute('file'))===null) |
|
882 | - throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
883 | - if(isset($this->_includes[$filePath])) |
|
884 | - $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
885 | - else |
|
886 | - $this->_includes[$filePath]=array($configPagePath,$when); |
|
917 | + if(($when=$node->getAttribute('when'))===null) { |
|
918 | + $when=true; |
|
919 | + } |
|
920 | + if(($filePath=$node->getAttribute('file'))===null) { |
|
921 | + throw new TConfigurationException('pageserviceconf_includefile_required'); |
|
922 | + } |
|
923 | + if(isset($this->_includes[$filePath])) { |
|
924 | + $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')'); |
|
925 | + } else { |
|
926 | + $this->_includes[$filePath]=array($configPagePath,$when); |
|
927 | + } |
|
887 | 928 | } |
888 | 929 | } |
889 | 930 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TPageService class file. |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Web.Services |
|
10 | - */ |
|
3 | + * TPageService class file. |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Web.Services |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Include classes to be used by page service |
@@ -258,6 +258,9 @@ discard block |
||
258 | 258 | */ |
259 | 259 | class TRpcException extends TException |
260 | 260 | { |
261 | + /** |
|
262 | + * @param string $message |
|
263 | + */ |
|
261 | 264 | public function __construct($message, $errorCode = -1) |
262 | 265 | { |
263 | 266 | $this->setErrorCode($errorCode); |
@@ -334,7 +337,7 @@ discard block |
||
334 | 337 | } |
335 | 338 | |
336 | 339 | /** |
337 | - * @return rpc server instance |
|
340 | + * @return TRpcServer server instance |
|
338 | 341 | */ |
339 | 342 | public function getRpcServer() |
340 | 343 | { |
@@ -366,6 +369,7 @@ discard block |
||
366 | 369 | /** |
367 | 370 | * @param string request payload |
368 | 371 | * Processed the request ans returns the response, if any |
372 | + * @param string $requestPayload |
|
369 | 373 | * @return processed response |
370 | 374 | * @abstract |
371 | 375 | */ |
@@ -641,7 +645,6 @@ discard block |
||
641 | 645 | /** |
642 | 646 | * Registers a new RPC method and handler details |
643 | 647 | * @param string $methodName |
644 | - * @param array $handlerDetails containing the callback handler |
|
645 | 648 | */ |
646 | 649 | public function addMethod($methodName, $methodDetails) |
647 | 650 | { |
@@ -90,28 +90,28 @@ discard block |
||
90 | 90 | { |
91 | 91 | $_properties = $this->apiProviders[$providerId]; |
92 | 92 | |
93 | - if(($_providerClass = $_properties->remove('class')) === null) |
|
93 | + if (($_providerClass = $_properties->remove('class')) === null) |
|
94 | 94 | throw new TConfigurationException('rpcservice_apiprovider_required'); |
95 | 95 | |
96 | 96 | Prado::using($_providerClass); |
97 | 97 | |
98 | 98 | $_providerClassName = ($_pos = strrpos($_providerClass, '.')) !== false ? substr($_providerClass, $_pos + 1) : $_providerClass; |
99 | - if(!is_subclass_of($_providerClassName, self::BASE_API_PROVIDER)) |
|
99 | + if (!is_subclass_of($_providerClassName, self::BASE_API_PROVIDER)) |
|
100 | 100 | throw new TConfigurationException('rpcservice_apiprovider_invalid'); |
101 | 101 | |
102 | - if(($_rpcServerClass = $_properties->remove('server')) === null) |
|
102 | + if (($_rpcServerClass = $_properties->remove('server')) === null) |
|
103 | 103 | $_rpcServerClass = self::BASE_RPC_SERVER; |
104 | 104 | |
105 | 105 | Prado::using($_rpcServerClass); |
106 | 106 | |
107 | 107 | $_rpcServerClassName = ($_pos = strrpos($_rpcServerClass, '.')) !== false ? substr($_rpcServerClass, $_pos + 1) : $_rpcServerClass; |
108 | - if($_rpcServerClassName!==self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER)) |
|
108 | + if ($_rpcServerClassName !== self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER)) |
|
109 | 109 | throw new TConfigurationException('rpcservice_rpcserver_invalid'); |
110 | 110 | |
111 | 111 | $_apiProvider = new $_providerClassName(new $_rpcServerClassName($protocolHandler)); |
112 | 112 | $_apiProvider->setId($providerId); |
113 | 113 | |
114 | - foreach($_properties as $_key => $_value) |
|
114 | + foreach ($_properties as $_key => $_value) |
|
115 | 115 | $_apiProvider->setSubProperty($_key, $_value); |
116 | 116 | |
117 | 117 | return $_apiProvider; |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function loadConfig(TXmlElement $xml) |
134 | 134 | { |
135 | - foreach($xml->getElementsByTagName('rpcapi') as $_apiProviderXml) |
|
135 | + foreach ($xml->getElementsByTagName('rpcapi') as $_apiProviderXml) |
|
136 | 136 | { |
137 | 137 | $_properties = $_apiProviderXml->getAttributes(); |
138 | 138 | |
139 | - if(($_id = $_properties->remove('id')) === null || $_id == "") |
|
139 | + if (($_id = $_properties->remove('id')) === null || $_id == "") |
|
140 | 140 | throw new TConfigurationException('rpcservice_apiproviderid_required'); |
141 | 141 | |
142 | - if(isset($this->apiProviders[$_id])) |
|
142 | + if (isset($this->apiProviders[$_id])) |
|
143 | 143 | throw new TConfigurationException('rpcservice_apiproviderid_duplicated'); |
144 | 144 | |
145 | 145 | $this->apiProviders[$_id] = $_properties; |
@@ -153,22 +153,22 @@ discard block |
||
153 | 153 | { |
154 | 154 | $_request = $this->getRequest(); |
155 | 155 | |
156 | - if(($_providerId = $_request->getServiceParameter()) == "") |
|
156 | + if (($_providerId = $_request->getServiceParameter()) == "") |
|
157 | 157 | throw new THttpException(400, 'RPC API-Provider id required'); |
158 | 158 | |
159 | - if(($_method = $_request->getRequestType()) != 'POST') |
|
160 | - throw new THttpException(405, 'Invalid request method "'.$_method.'"!'); // TODO Exception muss "Allow POST" Header setzen |
|
159 | + if (($_method = $_request->getRequestType()) != 'POST') |
|
160 | + throw new THttpException(405, 'Invalid request method "' . $_method . '"!'); // TODO Exception muss "Allow POST" Header setzen |
|
161 | 161 | |
162 | - if(($_mimeType = $_request->getContentType()) === null) |
|
162 | + if (($_mimeType = $_request->getContentType()) === null) |
|
163 | 163 | throw new THttpException(406, 'Content-Type is missing!'); // TODO Exception muss gültige Content-Type werte zurück geben |
164 | 164 | |
165 | - if(!in_array($_mimeType, array_keys($this->protocolHandlers))) |
|
165 | + if (!in_array($_mimeType, array_keys($this->protocolHandlers))) |
|
166 | 166 | throw new THttpException(406, 'Unsupported Content-Type!'); // TODO see previous |
167 | 167 | |
168 | 168 | $_protocolHandlerClass = $this->protocolHandlers[$_mimeType]; |
169 | 169 | $_protocolHandler = new $_protocolHandlerClass; |
170 | 170 | |
171 | - if(($_result = $this->createApiProvider($_protocolHandler, $_providerId)->processRequest()) !== null) |
|
171 | + if (($_result = $this->createApiProvider($_protocolHandler, $_providerId)->processRequest()) !== null) |
|
172 | 172 | { |
173 | 173 | $_response = $this->getResponse(); |
174 | 174 | $_protocolHandler->createResponseHeaders($_response); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | { |
239 | 239 | return $this->handler->callMethod($this->getPayload()); |
240 | 240 | } |
241 | - catch(TRpcException $e) |
|
241 | + catch (TRpcException $e) |
|
242 | 242 | { |
243 | 243 | return $this->handler->createErrorResponse($e); |
244 | 244 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | { |
321 | 321 | $this->rpcServer = $rpcServer; |
322 | 322 | |
323 | - foreach($this->registerMethods() as $_methodName => $_methodDetails) |
|
323 | + foreach ($this->registerMethods() as $_methodName => $_methodDetails) |
|
324 | 324 | $this->rpcServer->addRpcMethod($_methodName, $_methodDetails); |
325 | 325 | } |
326 | 326 | |
@@ -418,13 +418,13 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function callApiMethod($methodName, $parameters) |
420 | 420 | { |
421 | - if(!isset($this->rpcMethods[$methodName])) |
|
422 | - throw new TRpcException('Method "'.$methodName.'" not found'); |
|
421 | + if (!isset($this->rpcMethods[$methodName])) |
|
422 | + throw new TRpcException('Method "' . $methodName . '" not found'); |
|
423 | 423 | |
424 | - if($parameters === null) |
|
424 | + if ($parameters === null) |
|
425 | 425 | $parameters = array(); |
426 | 426 | |
427 | - if(!is_array($parameters)) |
|
427 | + if (!is_array($parameters)) |
|
428 | 428 | $parameters = array($parameters); |
429 | 429 | return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters); |
430 | 430 | } |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | */ |
446 | 446 | class TJsonRpcProtocol extends TRpcProtocol |
447 | 447 | { |
448 | - protected $_id=null; |
|
449 | - protected $_specificationVersion=1.0; |
|
448 | + protected $_id = null; |
|
449 | + protected $_specificationVersion = 1.0; |
|
450 | 450 | |
451 | 451 | /** |
452 | 452 | * Handles the RPC request |
@@ -459,31 +459,31 @@ discard block |
||
459 | 459 | { |
460 | 460 | $_request = $this->decode($requestPayload); |
461 | 461 | |
462 | - if(isset($_request['jsonrpc'])) |
|
462 | + if (isset($_request['jsonrpc'])) |
|
463 | 463 | { |
464 | - $this->_specificationVersion=$_request['jsonrpc']; |
|
465 | - if($this->_specificationVersion > 2.0) |
|
464 | + $this->_specificationVersion = $_request['jsonrpc']; |
|
465 | + if ($this->_specificationVersion > 2.0) |
|
466 | 466 | throw new TRpcException('Unsupported specification version', '-32600'); |
467 | 467 | } |
468 | 468 | |
469 | - if(isset($_request['id'])) |
|
470 | - $this->_id=$_request['id']; |
|
469 | + if (isset($_request['id'])) |
|
470 | + $this->_id = $_request['id']; |
|
471 | 471 | |
472 | - if(!isset($_request['method'])) |
|
472 | + if (!isset($_request['method'])) |
|
473 | 473 | throw new TRpcException('Missing request method', '-32600'); |
474 | 474 | |
475 | - if(!isset($_request['params'])) |
|
475 | + if (!isset($_request['params'])) |
|
476 | 476 | $parameters = array(); |
477 | 477 | else |
478 | 478 | $parameters = $_request['params']; |
479 | 479 | |
480 | - if(!is_array($parameters)) |
|
480 | + if (!is_array($parameters)) |
|
481 | 481 | $parameters = array($parameters); |
482 | 482 | |
483 | 483 | // a request without an id is a notification that doesn't need a response |
484 | - if($this->_id !== null) |
|
484 | + if ($this->_id !== null) |
|
485 | 485 | { |
486 | - if($this->_specificationVersion==2.0) |
|
486 | + if ($this->_specificationVersion == 2.0) |
|
487 | 487 | { |
488 | 488 | return $this->encode(array( |
489 | 489 | 'jsonrpc' => '2.0', |
@@ -499,15 +499,15 @@ discard block |
||
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | - catch(TRpcException $e) |
|
502 | + catch (TRpcException $e) |
|
503 | 503 | { |
504 | 504 | return $this->createErrorResponse($e); |
505 | 505 | } |
506 | - catch(THttpException $e) |
|
506 | + catch (THttpException $e) |
|
507 | 507 | { |
508 | 508 | throw $e; |
509 | 509 | } |
510 | - catch(Exception $e) |
|
510 | + catch (Exception $e) |
|
511 | 511 | { |
512 | 512 | return $this->createErrorResponse(new TRpcException('An internal error occured', '-32603')); |
513 | 513 | } |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | */ |
521 | 521 | public function createErrorResponse(TRpcException $exception) |
522 | 522 | { |
523 | - if($this->_specificationVersion==2.0) |
|
523 | + if ($this->_specificationVersion == 2.0) |
|
524 | 524 | { |
525 | 525 | return $this->encode(array( |
526 | 526 | 'id' => $this->_id, |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | private static function checkJsonError() |
581 | 581 | { |
582 | 582 | $errnum = json_last_error(); |
583 | - if($errnum != JSON_ERROR_NONE) |
|
583 | + if ($errnum != JSON_ERROR_NONE) |
|
584 | 584 | throw new Exception("JSON error: $msg", $err); |
585 | 585 | } |
586 | 586 | |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | */ |
594 | 594 | public function callApiMethod($methodName, $parameters) |
595 | 595 | { |
596 | - if(!isset($this->rpcMethods[$methodName])) |
|
597 | - throw new TRpcException('Method "'.$methodName.'" not found', '-32601'); |
|
596 | + if (!isset($this->rpcMethods[$methodName])) |
|
597 | + throw new TRpcException('Method "' . $methodName . '" not found', '-32601'); |
|
598 | 598 | |
599 | 599 | return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters); |
600 | 600 | } |
@@ -663,15 +663,15 @@ discard block |
||
663 | 663 | { |
664 | 664 | return xmlrpc_server_call_method($this->_xmlrpcServer, $requestPayload, null); |
665 | 665 | } |
666 | - catch(TRpcException $e) |
|
666 | + catch (TRpcException $e) |
|
667 | 667 | { |
668 | 668 | return $this->createErrorResponse($e); |
669 | 669 | } |
670 | - catch(THttpException $e) |
|
670 | + catch (THttpException $e) |
|
671 | 671 | { |
672 | 672 | throw $e; |
673 | 673 | } |
674 | - catch(Exception $e) |
|
674 | + catch (Exception $e) |
|
675 | 675 | { |
676 | 676 | return $this->createErrorResponse(new TRpcException('An internal error occured')); |
677 | 677 | } |
@@ -90,29 +90,34 @@ discard block |
||
90 | 90 | { |
91 | 91 | $_properties = $this->apiProviders[$providerId]; |
92 | 92 | |
93 | - if(($_providerClass = $_properties->remove('class')) === null) |
|
94 | - throw new TConfigurationException('rpcservice_apiprovider_required'); |
|
93 | + if(($_providerClass = $_properties->remove('class')) === null) { |
|
94 | + throw new TConfigurationException('rpcservice_apiprovider_required'); |
|
95 | + } |
|
95 | 96 | |
96 | 97 | Prado::using($_providerClass); |
97 | 98 | |
98 | 99 | $_providerClassName = ($_pos = strrpos($_providerClass, '.')) !== false ? substr($_providerClass, $_pos + 1) : $_providerClass; |
99 | - if(!is_subclass_of($_providerClassName, self::BASE_API_PROVIDER)) |
|
100 | - throw new TConfigurationException('rpcservice_apiprovider_invalid'); |
|
100 | + if(!is_subclass_of($_providerClassName, self::BASE_API_PROVIDER)) { |
|
101 | + throw new TConfigurationException('rpcservice_apiprovider_invalid'); |
|
102 | + } |
|
101 | 103 | |
102 | - if(($_rpcServerClass = $_properties->remove('server')) === null) |
|
103 | - $_rpcServerClass = self::BASE_RPC_SERVER; |
|
104 | + if(($_rpcServerClass = $_properties->remove('server')) === null) { |
|
105 | + $_rpcServerClass = self::BASE_RPC_SERVER; |
|
106 | + } |
|
104 | 107 | |
105 | 108 | Prado::using($_rpcServerClass); |
106 | 109 | |
107 | 110 | $_rpcServerClassName = ($_pos = strrpos($_rpcServerClass, '.')) !== false ? substr($_rpcServerClass, $_pos + 1) : $_rpcServerClass; |
108 | - if($_rpcServerClassName!==self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER)) |
|
109 | - throw new TConfigurationException('rpcservice_rpcserver_invalid'); |
|
111 | + if($_rpcServerClassName!==self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER)) { |
|
112 | + throw new TConfigurationException('rpcservice_rpcserver_invalid'); |
|
113 | + } |
|
110 | 114 | |
111 | 115 | $_apiProvider = new $_providerClassName(new $_rpcServerClassName($protocolHandler)); |
112 | 116 | $_apiProvider->setId($providerId); |
113 | 117 | |
114 | - foreach($_properties as $_key => $_value) |
|
115 | - $_apiProvider->setSubProperty($_key, $_value); |
|
118 | + foreach($_properties as $_key => $_value) { |
|
119 | + $_apiProvider->setSubProperty($_key, $_value); |
|
120 | + } |
|
116 | 121 | |
117 | 122 | return $_apiProvider; |
118 | 123 | } |
@@ -136,11 +141,13 @@ discard block |
||
136 | 141 | { |
137 | 142 | $_properties = $_apiProviderXml->getAttributes(); |
138 | 143 | |
139 | - if(($_id = $_properties->remove('id')) === null || $_id == "") |
|
140 | - throw new TConfigurationException('rpcservice_apiproviderid_required'); |
|
144 | + if(($_id = $_properties->remove('id')) === null || $_id == "") { |
|
145 | + throw new TConfigurationException('rpcservice_apiproviderid_required'); |
|
146 | + } |
|
141 | 147 | |
142 | - if(isset($this->apiProviders[$_id])) |
|
143 | - throw new TConfigurationException('rpcservice_apiproviderid_duplicated'); |
|
148 | + if(isset($this->apiProviders[$_id])) { |
|
149 | + throw new TConfigurationException('rpcservice_apiproviderid_duplicated'); |
|
150 | + } |
|
144 | 151 | |
145 | 152 | $this->apiProviders[$_id] = $_properties; |
146 | 153 | } |
@@ -153,17 +160,24 @@ discard block |
||
153 | 160 | { |
154 | 161 | $_request = $this->getRequest(); |
155 | 162 | |
156 | - if(($_providerId = $_request->getServiceParameter()) == "") |
|
157 | - throw new THttpException(400, 'RPC API-Provider id required'); |
|
163 | + if(($_providerId = $_request->getServiceParameter()) == "") { |
|
164 | + throw new THttpException(400, 'RPC API-Provider id required'); |
|
165 | + } |
|
158 | 166 | |
159 | - if(($_method = $_request->getRequestType()) != 'POST') |
|
160 | - throw new THttpException(405, 'Invalid request method "'.$_method.'"!'); // TODO Exception muss "Allow POST" Header setzen |
|
167 | + if(($_method = $_request->getRequestType()) != 'POST') { |
|
168 | + throw new THttpException(405, 'Invalid request method "'.$_method.'"!'); |
|
169 | + } |
|
170 | + // TODO Exception muss "Allow POST" Header setzen |
|
161 | 171 | |
162 | - if(($_mimeType = $_request->getContentType()) === null) |
|
163 | - throw new THttpException(406, 'Content-Type is missing!'); // TODO Exception muss gültige Content-Type werte zurück geben |
|
172 | + if(($_mimeType = $_request->getContentType()) === null) { |
|
173 | + throw new THttpException(406, 'Content-Type is missing!'); |
|
174 | + } |
|
175 | + // TODO Exception muss gültige Content-Type werte zurück geben |
|
164 | 176 | |
165 | - if(!in_array($_mimeType, array_keys($this->protocolHandlers))) |
|
166 | - throw new THttpException(406, 'Unsupported Content-Type!'); // TODO see previous |
|
177 | + if(!in_array($_mimeType, array_keys($this->protocolHandlers))) { |
|
178 | + throw new THttpException(406, 'Unsupported Content-Type!'); |
|
179 | + } |
|
180 | + // TODO see previous |
|
167 | 181 | |
168 | 182 | $_protocolHandlerClass = $this->protocolHandlers[$_mimeType]; |
169 | 183 | $_protocolHandler = new $_protocolHandlerClass; |
@@ -237,8 +251,7 @@ discard block |
||
237 | 251 | try |
238 | 252 | { |
239 | 253 | return $this->handler->callMethod($this->getPayload()); |
240 | - } |
|
241 | - catch(TRpcException $e) |
|
254 | + } catch(TRpcException $e) |
|
242 | 255 | { |
243 | 256 | return $this->handler->createErrorResponse($e); |
244 | 257 | } |
@@ -320,8 +333,9 @@ discard block |
||
320 | 333 | { |
321 | 334 | $this->rpcServer = $rpcServer; |
322 | 335 | |
323 | - foreach($this->registerMethods() as $_methodName => $_methodDetails) |
|
324 | - $this->rpcServer->addRpcMethod($_methodName, $_methodDetails); |
|
336 | + foreach($this->registerMethods() as $_methodName => $_methodDetails) { |
|
337 | + $this->rpcServer->addRpcMethod($_methodName, $_methodDetails); |
|
338 | + } |
|
325 | 339 | } |
326 | 340 | |
327 | 341 | /** |
@@ -418,14 +432,17 @@ discard block |
||
418 | 432 | */ |
419 | 433 | public function callApiMethod($methodName, $parameters) |
420 | 434 | { |
421 | - if(!isset($this->rpcMethods[$methodName])) |
|
422 | - throw new TRpcException('Method "'.$methodName.'" not found'); |
|
435 | + if(!isset($this->rpcMethods[$methodName])) { |
|
436 | + throw new TRpcException('Method "'.$methodName.'" not found'); |
|
437 | + } |
|
423 | 438 | |
424 | - if($parameters === null) |
|
425 | - $parameters = array(); |
|
439 | + if($parameters === null) { |
|
440 | + $parameters = array(); |
|
441 | + } |
|
426 | 442 | |
427 | - if(!is_array($parameters)) |
|
428 | - $parameters = array($parameters); |
|
443 | + if(!is_array($parameters)) { |
|
444 | + $parameters = array($parameters); |
|
445 | + } |
|
429 | 446 | return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters); |
430 | 447 | } |
431 | 448 | } |
@@ -462,23 +479,28 @@ discard block |
||
462 | 479 | if(isset($_request['jsonrpc'])) |
463 | 480 | { |
464 | 481 | $this->_specificationVersion=$_request['jsonrpc']; |
465 | - if($this->_specificationVersion > 2.0) |
|
466 | - throw new TRpcException('Unsupported specification version', '-32600'); |
|
482 | + if($this->_specificationVersion > 2.0) { |
|
483 | + throw new TRpcException('Unsupported specification version', '-32600'); |
|
484 | + } |
|
467 | 485 | } |
468 | 486 | |
469 | - if(isset($_request['id'])) |
|
470 | - $this->_id=$_request['id']; |
|
487 | + if(isset($_request['id'])) { |
|
488 | + $this->_id=$_request['id']; |
|
489 | + } |
|
471 | 490 | |
472 | - if(!isset($_request['method'])) |
|
473 | - throw new TRpcException('Missing request method', '-32600'); |
|
491 | + if(!isset($_request['method'])) { |
|
492 | + throw new TRpcException('Missing request method', '-32600'); |
|
493 | + } |
|
474 | 494 | |
475 | - if(!isset($_request['params'])) |
|
476 | - $parameters = array(); |
|
477 | - else |
|
478 | - $parameters = $_request['params']; |
|
495 | + if(!isset($_request['params'])) { |
|
496 | + $parameters = array(); |
|
497 | + } else { |
|
498 | + $parameters = $_request['params']; |
|
499 | + } |
|
479 | 500 | |
480 | - if(!is_array($parameters)) |
|
481 | - $parameters = array($parameters); |
|
501 | + if(!is_array($parameters)) { |
|
502 | + $parameters = array($parameters); |
|
503 | + } |
|
482 | 504 | |
483 | 505 | // a request without an id is a notification that doesn't need a response |
484 | 506 | if($this->_id !== null) |
@@ -498,16 +520,13 @@ discard block |
||
498 | 520 | )); |
499 | 521 | } |
500 | 522 | } |
501 | - } |
|
502 | - catch(TRpcException $e) |
|
523 | + } catch(TRpcException $e) |
|
503 | 524 | { |
504 | 525 | return $this->createErrorResponse($e); |
505 | - } |
|
506 | - catch(THttpException $e) |
|
526 | + } catch(THttpException $e) |
|
507 | 527 | { |
508 | 528 | throw $e; |
509 | - } |
|
510 | - catch(Exception $e) |
|
529 | + } catch(Exception $e) |
|
511 | 530 | { |
512 | 531 | return $this->createErrorResponse(new TRpcException('An internal error occured', '-32603')); |
513 | 532 | } |
@@ -580,8 +599,9 @@ discard block |
||
580 | 599 | private static function checkJsonError() |
581 | 600 | { |
582 | 601 | $errnum = json_last_error(); |
583 | - if($errnum != JSON_ERROR_NONE) |
|
584 | - throw new Exception("JSON error: $msg", $err); |
|
602 | + if($errnum != JSON_ERROR_NONE) { |
|
603 | + throw new Exception("JSON error: $msg", $err); |
|
604 | + } |
|
585 | 605 | } |
586 | 606 | |
587 | 607 | /** |
@@ -593,8 +613,9 @@ discard block |
||
593 | 613 | */ |
594 | 614 | public function callApiMethod($methodName, $parameters) |
595 | 615 | { |
596 | - if(!isset($this->rpcMethods[$methodName])) |
|
597 | - throw new TRpcException('Method "'.$methodName.'" not found', '-32601'); |
|
616 | + if(!isset($this->rpcMethods[$methodName])) { |
|
617 | + throw new TRpcException('Method "'.$methodName.'" not found', '-32601'); |
|
618 | + } |
|
598 | 619 | |
599 | 620 | return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters); |
600 | 621 | } |
@@ -662,16 +683,13 @@ discard block |
||
662 | 683 | try |
663 | 684 | { |
664 | 685 | return xmlrpc_server_call_method($this->_xmlrpcServer, $requestPayload, null); |
665 | - } |
|
666 | - catch(TRpcException $e) |
|
686 | + } catch(TRpcException $e) |
|
667 | 687 | { |
668 | 688 | return $this->createErrorResponse($e); |
669 | - } |
|
670 | - catch(THttpException $e) |
|
689 | + } catch(THttpException $e) |
|
671 | 690 | { |
672 | 691 | throw $e; |
673 | - } |
|
674 | - catch(Exception $e) |
|
692 | + } catch(Exception $e) |
|
675 | 693 | { |
676 | 694 | return $this->createErrorResponse(new TRpcException('An internal error occured')); |
677 | 695 | } |
@@ -101,6 +101,7 @@ discard block |
||
101 | 101 | * Sets the root directory storing published asset files. |
102 | 102 | * The directory must be in namespace format. |
103 | 103 | * @param string the root directory storing published asset files |
104 | + * @param string $value |
|
104 | 105 | * @throws TInvalidOperationException if the module is initialized already |
105 | 106 | */ |
106 | 107 | public function setBasePath($value) |
@@ -125,6 +126,7 @@ discard block |
||
125 | 126 | |
126 | 127 | /** |
127 | 128 | * @param string the base url that the published asset files can be accessed |
129 | + * @param string $value |
|
128 | 130 | * @throws TInvalidOperationException if the module is initialized already |
129 | 131 | */ |
130 | 132 | public function setBaseUrl($value) |
@@ -215,6 +217,7 @@ discard block |
||
215 | 217 | * This method does not perform any publishing. It merely tells you |
216 | 218 | * if the file path is published, what the URL will be to access it. |
217 | 219 | * @param string directory or file path being published |
220 | + * @param string $path |
|
218 | 221 | * @return string the published URL for the file path |
219 | 222 | */ |
220 | 223 | public function getPublishedUrl($path) |
@@ -230,6 +233,7 @@ discard block |
||
230 | 233 | * Generate a CRC32 hash for the directory path. Collisions are higher |
231 | 234 | * than MD5 but generates a much smaller hash string. |
232 | 235 | * @param string string to be hashed. |
236 | + * @param string $dir |
|
233 | 237 | * @return string hashed string. |
234 | 238 | */ |
235 | 239 | protected function hash($dir) |
@@ -243,6 +247,8 @@ discard block |
||
243 | 247 | * or has an older file modification time. |
244 | 248 | * @param string source file path |
245 | 249 | * @param string destination directory (if not exists, it will be created) |
250 | + * @param string $src |
|
251 | + * @param string $dst |
|
246 | 252 | */ |
247 | 253 | protected function copyFile($src,$dst) |
248 | 254 | { |
@@ -265,6 +271,8 @@ discard block |
||
265 | 271 | * File modification time is used to ensure the copied files are latest. |
266 | 272 | * @param string the source directory |
267 | 273 | * @param string the destination directory |
274 | + * @param string $src |
|
275 | + * @param string $dst |
|
268 | 276 | * @todo a generic solution to ignore certain directories and files |
269 | 277 | */ |
270 | 278 | public function copyDirectory($src,$dst) |
@@ -306,6 +314,8 @@ discard block |
||
306 | 314 | * @param string tar filename |
307 | 315 | * @param string MD5 checksum for the corresponding tar file. |
308 | 316 | * @param boolean Wether or not to check the time stamp of the file for publishing. Defaults to false. |
317 | + * @param string $tarfile |
|
318 | + * @param string $md5sum |
|
309 | 319 | * @return string URL path to the directory where the tar file was extracted. |
310 | 320 | */ |
311 | 321 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false) |
@@ -336,6 +346,7 @@ discard block |
||
336 | 346 | * N.B Tar file must not be compressed. |
337 | 347 | * @param string tar file |
338 | 348 | * @param string path where the contents of tar file are to be extracted |
349 | + * @param string $destination |
|
339 | 350 | * @return boolean true if extract successful, false otherwise. |
340 | 351 | */ |
341 | 352 | protected function deployTarFile($path,$destination) |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * Default web accessible base path for storing private files |
47 | 47 | */ |
48 | - const DEFAULT_BASEPATH='assets'; |
|
48 | + const DEFAULT_BASEPATH = 'assets'; |
|
49 | 49 | /** |
50 | 50 | * @var string base web accessible path for storing private files |
51 | 51 | */ |
52 | - private $_basePath=null; |
|
52 | + private $_basePath = null; |
|
53 | 53 | /** |
54 | 54 | * @var string base URL for accessing the publishing directory. |
55 | 55 | */ |
56 | - private $_baseUrl=null; |
|
56 | + private $_baseUrl = null; |
|
57 | 57 | /** |
58 | 58 | * @var boolean whether to use timestamp checking to ensure files are published with up-to-date versions. |
59 | 59 | */ |
60 | - private $_checkTimestamp=false; |
|
60 | + private $_checkTimestamp = false; |
|
61 | 61 | /** |
62 | 62 | * @var TApplication application instance |
63 | 63 | */ |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * @var array published assets |
67 | 67 | */ |
68 | - private $_published=array(); |
|
68 | + private $_published = array(); |
|
69 | 69 | /** |
70 | 70 | * @var boolean whether the module is initialized |
71 | 71 | */ |
72 | - private $_initialized=false; |
|
72 | + private $_initialized = false; |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Initializes the module. |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function init($config) |
80 | 80 | { |
81 | - $application=$this->getApplication(); |
|
82 | - if($this->_basePath===null) |
|
83 | - $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
84 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
85 | - throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath); |
|
86 | - if($this->_baseUrl===null) |
|
87 | - $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH; |
|
81 | + $application = $this->getApplication(); |
|
82 | + if ($this->_basePath === null) |
|
83 | + $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
84 | + if (!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
85 | + throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
|
86 | + if ($this->_baseUrl === null) |
|
87 | + $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
88 | 88 | $application->setAssetManager($this); |
89 | - $this->_initialized=true; |
|
89 | + $this->_initialized = true; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function setBasePath($value) |
107 | 107 | { |
108 | - if($this->_initialized) |
|
108 | + if ($this->_initialized) |
|
109 | 109 | throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
110 | 110 | else |
111 | 111 | { |
112 | - $this->_basePath=Prado::getPathOfNamespace($value); |
|
113 | - if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
114 | - throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value); |
|
112 | + $this->_basePath = Prado::getPathOfNamespace($value); |
|
113 | + if ($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
114 | + throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function setBaseUrl($value) |
131 | 131 | { |
132 | - if($this->_initialized) |
|
132 | + if ($this->_initialized) |
|
133 | 133 | throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
134 | 134 | else |
135 | - $this->_baseUrl=rtrim($value,'/'); |
|
135 | + $this->_baseUrl = rtrim($value, '/'); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -149,30 +149,30 @@ discard block |
||
149 | 149 | * @throws TInvalidDataValueException if the file path to be published is |
150 | 150 | * invalid |
151 | 151 | */ |
152 | - public function publishFilePath($path,$checkTimestamp=false) |
|
152 | + public function publishFilePath($path, $checkTimestamp = false) |
|
153 | 153 | { |
154 | - if(isset($this->_published[$path])) |
|
154 | + if (isset($this->_published[$path])) |
|
155 | 155 | return $this->_published[$path]; |
156 | - else if(empty($path) || ($fullpath=realpath($path))===false) |
|
157 | - throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); |
|
158 | - else if(is_file($fullpath)) |
|
156 | + else if (empty($path) || ($fullpath = realpath($path)) === false) |
|
157 | + throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
|
158 | + else if (is_file($fullpath)) |
|
159 | 159 | { |
160 | - $dir=$this->hash(dirname($fullpath)); |
|
161 | - $fileName=basename($fullpath); |
|
162 | - $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir; |
|
163 | - if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
164 | - $this->copyFile($fullpath,$dst); |
|
165 | - return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName; |
|
160 | + $dir = $this->hash(dirname($fullpath)); |
|
161 | + $fileName = basename($fullpath); |
|
162 | + $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
|
163 | + if (!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
164 | + $this->copyFile($fullpath, $dst); |
|
165 | + return $this->_published[$path] = $this->_baseUrl . '/' . $dir . '/' . $fileName; |
|
166 | 166 | } |
167 | 167 | else |
168 | 168 | { |
169 | - $dir=$this->hash($fullpath); |
|
170 | - if(!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
169 | + $dir = $this->hash($fullpath); |
|
170 | + if (!is_dir($this->_basePath . DIRECTORY_SEPARATOR . $dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
171 | 171 | { |
172 | - Prado::trace("Publishing directory $fullpath",'System.Web.UI.TAssetManager'); |
|
173 | - $this->copyDirectory($fullpath,$this->_basePath.DIRECTORY_SEPARATOR.$dir); |
|
172 | + Prado::trace("Publishing directory $fullpath", 'System.Web.UI.TAssetManager'); |
|
173 | + $this->copyDirectory($fullpath, $this->_basePath . DIRECTORY_SEPARATOR . $dir); |
|
174 | 174 | } |
175 | - return $this->_published[$path]=$this->_baseUrl.'/'.$dir; |
|
175 | + return $this->_published[$path] = $this->_baseUrl . '/' . $dir; |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @param $values List of published assets |
190 | 190 | * @since 3.1.6 |
191 | 191 | */ |
192 | - protected function setPublished($values=array()) |
|
192 | + protected function setPublished($values = array()) |
|
193 | 193 | { |
194 | 194 | $this->_published = $values; |
195 | 195 | } |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function getPublishedPath($path) |
205 | 205 | { |
206 | - $path=realpath($path); |
|
207 | - if(is_file($path)) |
|
208 | - return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
206 | + $path = realpath($path); |
|
207 | + if (is_file($path)) |
|
208 | + return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
209 | 209 | else |
210 | - return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
210 | + return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function getPublishedUrl($path) |
221 | 221 | { |
222 | - $path=realpath($path); |
|
223 | - if(is_file($path)) |
|
224 | - return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
222 | + $path = realpath($path); |
|
223 | + if (is_file($path)) |
|
224 | + return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
225 | 225 | else |
226 | - return $this->_baseUrl.'/'.$this->hash($path); |
|
226 | + return $this->_baseUrl . '/' . $this->hash($path); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | protected function hash($dir) |
236 | 236 | { |
237 | - return sprintf('%x',crc32($dir.Prado::getVersion())); |
|
237 | + return sprintf('%x', crc32($dir . Prado::getVersion())); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,18 +244,18 @@ discard block |
||
244 | 244 | * @param string source file path |
245 | 245 | * @param string destination directory (if not exists, it will be created) |
246 | 246 | */ |
247 | - protected function copyFile($src,$dst) |
|
247 | + protected function copyFile($src, $dst) |
|
248 | 248 | { |
249 | - if(!is_dir($dst)) |
|
249 | + if (!is_dir($dst)) |
|
250 | 250 | { |
251 | 251 | @mkdir($dst); |
252 | 252 | @chmod($dst, PRADO_CHMOD); |
253 | 253 | } |
254 | - $dstFile=$dst.DIRECTORY_SEPARATOR.basename($src); |
|
255 | - if(@filemtime($dstFile)<@filemtime($src)) |
|
254 | + $dstFile = $dst . DIRECTORY_SEPARATOR . basename($src); |
|
255 | + if (@filemtime($dstFile) < @filemtime($src)) |
|
256 | 256 | { |
257 | - Prado::trace("Publishing file $src to $dstFile",'System.Web.TAssetManager'); |
|
258 | - @copy($src,$dstFile); |
|
257 | + Prado::trace("Publishing file $src to $dstFile", 'System.Web.TAssetManager'); |
|
258 | + @copy($src, $dstFile); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
@@ -267,29 +267,29 @@ discard block |
||
267 | 267 | * @param string the destination directory |
268 | 268 | * @todo a generic solution to ignore certain directories and files |
269 | 269 | */ |
270 | - public function copyDirectory($src,$dst) |
|
270 | + public function copyDirectory($src, $dst) |
|
271 | 271 | { |
272 | - if(!is_dir($dst)) |
|
272 | + if (!is_dir($dst)) |
|
273 | 273 | { |
274 | 274 | @mkdir($dst); |
275 | 275 | @chmod($dst, PRADO_CHMOD); |
276 | 276 | } |
277 | - if($folder=@opendir($src)) |
|
277 | + if ($folder = @opendir($src)) |
|
278 | 278 | { |
279 | - while($file=@readdir($folder)) |
|
279 | + while ($file = @readdir($folder)) |
|
280 | 280 | { |
281 | - if($file==='.' || $file==='..' || $file==='.svn') |
|
281 | + if ($file === '.' || $file === '..' || $file === '.svn') |
|
282 | 282 | continue; |
283 | - else if(is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
283 | + else if (is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
284 | 284 | { |
285 | - if(@filemtime($dst.DIRECTORY_SEPARATOR.$file)<@filemtime($src.DIRECTORY_SEPARATOR.$file)) |
|
285 | + if (@filemtime($dst . DIRECTORY_SEPARATOR . $file) < @filemtime($src . DIRECTORY_SEPARATOR . $file)) |
|
286 | 286 | { |
287 | - @copy($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
|
288 | - @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD); |
|
287 | + @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
288 | + @chmod($dst . DIRECTORY_SEPARATOR . $file, PRADO_CHMOD); |
|
289 | 289 | } |
290 | 290 | } |
291 | 291 | else |
292 | - $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
|
292 | + $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
293 | 293 | } |
294 | 294 | closedir($folder); |
295 | 295 | } else { |
@@ -308,26 +308,26 @@ discard block |
||
308 | 308 | * @param boolean Wether or not to check the time stamp of the file for publishing. Defaults to false. |
309 | 309 | * @return string URL path to the directory where the tar file was extracted. |
310 | 310 | */ |
311 | - public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false) |
|
311 | + public function publishTarFile($tarfile, $md5sum, $checkTimestamp = false) |
|
312 | 312 | { |
313 | - if(isset($this->_published[$md5sum])) |
|
313 | + if (isset($this->_published[$md5sum])) |
|
314 | 314 | return $this->_published[$md5sum]; |
315 | - else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath)) |
|
316 | - throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum); |
|
315 | + else if (($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
316 | + throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
|
317 | 317 | else |
318 | 318 | { |
319 | - $dir=$this->hash(dirname($fullpath)); |
|
320 | - $fileName=basename($fullpath); |
|
321 | - $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir; |
|
322 | - if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
319 | + $dir = $this->hash(dirname($fullpath)); |
|
320 | + $fileName = basename($fullpath); |
|
321 | + $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
|
322 | + if (!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
323 | 323 | { |
324 | - if(@filemtime($dst.DIRECTORY_SEPARATOR.$fileName)<@filemtime($fullpath)) |
|
324 | + if (@filemtime($dst . DIRECTORY_SEPARATOR . $fileName) < @filemtime($fullpath)) |
|
325 | 325 | { |
326 | - $this->copyFile($fullpath,$dst); |
|
327 | - $this->deployTarFile($tarfile,$dst); |
|
326 | + $this->copyFile($fullpath, $dst); |
|
327 | + $this->deployTarFile($tarfile, $dst); |
|
328 | 328 | } |
329 | 329 | } |
330 | - return $this->_published[$md5sum]=$this->_baseUrl.'/'.$dir; |
|
330 | + return $this->_published[$md5sum] = $this->_baseUrl . '/' . $dir; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | * @param string path where the contents of tar file are to be extracted |
339 | 339 | * @return boolean true if extract successful, false otherwise. |
340 | 340 | */ |
341 | - protected function deployTarFile($path,$destination) |
|
341 | + protected function deployTarFile($path, $destination) |
|
342 | 342 | { |
343 | - if(($fullpath=realpath($path))===false || !is_file($fullpath)) |
|
344 | - throw new TIOException('assetmanager_tarfile_invalid',$path); |
|
343 | + if (($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
344 | + throw new TIOException('assetmanager_tarfile_invalid', $path); |
|
345 | 345 | else |
346 | 346 | { |
347 | 347 | Prado::using('System.IO.TTarFileExtractor'); |
@@ -79,12 +79,15 @@ discard block |
||
79 | 79 | public function init($config) |
80 | 80 | { |
81 | 81 | $application=$this->getApplication(); |
82 | - if($this->_basePath===null) |
|
83 | - $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
84 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
85 | - throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath); |
|
86 | - if($this->_baseUrl===null) |
|
87 | - $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH; |
|
82 | + if($this->_basePath===null) { |
|
83 | + $this->_basePath=dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
84 | + } |
|
85 | + if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) { |
|
86 | + throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath); |
|
87 | + } |
|
88 | + if($this->_baseUrl===null) { |
|
89 | + $this->_baseUrl=rtrim(dirname($application->getRequest()->getApplicationUrl()),'/\\').'/'.self::DEFAULT_BASEPATH; |
|
90 | + } |
|
88 | 91 | $application->setAssetManager($this); |
89 | 92 | $this->_initialized=true; |
90 | 93 | } |
@@ -105,13 +108,14 @@ discard block |
||
105 | 108 | */ |
106 | 109 | public function setBasePath($value) |
107 | 110 | { |
108 | - if($this->_initialized) |
|
109 | - throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
110 | - else |
|
111 | + if($this->_initialized) { |
|
112 | + throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
113 | + } else |
|
111 | 114 | { |
112 | 115 | $this->_basePath=Prado::getPathOfNamespace($value); |
113 | - if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
114 | - throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value); |
|
116 | + if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) { |
|
117 | + throw new TInvalidDataValueException('assetmanager_basepath_invalid',$value); |
|
118 | + } |
|
115 | 119 | } |
116 | 120 | } |
117 | 121 | |
@@ -129,10 +133,11 @@ discard block |
||
129 | 133 | */ |
130 | 134 | public function setBaseUrl($value) |
131 | 135 | { |
132 | - if($this->_initialized) |
|
133 | - throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
134 | - else |
|
135 | - $this->_baseUrl=rtrim($value,'/'); |
|
136 | + if($this->_initialized) { |
|
137 | + throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
138 | + } else { |
|
139 | + $this->_baseUrl=rtrim($value,'/'); |
|
140 | + } |
|
136 | 141 | } |
137 | 142 | |
138 | 143 | /** |
@@ -151,20 +156,20 @@ discard block |
||
151 | 156 | */ |
152 | 157 | public function publishFilePath($path,$checkTimestamp=false) |
153 | 158 | { |
154 | - if(isset($this->_published[$path])) |
|
155 | - return $this->_published[$path]; |
|
156 | - else if(empty($path) || ($fullpath=realpath($path))===false) |
|
157 | - throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); |
|
158 | - else if(is_file($fullpath)) |
|
159 | + if(isset($this->_published[$path])) { |
|
160 | + return $this->_published[$path]; |
|
161 | + } else if(empty($path) || ($fullpath=realpath($path))===false) { |
|
162 | + throw new TInvalidDataValueException('assetmanager_filepath_invalid',$path); |
|
163 | + } else if(is_file($fullpath)) |
|
159 | 164 | { |
160 | 165 | $dir=$this->hash(dirname($fullpath)); |
161 | 166 | $fileName=basename($fullpath); |
162 | 167 | $dst=$this->_basePath.DIRECTORY_SEPARATOR.$dir; |
163 | - if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
164 | - $this->copyFile($fullpath,$dst); |
|
168 | + if(!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) { |
|
169 | + $this->copyFile($fullpath,$dst); |
|
170 | + } |
|
165 | 171 | return $this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.$fileName; |
166 | - } |
|
167 | - else |
|
172 | + } else |
|
168 | 173 | { |
169 | 174 | $dir=$this->hash($fullpath); |
170 | 175 | if(!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplicationMode::Performance) |
@@ -204,10 +209,11 @@ discard block |
||
204 | 209 | public function getPublishedPath($path) |
205 | 210 | { |
206 | 211 | $path=realpath($path); |
207 | - if(is_file($path)) |
|
208 | - return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
209 | - else |
|
210 | - return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
212 | + if(is_file($path)) { |
|
213 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
214 | + } else { |
|
215 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
216 | + } |
|
211 | 217 | } |
212 | 218 | |
213 | 219 | /** |
@@ -220,10 +226,11 @@ discard block |
||
220 | 226 | public function getPublishedUrl($path) |
221 | 227 | { |
222 | 228 | $path=realpath($path); |
223 | - if(is_file($path)) |
|
224 | - return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
225 | - else |
|
226 | - return $this->_baseUrl.'/'.$this->hash($path); |
|
229 | + if(is_file($path)) { |
|
230 | + return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
231 | + } else { |
|
232 | + return $this->_baseUrl.'/'.$this->hash($path); |
|
233 | + } |
|
227 | 234 | } |
228 | 235 | |
229 | 236 | /** |
@@ -278,18 +285,18 @@ discard block |
||
278 | 285 | { |
279 | 286 | while($file=@readdir($folder)) |
280 | 287 | { |
281 | - if($file==='.' || $file==='..' || $file==='.svn') |
|
282 | - continue; |
|
283 | - else if(is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
288 | + if($file==='.' || $file==='..' || $file==='.svn') { |
|
289 | + continue; |
|
290 | + } else if(is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
284 | 291 | { |
285 | 292 | if(@filemtime($dst.DIRECTORY_SEPARATOR.$file)<@filemtime($src.DIRECTORY_SEPARATOR.$file)) |
286 | 293 | { |
287 | 294 | @copy($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
288 | 295 | @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD); |
289 | 296 | } |
297 | + } else { |
|
298 | + $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
|
290 | 299 | } |
291 | - else |
|
292 | - $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file,$dst.DIRECTORY_SEPARATOR.$file); |
|
293 | 300 | } |
294 | 301 | closedir($folder); |
295 | 302 | } else { |
@@ -310,11 +317,11 @@ discard block |
||
310 | 317 | */ |
311 | 318 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp=false) |
312 | 319 | { |
313 | - if(isset($this->_published[$md5sum])) |
|
314 | - return $this->_published[$md5sum]; |
|
315 | - else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath)) |
|
316 | - throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum); |
|
317 | - else |
|
320 | + if(isset($this->_published[$md5sum])) { |
|
321 | + return $this->_published[$md5sum]; |
|
322 | + } else if(($fullpath=realpath($md5sum))===false || !is_file($fullpath)) { |
|
323 | + throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid',$md5sum); |
|
324 | + } else |
|
318 | 325 | { |
319 | 326 | $dir=$this->hash(dirname($fullpath)); |
320 | 327 | $fileName=basename($fullpath); |
@@ -340,9 +347,9 @@ discard block |
||
340 | 347 | */ |
341 | 348 | protected function deployTarFile($path,$destination) |
342 | 349 | { |
343 | - if(($fullpath=realpath($path))===false || !is_file($fullpath)) |
|
344 | - throw new TIOException('assetmanager_tarfile_invalid',$path); |
|
345 | - else |
|
350 | + if(($fullpath=realpath($path))===false || !is_file($fullpath)) { |
|
351 | + throw new TIOException('assetmanager_tarfile_invalid',$path); |
|
352 | + } else |
|
346 | 353 | { |
347 | 354 | Prado::using('System.IO.TTarFileExtractor'); |
348 | 355 | $tar = new TTarFileExtractor($fullpath); |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TAssetManager class |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Web |
|
10 | - */ |
|
3 | + * TAssetManager class |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Web |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * TAssetManager class |