@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function init($config) |
169 | 169 | { |
170 | - if($this->_bufferOutput) |
|
170 | + if ($this->_bufferOutput) |
|
171 | 171 | ob_start(); |
172 | 172 | $this->_initialized = true; |
173 | 173 | $this->getApplication()->setResponse($this); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | public function setCacheControl($value) |
205 | 205 | { |
206 | - session_cache_limiter(TPropertyValue::ensureEnum($value, ['none','nocache','private','private_no_expire','public'])); |
|
206 | + session_cache_limiter(TPropertyValue::ensureEnum($value, ['none', 'nocache', 'private', 'private_no_expire', 'public'])); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public function setCharset($charset) |
239 | 239 | { |
240 | - $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset; |
|
240 | + $this->_charset = (strToLower($charset) === 'false') ? false : (string) $charset; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function setBufferOutput($value) |
256 | 256 | { |
257 | - if($this->_initialized) |
|
257 | + if ($this->_initialized) |
|
258 | 258 | throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
259 | 259 | else |
260 | 260 | $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | if ($this->_httpHeaderSent) |
282 | 282 | throw new \Exception('Unable to alter response as HTTP header already sent'); |
283 | 283 | $status = TPropertyValue::ensureInteger($status); |
284 | - if(isset(self::$HTTP_STATUS_CODES[$status])) { |
|
284 | + if (isset(self::$HTTP_STATUS_CODES[$status])) { |
|
285 | 285 | $this->_reason = self::$HTTP_STATUS_CODES[$status]; |
286 | - }else{ |
|
287 | - if($reason === null || $reason === '') { |
|
286 | + } else { |
|
287 | + if ($reason === null || $reason === '') { |
|
288 | 288 | throw new TInvalidDataValueException("response_status_reason_missing"); |
289 | 289 | } |
290 | 290 | $reason = TPropertyValue::ensureString($reason); |
291 | - if(strpos($reason, "\r") != false || strpos($reason, "\n") != false) { |
|
291 | + if (strpos($reason, "\r") != false || strpos($reason, "\n") != false) { |
|
292 | 292 | throw new TInvalidDataValueException("response_status_reason_barchars"); |
293 | 293 | } |
294 | 294 | $this->_reason = $reason; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function getCookies() |
310 | 310 | { |
311 | - if($this->_cookies === null) |
|
311 | + if ($this->_cookies === null) |
|
312 | 312 | $this->_cookies = new THttpCookieCollection($this); |
313 | 313 | return $this->_cookies; |
314 | 314 | } |
@@ -353,31 +353,31 @@ discard block |
||
353 | 353 | 'xls' => 'application/vnd.ms-excel', |
354 | 354 | ]; |
355 | 355 | |
356 | - if($mimeType === null) |
|
356 | + if ($mimeType === null) |
|
357 | 357 | { |
358 | 358 | $mimeType = 'text/plain'; |
359 | - if(function_exists('mime_content_type')) |
|
359 | + if (function_exists('mime_content_type')) |
|
360 | 360 | $mimeType = mime_content_type($fileName); |
361 | - elseif(($ext = strrchr($fileName, '.')) !== false) |
|
361 | + elseif (($ext = strrchr($fileName, '.')) !== false) |
|
362 | 362 | { |
363 | 363 | $ext = substr($ext, 1); |
364 | - if(isset($defaultMimeTypes[$ext])) |
|
364 | + if (isset($defaultMimeTypes[$ext])) |
|
365 | 365 | $mimeType = $defaultMimeTypes[$ext]; |
366 | 366 | } |
367 | 367 | } |
368 | 368 | |
369 | - if($clientFileName === null) |
|
369 | + if ($clientFileName === null) |
|
370 | 370 | $clientFileName = basename($fileName); |
371 | 371 | else |
372 | 372 | $clientFileName = basename($clientFileName); |
373 | 373 | |
374 | - if($fileSize === null || $fileSize < 0) |
|
375 | - $fileSize = ($content === null?filesize($fileName):strlen($content)); |
|
374 | + if ($fileSize === null || $fileSize < 0) |
|
375 | + $fileSize = ($content === null ?filesize($fileName) : strlen($content)); |
|
376 | 376 | |
377 | 377 | $this->sendHttpHeader(); |
378 | - if(is_array($headers)) |
|
378 | + if (is_array($headers)) |
|
379 | 379 | { |
380 | - foreach($headers as $h) |
|
380 | + foreach ($headers as $h) |
|
381 | 381 | header($h); |
382 | 382 | } |
383 | 383 | else |
@@ -389,10 +389,10 @@ discard block |
||
389 | 389 | $this->_contentTypeHeaderSent = true; |
390 | 390 | } |
391 | 391 | |
392 | - header('Content-Length: ' . $fileSize); |
|
393 | - header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
|
392 | + header('Content-Length: '.$fileSize); |
|
393 | + header("Content-Disposition: ".($forceDownload ? 'attachment' : 'inline')."; filename=\"$clientFileName\""); |
|
394 | 394 | header('Content-Transfer-Encoding: binary'); |
395 | - if($content === null) |
|
395 | + if ($content === null) |
|
396 | 396 | readfile($fileName); |
397 | 397 | else |
398 | 398 | echo $content; |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | */ |
407 | 407 | public function redirect($url) |
408 | 408 | { |
409 | - if($this->getHasAdapter()) |
|
409 | + if ($this->getHasAdapter()) |
|
410 | 410 | $this->_adapter->httpRedirect($url); |
411 | 411 | else |
412 | 412 | $this->httpRedirect($url); |
@@ -431,27 +431,27 @@ discard block |
||
431 | 431 | // Under IIS, explicitly send an HTTP response including the status code |
432 | 432 | // this is handled automatically by PHP on Apache and others |
433 | 433 | $isIIS = (stripos($this->getRequest()->getServerSoftware(), "microsoft-iis") !== false); |
434 | - if($url[0] === '/') |
|
435 | - $url = $this->getRequest()->getBaseUrl() . $url; |
|
434 | + if ($url[0] === '/') |
|
435 | + $url = $this->getRequest()->getBaseUrl().$url; |
|
436 | 436 | if ($this->_status >= 300 && $this->_status < 400) |
437 | 437 | { |
438 | 438 | // The status code has been modified to a valid redirection status, send it |
439 | - if($isIIS) |
|
439 | + if ($isIIS) |
|
440 | 440 | { |
441 | - header('HTTP/1.1 ' . $this->_status . ' ' . self::$HTTP_STATUS_CODES[ |
|
441 | + header('HTTP/1.1 '.$this->_status.' '.self::$HTTP_STATUS_CODES[ |
|
442 | 442 | array_key_exists($this->_status, self::$HTTP_STATUS_CODES) |
443 | 443 | ? $this->_status |
444 | 444 | : 302 |
445 | 445 | ]); |
446 | 446 | } |
447 | - header('Location: ' . str_replace('&', '&', $url), true, $this->_status); |
|
447 | + header('Location: '.str_replace('&', '&', $url), true, $this->_status); |
|
448 | 448 | } else { |
449 | - if($isIIS) |
|
450 | - header('HTTP/1.1 302 ' . self::$HTTP_STATUS_CODES[302]); |
|
451 | - header('Location: ' . str_replace('&', '&', $url)); |
|
449 | + if ($isIIS) |
|
450 | + header('HTTP/1.1 302 '.self::$HTTP_STATUS_CODES[302]); |
|
451 | + header('Location: '.str_replace('&', '&', $url)); |
|
452 | 452 | } |
453 | 453 | |
454 | - if(!$this->getApplication()->getRequestCompleted()) |
|
454 | + if (!$this->getApplication()->getRequestCompleted()) |
|
455 | 455 | $this->getApplication()->onEndRequest(); |
456 | 456 | |
457 | 457 | exit(); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | */ |
473 | 473 | public function flush($continueBuffering = true) |
474 | 474 | { |
475 | - if($this->getHasAdapter()) |
|
475 | + if ($this->getHasAdapter()) |
|
476 | 476 | $this->_adapter->flushContent($continueBuffering); |
477 | 477 | else |
478 | 478 | $this->flushContent($continueBuffering); |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | { |
497 | 497 | Prado::trace("Flushing output", 'Prado\Web\THttpResponse'); |
498 | 498 | $this->ensureHeadersSent(); |
499 | - if($this->_bufferOutput) |
|
499 | + if ($this->_bufferOutput) |
|
500 | 500 | { |
501 | 501 | // avoid forced send of http headers (ob_flush() does that) if there's no output yet |
502 | 502 | if (ob_get_length() > 0) |
@@ -530,10 +530,10 @@ discard block |
||
530 | 530 | protected function sendHttpHeader() |
531 | 531 | { |
532 | 532 | $protocol = $this->getRequest()->getHttpProtocolVersion(); |
533 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
533 | + if ($this->getRequest()->getHttpProtocolVersion() === null) |
|
534 | 534 | $protocol = 'HTTP/1.1'; |
535 | 535 | |
536 | - header($protocol . ' ' . $this->_status . ' ' . $this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
|
536 | + header($protocol.' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
|
537 | 537 | |
538 | 538 | $this->_httpHeaderSent = true; |
539 | 539 | } |
@@ -552,18 +552,18 @@ discard block |
||
552 | 552 | */ |
553 | 553 | protected function sendContentTypeHeader() |
554 | 554 | { |
555 | - $contentType = $this->_contentType === null?self::DEFAULT_CONTENTTYPE:$this->_contentType; |
|
555 | + $contentType = $this->_contentType === null ?self::DEFAULT_CONTENTTYPE : $this->_contentType; |
|
556 | 556 | $charset = $this->getCharset(); |
557 | - if($charset === false) { |
|
558 | - $this->appendHeader('Content-Type: ' . $contentType); |
|
557 | + if ($charset === false) { |
|
558 | + $this->appendHeader('Content-Type: '.$contentType); |
|
559 | 559 | return; |
560 | 560 | } |
561 | 561 | |
562 | - if($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
562 | + if ($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
563 | 563 | $charset = $globalization->getCharset(); |
564 | 564 | |
565 | - if($charset === '') $charset = self::DEFAULT_CHARSET; |
|
566 | - $this->appendHeader('Content-Type: ' . $contentType . ';charset=' . $charset); |
|
565 | + if ($charset === '') $charset = self::DEFAULT_CHARSET; |
|
566 | + $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
|
567 | 567 | |
568 | 568 | $this->_contentTypeHeaderSent = true; |
569 | 569 | } |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | public function getContents() |
578 | 578 | { |
579 | 579 | Prado::trace("Retrieving output", 'Prado\Web\THttpResponse'); |
580 | - return $this->_bufferOutput?ob_get_contents():''; |
|
580 | + return $this->_bufferOutput ?ob_get_contents() : ''; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public function clear() |
587 | 587 | { |
588 | - if($this->_bufferOutput) |
|
588 | + if ($this->_bufferOutput) |
|
589 | 589 | ob_clean(); |
590 | 590 | Prado::trace("Clearing output", 'Prado\Web\THttpResponse'); |
591 | 591 | } |
@@ -598,17 +598,17 @@ discard block |
||
598 | 598 | { |
599 | 599 | $result = []; |
600 | 600 | $headers = headers_list(); |
601 | - foreach($headers as $header) { |
|
601 | + foreach ($headers as $header) { |
|
602 | 602 | $tmp = explode(':', $header); |
603 | 603 | $key = trim(array_shift($tmp)); |
604 | 604 | $value = trim(implode(':', $tmp)); |
605 | - if(isset($result[$key])) |
|
606 | - $result[$key] .= ', ' . $value; |
|
605 | + if (isset($result[$key])) |
|
606 | + $result[$key] .= ', '.$value; |
|
607 | 607 | else |
608 | 608 | $result[$key] = $value; |
609 | 609 | } |
610 | 610 | |
611 | - if($case !== null) |
|
611 | + if ($case !== null) |
|
612 | 612 | return array_change_key_case($result, $case); |
613 | 613 | |
614 | 614 | return $result; |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | public function addCookie($cookie) |
648 | 648 | { |
649 | 649 | $request = $this->getRequest(); |
650 | - if($request->getEnableCookieValidation()) |
|
650 | + if ($request->getEnableCookieValidation()) |
|
651 | 651 | { |
652 | 652 | $value = $this->getApplication()->getSecurityManager()->hashData($cookie->getValue()); |
653 | 653 | setcookie( |
@@ -714,9 +714,9 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function createHtmlWriter($type = null) |
716 | 716 | { |
717 | - if($type === null) |
|
717 | + if ($type === null) |
|
718 | 718 | $type = $this->getHtmlWriterType(); |
719 | - if($this->getHasAdapter()) |
|
719 | + if ($this->getHasAdapter()) |
|
720 | 720 | return $this->_adapter->createNewHtmlWriter($type, $this); |
721 | 721 | else |
722 | 722 | return $this->createNewHtmlWriter($type, $this); |
@@ -167,8 +167,9 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function init($config) |
169 | 169 | { |
170 | - if($this->_bufferOutput) |
|
171 | - ob_start(); |
|
170 | + if($this->_bufferOutput) { |
|
171 | + ob_start(); |
|
172 | + } |
|
172 | 173 | $this->_initialized = true; |
173 | 174 | $this->getApplication()->setResponse($this); |
174 | 175 | } |
@@ -211,8 +212,9 @@ discard block |
||
211 | 212 | */ |
212 | 213 | public function setContentType($type) |
213 | 214 | { |
214 | - if ($this->_contentTypeHeaderSent) |
|
215 | - throw new \Exception('Unable to alter content-type as it has been already sent'); |
|
215 | + if ($this->_contentTypeHeaderSent) { |
|
216 | + throw new \Exception('Unable to alter content-type as it has been already sent'); |
|
217 | + } |
|
216 | 218 | $this->_contentType = $type; |
217 | 219 | } |
218 | 220 | |
@@ -254,10 +256,11 @@ discard block |
||
254 | 256 | */ |
255 | 257 | public function setBufferOutput($value) |
256 | 258 | { |
257 | - if($this->_initialized) |
|
258 | - throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
259 | - else |
|
260 | - $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
|
259 | + if($this->_initialized) { |
|
260 | + throw new TInvalidOperationException('httpresponse_bufferoutput_unchangeable'); |
|
261 | + } else { |
|
262 | + $this->_bufferOutput = TPropertyValue::ensureBoolean($value); |
|
263 | + } |
|
261 | 264 | } |
262 | 265 | |
263 | 266 | /** |
@@ -278,12 +281,13 @@ discard block |
||
278 | 281 | */ |
279 | 282 | public function setStatusCode($status, $reason = null) |
280 | 283 | { |
281 | - if ($this->_httpHeaderSent) |
|
282 | - throw new \Exception('Unable to alter response as HTTP header already sent'); |
|
284 | + if ($this->_httpHeaderSent) { |
|
285 | + throw new \Exception('Unable to alter response as HTTP header already sent'); |
|
286 | + } |
|
283 | 287 | $status = TPropertyValue::ensureInteger($status); |
284 | 288 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
285 | 289 | $this->_reason = self::$HTTP_STATUS_CODES[$status]; |
286 | - }else{ |
|
290 | + } else{ |
|
287 | 291 | if($reason === null || $reason === '') { |
288 | 292 | throw new TInvalidDataValueException("response_status_reason_missing"); |
289 | 293 | } |
@@ -308,8 +312,9 @@ discard block |
||
308 | 312 | */ |
309 | 313 | public function getCookies() |
310 | 314 | { |
311 | - if($this->_cookies === null) |
|
312 | - $this->_cookies = new THttpCookieCollection($this); |
|
315 | + if($this->_cookies === null) { |
|
316 | + $this->_cookies = new THttpCookieCollection($this); |
|
317 | + } |
|
313 | 318 | return $this->_cookies; |
314 | 319 | } |
315 | 320 | |
@@ -321,8 +326,9 @@ discard block |
||
321 | 326 | public function write($str) |
322 | 327 | { |
323 | 328 | // when starting output make sure we send the headers first |
324 | - if (!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
325 | - $this->ensureHeadersSent(); |
|
329 | + if (!$this->_bufferOutput and !$this->_httpHeaderSent) { |
|
330 | + $this->ensureHeadersSent(); |
|
331 | + } |
|
326 | 332 | echo $str; |
327 | 333 | } |
328 | 334 | |
@@ -356,31 +362,34 @@ discard block |
||
356 | 362 | if($mimeType === null) |
357 | 363 | { |
358 | 364 | $mimeType = 'text/plain'; |
359 | - if(function_exists('mime_content_type')) |
|
360 | - $mimeType = mime_content_type($fileName); |
|
361 | - elseif(($ext = strrchr($fileName, '.')) !== false) |
|
365 | + if(function_exists('mime_content_type')) { |
|
366 | + $mimeType = mime_content_type($fileName); |
|
367 | + } elseif(($ext = strrchr($fileName, '.')) !== false) |
|
362 | 368 | { |
363 | 369 | $ext = substr($ext, 1); |
364 | - if(isset($defaultMimeTypes[$ext])) |
|
365 | - $mimeType = $defaultMimeTypes[$ext]; |
|
370 | + if(isset($defaultMimeTypes[$ext])) { |
|
371 | + $mimeType = $defaultMimeTypes[$ext]; |
|
372 | + } |
|
366 | 373 | } |
367 | 374 | } |
368 | 375 | |
369 | - if($clientFileName === null) |
|
370 | - $clientFileName = basename($fileName); |
|
371 | - else |
|
372 | - $clientFileName = basename($clientFileName); |
|
376 | + if($clientFileName === null) { |
|
377 | + $clientFileName = basename($fileName); |
|
378 | + } else { |
|
379 | + $clientFileName = basename($clientFileName); |
|
380 | + } |
|
373 | 381 | |
374 | - if($fileSize === null || $fileSize < 0) |
|
375 | - $fileSize = ($content === null?filesize($fileName):strlen($content)); |
|
382 | + if($fileSize === null || $fileSize < 0) { |
|
383 | + $fileSize = ($content === null?filesize($fileName):strlen($content)); |
|
384 | + } |
|
376 | 385 | |
377 | 386 | $this->sendHttpHeader(); |
378 | 387 | if(is_array($headers)) |
379 | 388 | { |
380 | - foreach($headers as $h) |
|
381 | - header($h); |
|
382 | - } |
|
383 | - else |
|
389 | + foreach($headers as $h) { |
|
390 | + header($h); |
|
391 | + } |
|
392 | + } else |
|
384 | 393 | { |
385 | 394 | header('Pragma: public'); |
386 | 395 | header('Expires: 0'); |
@@ -392,10 +401,11 @@ discard block |
||
392 | 401 | header('Content-Length: ' . $fileSize); |
393 | 402 | header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
394 | 403 | header('Content-Transfer-Encoding: binary'); |
395 | - if($content === null) |
|
396 | - readfile($fileName); |
|
397 | - else |
|
398 | - echo $content; |
|
404 | + if($content === null) { |
|
405 | + readfile($fileName); |
|
406 | + } else { |
|
407 | + echo $content; |
|
408 | + } |
|
399 | 409 | } |
400 | 410 | |
401 | 411 | /** |
@@ -406,10 +416,11 @@ discard block |
||
406 | 416 | */ |
407 | 417 | public function redirect($url) |
408 | 418 | { |
409 | - if($this->getHasAdapter()) |
|
410 | - $this->_adapter->httpRedirect($url); |
|
411 | - else |
|
412 | - $this->httpRedirect($url); |
|
419 | + if($this->getHasAdapter()) { |
|
420 | + $this->_adapter->httpRedirect($url); |
|
421 | + } else { |
|
422 | + $this->httpRedirect($url); |
|
423 | + } |
|
413 | 424 | } |
414 | 425 | |
415 | 426 | /** |
@@ -431,8 +442,9 @@ discard block |
||
431 | 442 | // Under IIS, explicitly send an HTTP response including the status code |
432 | 443 | // this is handled automatically by PHP on Apache and others |
433 | 444 | $isIIS = (stripos($this->getRequest()->getServerSoftware(), "microsoft-iis") !== false); |
434 | - if($url[0] === '/') |
|
435 | - $url = $this->getRequest()->getBaseUrl() . $url; |
|
445 | + if($url[0] === '/') { |
|
446 | + $url = $this->getRequest()->getBaseUrl() . $url; |
|
447 | + } |
|
436 | 448 | if ($this->_status >= 300 && $this->_status < 400) |
437 | 449 | { |
438 | 450 | // The status code has been modified to a valid redirection status, send it |
@@ -446,13 +458,15 @@ discard block |
||
446 | 458 | } |
447 | 459 | header('Location: ' . str_replace('&', '&', $url), true, $this->_status); |
448 | 460 | } else { |
449 | - if($isIIS) |
|
450 | - header('HTTP/1.1 302 ' . self::$HTTP_STATUS_CODES[302]); |
|
461 | + if($isIIS) { |
|
462 | + header('HTTP/1.1 302 ' . self::$HTTP_STATUS_CODES[302]); |
|
463 | + } |
|
451 | 464 | header('Location: ' . str_replace('&', '&', $url)); |
452 | 465 | } |
453 | 466 | |
454 | - if(!$this->getApplication()->getRequestCompleted()) |
|
455 | - $this->getApplication()->onEndRequest(); |
|
467 | + if(!$this->getApplication()->getRequestCompleted()) { |
|
468 | + $this->getApplication()->onEndRequest(); |
|
469 | + } |
|
456 | 470 | |
457 | 471 | exit(); |
458 | 472 | } |
@@ -472,10 +486,11 @@ discard block |
||
472 | 486 | */ |
473 | 487 | public function flush($continueBuffering = true) |
474 | 488 | { |
475 | - if($this->getHasAdapter()) |
|
476 | - $this->_adapter->flushContent($continueBuffering); |
|
477 | - else |
|
478 | - $this->flushContent($continueBuffering); |
|
489 | + if($this->getHasAdapter()) { |
|
490 | + $this->_adapter->flushContent($continueBuffering); |
|
491 | + } else { |
|
492 | + $this->flushContent($continueBuffering); |
|
493 | + } |
|
479 | 494 | } |
480 | 495 | |
481 | 496 | /** |
@@ -505,14 +520,14 @@ discard block |
||
505 | 520 | { |
506 | 521 | $this->_bufferOutput = false; |
507 | 522 | ob_end_flush(); |
523 | + } else { |
|
524 | + ob_flush(); |
|
508 | 525 | } |
509 | - else |
|
510 | - ob_flush(); |
|
511 | 526 | flush(); |
512 | 527 | } |
528 | + } else { |
|
529 | + flush(); |
|
513 | 530 | } |
514 | - else |
|
515 | - flush(); |
|
516 | 531 | } |
517 | 532 | |
518 | 533 | /** |
@@ -520,8 +535,9 @@ discard block |
||
520 | 535 | */ |
521 | 536 | protected function ensureHttpHeaderSent() |
522 | 537 | { |
523 | - if (!$this->_httpHeaderSent) |
|
524 | - $this->sendHttpHeader(); |
|
538 | + if (!$this->_httpHeaderSent) { |
|
539 | + $this->sendHttpHeader(); |
|
540 | + } |
|
525 | 541 | } |
526 | 542 | |
527 | 543 | /** |
@@ -530,8 +546,9 @@ discard block |
||
530 | 546 | protected function sendHttpHeader() |
531 | 547 | { |
532 | 548 | $protocol = $this->getRequest()->getHttpProtocolVersion(); |
533 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
534 | - $protocol = 'HTTP/1.1'; |
|
549 | + if($this->getRequest()->getHttpProtocolVersion() === null) { |
|
550 | + $protocol = 'HTTP/1.1'; |
|
551 | + } |
|
535 | 552 | |
536 | 553 | header($protocol . ' ' . $this->_status . ' ' . $this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
537 | 554 | |
@@ -543,8 +560,9 @@ discard block |
||
543 | 560 | */ |
544 | 561 | protected function ensureContentTypeHeaderSent() |
545 | 562 | { |
546 | - if (!$this->_contentTypeHeaderSent) |
|
547 | - $this->sendContentTypeHeader(); |
|
563 | + if (!$this->_contentTypeHeaderSent) { |
|
564 | + $this->sendContentTypeHeader(); |
|
565 | + } |
|
548 | 566 | } |
549 | 567 | |
550 | 568 | /** |
@@ -559,10 +577,13 @@ discard block |
||
559 | 577 | return; |
560 | 578 | } |
561 | 579 | |
562 | - if($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) |
|
563 | - $charset = $globalization->getCharset(); |
|
580 | + if($charset === '' && ($globalization = $this->getApplication()->getGlobalization(false)) !== null) { |
|
581 | + $charset = $globalization->getCharset(); |
|
582 | + } |
|
564 | 583 | |
565 | - if($charset === '') $charset = self::DEFAULT_CHARSET; |
|
584 | + if($charset === '') { |
|
585 | + $charset = self::DEFAULT_CHARSET; |
|
586 | + } |
|
566 | 587 | $this->appendHeader('Content-Type: ' . $contentType . ';charset=' . $charset); |
567 | 588 | |
568 | 589 | $this->_contentTypeHeaderSent = true; |
@@ -585,8 +606,9 @@ discard block |
||
585 | 606 | */ |
586 | 607 | public function clear() |
587 | 608 | { |
588 | - if($this->_bufferOutput) |
|
589 | - ob_clean(); |
|
609 | + if($this->_bufferOutput) { |
|
610 | + ob_clean(); |
|
611 | + } |
|
590 | 612 | Prado::trace("Clearing output", 'Prado\Web\THttpResponse'); |
591 | 613 | } |
592 | 614 | |
@@ -602,14 +624,16 @@ discard block |
||
602 | 624 | $tmp = explode(':', $header); |
603 | 625 | $key = trim(array_shift($tmp)); |
604 | 626 | $value = trim(implode(':', $tmp)); |
605 | - if(isset($result[$key])) |
|
606 | - $result[$key] .= ', ' . $value; |
|
607 | - else |
|
608 | - $result[$key] = $value; |
|
627 | + if(isset($result[$key])) { |
|
628 | + $result[$key] .= ', ' . $value; |
|
629 | + } else { |
|
630 | + $result[$key] = $value; |
|
631 | + } |
|
609 | 632 | } |
610 | 633 | |
611 | - if($case !== null) |
|
612 | - return array_change_key_case($result, $case); |
|
634 | + if($case !== null) { |
|
635 | + return array_change_key_case($result, $case); |
|
636 | + } |
|
613 | 637 | |
614 | 638 | return $result; |
615 | 639 | } |
@@ -659,8 +683,7 @@ discard block |
||
659 | 683 | $cookie->getSecure(), |
660 | 684 | $cookie->getHttpOnly() |
661 | 685 | ); |
662 | - } |
|
663 | - else { |
|
686 | + } else { |
|
664 | 687 | setcookie( |
665 | 688 | $cookie->getName(), |
666 | 689 | $cookie->getValue(), |
@@ -714,12 +737,14 @@ discard block |
||
714 | 737 | */ |
715 | 738 | public function createHtmlWriter($type = null) |
716 | 739 | { |
717 | - if($type === null) |
|
718 | - $type = $this->getHtmlWriterType(); |
|
719 | - if($this->getHasAdapter()) |
|
720 | - return $this->_adapter->createNewHtmlWriter($type, $this); |
|
721 | - else |
|
722 | - return $this->createNewHtmlWriter($type, $this); |
|
740 | + if($type === null) { |
|
741 | + $type = $this->getHtmlWriterType(); |
|
742 | + } |
|
743 | + if($this->getHasAdapter()) { |
|
744 | + return $this->_adapter->createNewHtmlWriter($type, $this); |
|
745 | + } else { |
|
746 | + return $this->createNewHtmlWriter($type, $this); |
|
747 | + } |
|
723 | 748 | } |
724 | 749 | |
725 | 750 | /** |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function init($config) |
59 | 59 | { |
60 | - if($this->_cacheModuleID === '') |
|
60 | + if ($this->_cacheModuleID === '') |
|
61 | 61 | throw new TConfigurationException('cachesession_cachemoduleid_required'); |
62 | - elseif(($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) |
|
62 | + elseif (($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) |
|
63 | 63 | throw new TConfigurationException('cachesession_cachemodule_inexistent', $this->_cacheModuleID); |
64 | - elseif($cache instanceof ICache) |
|
64 | + elseif ($cache instanceof ICache) |
|
65 | 65 | $this->_cache = $cache; |
66 | 66 | else |
67 | 67 | throw new TConfigurationException('cachesession_cachemodule_invalid', $this->_cacheModuleID); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function _read($id) |
102 | 102 | { |
103 | - return (string)$this->_cache->get($this->calculateKey($id)); |
|
103 | + return (string) $this->_cache->get($this->calculateKey($id)); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function calculateKey($id) |
149 | 149 | { |
150 | - return $this->_prefix . ':' . $id; |
|
150 | + return $this->_prefix.':'.$id; |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 |
@@ -57,14 +57,15 @@ |
||
57 | 57 | */ |
58 | 58 | public function init($config) |
59 | 59 | { |
60 | - if($this->_cacheModuleID === '') |
|
61 | - throw new TConfigurationException('cachesession_cachemoduleid_required'); |
|
62 | - elseif(($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) |
|
63 | - throw new TConfigurationException('cachesession_cachemodule_inexistent', $this->_cacheModuleID); |
|
64 | - elseif($cache instanceof ICache) |
|
65 | - $this->_cache = $cache; |
|
66 | - else |
|
67 | - throw new TConfigurationException('cachesession_cachemodule_invalid', $this->_cacheModuleID); |
|
60 | + if($this->_cacheModuleID === '') { |
|
61 | + throw new TConfigurationException('cachesession_cachemoduleid_required'); |
|
62 | + } elseif(($cache = $this->getApplication()->getModule($this->_cacheModuleID)) === null) { |
|
63 | + throw new TConfigurationException('cachesession_cachemodule_inexistent', $this->_cacheModuleID); |
|
64 | + } elseif($cache instanceof ICache) { |
|
65 | + $this->_cache = $cache; |
|
66 | + } else { |
|
67 | + throw new TConfigurationException('cachesession_cachemodule_invalid', $this->_cacheModuleID); |
|
68 | + } |
|
68 | 69 | $this->setUseCustomStorage(true); |
69 | 70 | parent::init($config); |
70 | 71 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function init($config) |
127 | 127 | { |
128 | - if($this->_autoStart) |
|
128 | + if ($this->_autoStart) |
|
129 | 129 | $this->open(); |
130 | 130 | $this->_initialized = true; |
131 | 131 | $this->getApplication()->setSession($this); |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function open() |
139 | 139 | { |
140 | - if(!$this->_started) |
|
140 | + if (!$this->_started) |
|
141 | 141 | { |
142 | - if($this->_customStorage) |
|
143 | - session_set_save_handler([$this,'_open'], [$this,'_close'], [$this,'_read'], [$this,'_write'], [$this,'_destroy'], [$this,'_gc']); |
|
144 | - if($this->_cookie !== null) |
|
142 | + if ($this->_customStorage) |
|
143 | + session_set_save_handler([$this, '_open'], [$this, '_close'], [$this, '_read'], [$this, '_write'], [$this, '_destroy'], [$this, '_gc']); |
|
144 | + if ($this->_cookie !== null) |
|
145 | 145 | session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
146 | - if(ini_get('session.auto_start') !== '1') |
|
146 | + if (ini_get('session.auto_start') !== '1') |
|
147 | 147 | session_start(); |
148 | 148 | $this->_started = true; |
149 | 149 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function close() |
156 | 156 | { |
157 | - if($this->_started) |
|
157 | + if ($this->_started) |
|
158 | 158 | { |
159 | 159 | session_write_close(); |
160 | 160 | $this->_started = false; |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function destroy() |
168 | 168 | { |
169 | - if($this->_started) |
|
169 | + if ($this->_started) |
|
170 | 170 | { |
171 | 171 | session_destroy(); |
172 | 172 | $this->_started = false; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function setSessionID($value) |
211 | 211 | { |
212 | - if($this->_started) |
|
212 | + if ($this->_started) |
|
213 | 213 | throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
214 | 214 | else |
215 | 215 | session_id($value); |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function setSessionName($value) |
231 | 231 | { |
232 | - if($this->_started) |
|
232 | + if ($this->_started) |
|
233 | 233 | throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
234 | - elseif(ctype_alnum($value)) |
|
234 | + elseif (ctype_alnum($value)) |
|
235 | 235 | session_name($value); |
236 | 236 | else |
237 | 237 | throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function setSavePath($value) |
253 | 253 | { |
254 | - if($this->_started) |
|
254 | + if ($this->_started) |
|
255 | 255 | throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
256 | - elseif(is_dir($value)) |
|
256 | + elseif (is_dir($value)) |
|
257 | 257 | session_save_path(realpath($value)); |
258 | - elseif(null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) |
|
258 | + elseif (null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) |
|
259 | 259 | session_save_path(realpath($ns)); |
260 | 260 | else |
261 | 261 | throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function getCookie() |
287 | 287 | { |
288 | - if($this->_cookie === null) |
|
288 | + if ($this->_cookie === null) |
|
289 | 289 | $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
290 | 290 | return $this->_cookie; |
291 | 291 | } |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function getCookieMode() |
297 | 297 | { |
298 | - if(ini_get('session.use_cookies') === '0') |
|
298 | + if (ini_get('session.use_cookies') === '0') |
|
299 | 299 | return THttpSessionCookieMode::None; |
300 | - elseif(ini_get('session.use_only_cookies') === '0') |
|
300 | + elseif (ini_get('session.use_only_cookies') === '0') |
|
301 | 301 | return THttpSessionCookieMode::Allow; |
302 | 302 | else |
303 | 303 | return THttpSessionCookieMode::Only; |
@@ -309,17 +309,17 @@ discard block |
||
309 | 309 | */ |
310 | 310 | public function setCookieMode($value) |
311 | 311 | { |
312 | - if($this->_started) |
|
312 | + if ($this->_started) |
|
313 | 313 | throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
314 | 314 | else |
315 | 315 | { |
316 | 316 | $value = TPropertyValue::ensureEnum($value, 'Prado\\Web\\THttpSessionCookieMode'); |
317 | - if($value === THttpSessionCookieMode::None) |
|
317 | + if ($value === THttpSessionCookieMode::None) |
|
318 | 318 | { |
319 | 319 | ini_set('session.use_cookies', '0'); |
320 | 320 | ini_set('session.use_only_cookies', '0'); |
321 | 321 | } |
322 | - elseif($value === THttpSessionCookieMode::Allow) |
|
322 | + elseif ($value === THttpSessionCookieMode::Allow) |
|
323 | 323 | { |
324 | 324 | ini_set('session.use_cookies', '1'); |
325 | 325 | ini_set('session.use_only_cookies', '0'); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | public function setAutoStart($value) |
349 | 349 | { |
350 | - if($this->_initialized) |
|
350 | + if ($this->_initialized) |
|
351 | 351 | throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
352 | 352 | else |
353 | 353 | $this->_autoStart = TPropertyValue::ensureBoolean($value); |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function setGCProbability($value) |
370 | 370 | { |
371 | - if($this->_started) |
|
371 | + if ($this->_started) |
|
372 | 372 | throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
373 | 373 | else |
374 | 374 | { |
375 | 375 | $value = TPropertyValue::ensureInteger($value); |
376 | - if($value >= 0 && $value <= 100) |
|
376 | + if ($value >= 0 && $value <= 100) |
|
377 | 377 | { |
378 | 378 | ini_set('session.gc_probability', $value); |
379 | 379 | ini_set('session.gc_divisor', '100'); |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function setUseTransparentSessionID($value) |
402 | 402 | { |
403 | - if($this->_started) |
|
403 | + if ($this->_started) |
|
404 | 404 | throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
405 | 405 | else |
406 | 406 | { |
407 | 407 | $value = TPropertyValue::ensureBoolean($value); |
408 | 408 | if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) |
409 | 409 | throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
410 | - ini_set('session.use_trans_sid', $value?'1':'0'); |
|
410 | + ini_set('session.use_trans_sid', $value ? '1' : '0'); |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | */ |
426 | 426 | public function setTimeout($value) |
427 | 427 | { |
428 | - if($this->_started) |
|
428 | + if ($this->_started) |
|
429 | 429 | throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
430 | 430 | else |
431 | 431 | ini_set('session.gc_maxlifetime', $value); |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | */ |
566 | 566 | public function remove($key) |
567 | 567 | { |
568 | - if(isset($_SESSION[$key])) |
|
568 | + if (isset($_SESSION[$key])) |
|
569 | 569 | { |
570 | 570 | $value = $_SESSION[$key]; |
571 | 571 | unset($_SESSION[$key]); |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function clear() |
582 | 582 | { |
583 | - foreach(array_keys($_SESSION) as $key) |
|
583 | + foreach (array_keys($_SESSION) as $key) |
|
584 | 584 | unset($_SESSION[$key]); |
585 | 585 | } |
586 | 586 |
@@ -125,8 +125,9 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function init($config) |
127 | 127 | { |
128 | - if($this->_autoStart) |
|
129 | - $this->open(); |
|
128 | + if($this->_autoStart) { |
|
129 | + $this->open(); |
|
130 | + } |
|
130 | 131 | $this->_initialized = true; |
131 | 132 | $this->getApplication()->setSession($this); |
132 | 133 | register_shutdown_function([$this, "close"]); |
@@ -139,12 +140,15 @@ discard block |
||
139 | 140 | { |
140 | 141 | if(!$this->_started) |
141 | 142 | { |
142 | - if($this->_customStorage) |
|
143 | - session_set_save_handler([$this,'_open'], [$this,'_close'], [$this,'_read'], [$this,'_write'], [$this,'_destroy'], [$this,'_gc']); |
|
144 | - if($this->_cookie !== null) |
|
145 | - session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
|
146 | - if(ini_get('session.auto_start') !== '1') |
|
147 | - session_start(); |
|
143 | + if($this->_customStorage) { |
|
144 | + session_set_save_handler([$this,'_open'], [$this,'_close'], [$this,'_read'], [$this,'_write'], [$this,'_destroy'], [$this,'_gc']); |
|
145 | + } |
|
146 | + if($this->_cookie !== null) { |
|
147 | + session_set_cookie_params($this->_cookie->getExpire(), $this->_cookie->getPath(), $this->_cookie->getDomain(), $this->_cookie->getSecure(), $this->_cookie->getHttpOnly()); |
|
148 | + } |
|
149 | + if(ini_get('session.auto_start') !== '1') { |
|
150 | + session_start(); |
|
151 | + } |
|
148 | 152 | $this->_started = true; |
149 | 153 | } |
150 | 154 | } |
@@ -209,10 +213,11 @@ discard block |
||
209 | 213 | */ |
210 | 214 | public function setSessionID($value) |
211 | 215 | { |
212 | - if($this->_started) |
|
213 | - throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
214 | - else |
|
215 | - session_id($value); |
|
216 | + if($this->_started) { |
|
217 | + throw new TInvalidOperationException('httpsession_sessionid_unchangeable'); |
|
218 | + } else { |
|
219 | + session_id($value); |
|
220 | + } |
|
216 | 221 | } |
217 | 222 | |
218 | 223 | /** |
@@ -229,12 +234,13 @@ discard block |
||
229 | 234 | */ |
230 | 235 | public function setSessionName($value) |
231 | 236 | { |
232 | - if($this->_started) |
|
233 | - throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
234 | - elseif(ctype_alnum($value)) |
|
235 | - session_name($value); |
|
236 | - else |
|
237 | - throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
|
237 | + if($this->_started) { |
|
238 | + throw new TInvalidOperationException('httpsession_sessionname_unchangeable'); |
|
239 | + } elseif(ctype_alnum($value)) { |
|
240 | + session_name($value); |
|
241 | + } else { |
|
242 | + throw new TInvalidDataValueException('httpsession_sessionname_invalid', $value); |
|
243 | + } |
|
238 | 244 | } |
239 | 245 | |
240 | 246 | /** |
@@ -251,14 +257,15 @@ discard block |
||
251 | 257 | */ |
252 | 258 | public function setSavePath($value) |
253 | 259 | { |
254 | - if($this->_started) |
|
255 | - throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
256 | - elseif(is_dir($value)) |
|
257 | - session_save_path(realpath($value)); |
|
258 | - elseif(null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) |
|
259 | - session_save_path(realpath($ns)); |
|
260 | - else |
|
261 | - throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
|
260 | + if($this->_started) { |
|
261 | + throw new TInvalidOperationException('httpsession_savepath_unchangeable'); |
|
262 | + } elseif(is_dir($value)) { |
|
263 | + session_save_path(realpath($value)); |
|
264 | + } elseif(null !== ($ns = Prado::getPathOfNamespace($value)) && is_dir($ns)) { |
|
265 | + session_save_path(realpath($ns)); |
|
266 | + } else { |
|
267 | + throw new TInvalidDataValueException('httpsession_savepath_invalid', $value); |
|
268 | + } |
|
262 | 269 | } |
263 | 270 | |
264 | 271 | /** |
@@ -285,8 +292,9 @@ discard block |
||
285 | 292 | */ |
286 | 293 | public function getCookie() |
287 | 294 | { |
288 | - if($this->_cookie === null) |
|
289 | - $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
|
295 | + if($this->_cookie === null) { |
|
296 | + $this->_cookie = new THttpCookie($this->getSessionName(), $this->getSessionID()); |
|
297 | + } |
|
290 | 298 | return $this->_cookie; |
291 | 299 | } |
292 | 300 | |
@@ -295,12 +303,13 @@ discard block |
||
295 | 303 | */ |
296 | 304 | public function getCookieMode() |
297 | 305 | { |
298 | - if(ini_get('session.use_cookies') === '0') |
|
299 | - return THttpSessionCookieMode::None; |
|
300 | - elseif(ini_get('session.use_only_cookies') === '0') |
|
301 | - return THttpSessionCookieMode::Allow; |
|
302 | - else |
|
303 | - return THttpSessionCookieMode::Only; |
|
306 | + if(ini_get('session.use_cookies') === '0') { |
|
307 | + return THttpSessionCookieMode::None; |
|
308 | + } elseif(ini_get('session.use_only_cookies') === '0') { |
|
309 | + return THttpSessionCookieMode::Allow; |
|
310 | + } else { |
|
311 | + return THttpSessionCookieMode::Only; |
|
312 | + } |
|
304 | 313 | } |
305 | 314 | |
306 | 315 | /** |
@@ -309,22 +318,20 @@ discard block |
||
309 | 318 | */ |
310 | 319 | public function setCookieMode($value) |
311 | 320 | { |
312 | - if($this->_started) |
|
313 | - throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
314 | - else |
|
321 | + if($this->_started) { |
|
322 | + throw new TInvalidOperationException('httpsession_cookiemode_unchangeable'); |
|
323 | + } else |
|
315 | 324 | { |
316 | 325 | $value = TPropertyValue::ensureEnum($value, 'Prado\\Web\\THttpSessionCookieMode'); |
317 | 326 | if($value === THttpSessionCookieMode::None) |
318 | 327 | { |
319 | 328 | ini_set('session.use_cookies', '0'); |
320 | 329 | ini_set('session.use_only_cookies', '0'); |
321 | - } |
|
322 | - elseif($value === THttpSessionCookieMode::Allow) |
|
330 | + } elseif($value === THttpSessionCookieMode::Allow) |
|
323 | 331 | { |
324 | 332 | ini_set('session.use_cookies', '1'); |
325 | 333 | ini_set('session.use_only_cookies', '0'); |
326 | - } |
|
327 | - else |
|
334 | + } else |
|
328 | 335 | { |
329 | 336 | ini_set('session.use_cookies', '1'); |
330 | 337 | ini_set('session.use_only_cookies', '1'); |
@@ -347,10 +354,11 @@ discard block |
||
347 | 354 | */ |
348 | 355 | public function setAutoStart($value) |
349 | 356 | { |
350 | - if($this->_initialized) |
|
351 | - throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
352 | - else |
|
353 | - $this->_autoStart = TPropertyValue::ensureBoolean($value); |
|
357 | + if($this->_initialized) { |
|
358 | + throw new TInvalidOperationException('httpsession_autostart_unchangeable'); |
|
359 | + } else { |
|
360 | + $this->_autoStart = TPropertyValue::ensureBoolean($value); |
|
361 | + } |
|
354 | 362 | } |
355 | 363 | |
356 | 364 | /** |
@@ -368,18 +376,18 @@ discard block |
||
368 | 376 | */ |
369 | 377 | public function setGCProbability($value) |
370 | 378 | { |
371 | - if($this->_started) |
|
372 | - throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
373 | - else |
|
379 | + if($this->_started) { |
|
380 | + throw new TInvalidOperationException('httpsession_gcprobability_unchangeable'); |
|
381 | + } else |
|
374 | 382 | { |
375 | 383 | $value = TPropertyValue::ensureInteger($value); |
376 | 384 | if($value >= 0 && $value <= 100) |
377 | 385 | { |
378 | 386 | ini_set('session.gc_probability', $value); |
379 | 387 | ini_set('session.gc_divisor', '100'); |
388 | + } else { |
|
389 | + throw new TInvalidDataValueException('httpsession_gcprobability_invalid', $value); |
|
380 | 390 | } |
381 | - else |
|
382 | - throw new TInvalidDataValueException('httpsession_gcprobability_invalid', $value); |
|
383 | 391 | } |
384 | 392 | } |
385 | 393 | |
@@ -400,13 +408,14 @@ discard block |
||
400 | 408 | */ |
401 | 409 | public function setUseTransparentSessionID($value) |
402 | 410 | { |
403 | - if($this->_started) |
|
404 | - throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
405 | - else |
|
411 | + if($this->_started) { |
|
412 | + throw new TInvalidOperationException('httpsession_transid_unchangeable'); |
|
413 | + } else |
|
406 | 414 | { |
407 | 415 | $value = TPropertyValue::ensureBoolean($value); |
408 | - if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) |
|
409 | - throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
416 | + if ($value && $this->getCookieMode() == THttpSessionCookieMode::Only) { |
|
417 | + throw new TInvalidOperationException('httpsession_transid_cookieonly'); |
|
418 | + } |
|
410 | 419 | ini_set('session.use_trans_sid', $value?'1':'0'); |
411 | 420 | } |
412 | 421 | } |
@@ -425,10 +434,11 @@ discard block |
||
425 | 434 | */ |
426 | 435 | public function setTimeout($value) |
427 | 436 | { |
428 | - if($this->_started) |
|
429 | - throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
430 | - else |
|
431 | - ini_set('session.gc_maxlifetime', $value); |
|
437 | + if($this->_started) { |
|
438 | + throw new TInvalidOperationException('httpsession_maxlifetime_unchangeable'); |
|
439 | + } else { |
|
440 | + ini_set('session.gc_maxlifetime', $value); |
|
441 | + } |
|
432 | 442 | } |
433 | 443 | |
434 | 444 | /** |
@@ -570,9 +580,9 @@ discard block |
||
570 | 580 | $value = $_SESSION[$key]; |
571 | 581 | unset($_SESSION[$key]); |
572 | 582 | return $value; |
583 | + } else { |
|
584 | + return null; |
|
573 | 585 | } |
574 | - else |
|
575 | - return null; |
|
576 | 586 | } |
577 | 587 | |
578 | 588 | /** |
@@ -580,8 +590,9 @@ discard block |
||
580 | 590 | */ |
581 | 591 | public function clear() |
582 | 592 | { |
583 | - foreach(array_keys($_SESSION) as $key) |
|
584 | - unset($_SESSION[$key]); |
|
593 | + foreach(array_keys($_SESSION) as $key) { |
|
594 | + unset($_SESSION[$key]); |
|
595 | + } |
|
585 | 596 | } |
586 | 597 | |
587 | 598 | /** |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | public function init($config) |
90 | 90 | { |
91 | 91 | $application = $this->getApplication(); |
92 | - if($this->_basePath === null) |
|
93 | - $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
94 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
92 | + if ($this->_basePath === null) |
|
93 | + $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH; |
|
94 | + if (!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
95 | 95 | throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
96 | - if($this->_baseUrl === null) |
|
97 | - $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
96 | + if ($this->_baseUrl === null) |
|
97 | + $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\').'/'.self::DEFAULT_BASEPATH; |
|
98 | 98 | $application->setAssetManager($this); |
99 | 99 | $this->_initialized = true; |
100 | 100 | } |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function setBasePath($value) |
117 | 117 | { |
118 | - if($this->_initialized) |
|
118 | + if ($this->_initialized) |
|
119 | 119 | throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
120 | 120 | else |
121 | 121 | { |
122 | 122 | $this->_basePath = Prado::getPathOfNamespace($value); |
123 | - if($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
123 | + if ($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
124 | 124 | throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
125 | 125 | } |
126 | 126 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function setBaseUrl($value) |
141 | 141 | { |
142 | - if($this->_initialized) |
|
142 | + if ($this->_initialized) |
|
143 | 143 | throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
144 | 144 | else |
145 | 145 | $this->_baseUrl = rtrim($value, '/'); |
@@ -161,28 +161,28 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function publishFilePath($path, $checkTimestamp = false) |
163 | 163 | { |
164 | - if(isset($this->_published[$path])) |
|
164 | + if (isset($this->_published[$path])) |
|
165 | 165 | return $this->_published[$path]; |
166 | - elseif(empty($path) || ($fullpath = realpath($path)) === false) |
|
166 | + elseif (empty($path) || ($fullpath = realpath($path)) === false) |
|
167 | 167 | throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
168 | - elseif(is_file($fullpath)) |
|
168 | + elseif (is_file($fullpath)) |
|
169 | 169 | { |
170 | 170 | $dir = $this->hash(dirname($fullpath)); |
171 | 171 | $fileName = basename($fullpath); |
172 | - $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
|
173 | - if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
172 | + $dst = $this->_basePath.DIRECTORY_SEPARATOR.$dir; |
|
173 | + if (!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
174 | 174 | $this->copyFile($fullpath, $dst); |
175 | - return $this->_published[$path] = $this->_baseUrl . '/' . $dir . '/' . $fileName; |
|
175 | + return $this->_published[$path] = $this->_baseUrl.'/'.$dir.'/'.$fileName; |
|
176 | 176 | } |
177 | 177 | else |
178 | 178 | { |
179 | 179 | $dir = $this->hash($fullpath); |
180 | - if(!is_dir($this->_basePath . DIRECTORY_SEPARATOR . $dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
180 | + if (!is_dir($this->_basePath.DIRECTORY_SEPARATOR.$dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
181 | 181 | { |
182 | 182 | Prado::trace("Publishing directory $fullpath", 'Prado\Web\TAssetManager'); |
183 | - $this->copyDirectory($fullpath, $this->_basePath . DIRECTORY_SEPARATOR . $dir); |
|
183 | + $this->copyDirectory($fullpath, $this->_basePath.DIRECTORY_SEPARATOR.$dir); |
|
184 | 184 | } |
185 | - return $this->_published[$path] = $this->_baseUrl . '/' . $dir; |
|
185 | + return $this->_published[$path] = $this->_baseUrl.'/'.$dir; |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | public function getPublishedPath($path) |
215 | 215 | { |
216 | 216 | $path = realpath($path); |
217 | - if(is_file($path)) |
|
218 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
217 | + if (is_file($path)) |
|
218 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash(dirname($path)).DIRECTORY_SEPARATOR.basename($path); |
|
219 | 219 | else |
220 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
220 | + return $this->_basePath.DIRECTORY_SEPARATOR.$this->hash($path); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | public function getPublishedUrl($path) |
231 | 231 | { |
232 | 232 | $path = realpath($path); |
233 | - if(is_file($path)) |
|
234 | - return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
233 | + if (is_file($path)) |
|
234 | + return $this->_baseUrl.'/'.$this->hash(dirname($path)).'/'.basename($path); |
|
235 | 235 | else |
236 | - return $this->_baseUrl . '/' . $this->hash($path); |
|
236 | + return $this->_baseUrl.'/'.$this->hash($path); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | protected function hash($dir) |
246 | 246 | { |
247 | - return sprintf('%x', crc32($dir . Prado::getVersion())); |
|
247 | + return sprintf('%x', crc32($dir.Prado::getVersion())); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -256,13 +256,13 @@ discard block |
||
256 | 256 | */ |
257 | 257 | protected function copyFile($src, $dst) |
258 | 258 | { |
259 | - if(!is_dir($dst)) |
|
259 | + if (!is_dir($dst)) |
|
260 | 260 | { |
261 | 261 | @mkdir($dst); |
262 | 262 | @chmod($dst, PRADO_CHMOD); |
263 | 263 | } |
264 | - $dstFile = $dst . DIRECTORY_SEPARATOR . basename($src); |
|
265 | - if(@filemtime($dstFile) < @filemtime($src)) |
|
264 | + $dstFile = $dst.DIRECTORY_SEPARATOR.basename($src); |
|
265 | + if (@filemtime($dstFile) < @filemtime($src)) |
|
266 | 266 | { |
267 | 267 | Prado::trace("Publishing file $src to $dstFile", 'Prado\Web\TAssetManager'); |
268 | 268 | @copy($src, $dstFile); |
@@ -279,27 +279,27 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function copyDirectory($src, $dst) |
281 | 281 | { |
282 | - if(!is_dir($dst)) |
|
282 | + if (!is_dir($dst)) |
|
283 | 283 | { |
284 | 284 | @mkdir($dst); |
285 | 285 | @chmod($dst, PRADO_CHMOD); |
286 | 286 | } |
287 | - if($folder = @opendir($src)) |
|
287 | + if ($folder = @opendir($src)) |
|
288 | 288 | { |
289 | - while($file = @readdir($folder)) |
|
289 | + while ($file = @readdir($folder)) |
|
290 | 290 | { |
291 | - if($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') |
|
291 | + if ($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') |
|
292 | 292 | continue; |
293 | - elseif(is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
293 | + elseif (is_file($src.DIRECTORY_SEPARATOR.$file)) |
|
294 | 294 | { |
295 | - if(@filemtime($dst . DIRECTORY_SEPARATOR . $file) < @filemtime($src . DIRECTORY_SEPARATOR . $file)) |
|
295 | + if (@filemtime($dst.DIRECTORY_SEPARATOR.$file) < @filemtime($src.DIRECTORY_SEPARATOR.$file)) |
|
296 | 296 | { |
297 | - @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
298 | - @chmod($dst . DIRECTORY_SEPARATOR . $file, PRADO_CHMOD); |
|
297 | + @copy($src.DIRECTORY_SEPARATOR.$file, $dst.DIRECTORY_SEPARATOR.$file); |
|
298 | + @chmod($dst.DIRECTORY_SEPARATOR.$file, PRADO_CHMOD); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | else |
302 | - $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
302 | + $this->copyDirectory($src.DIRECTORY_SEPARATOR.$file, $dst.DIRECTORY_SEPARATOR.$file); |
|
303 | 303 | } |
304 | 304 | closedir($folder); |
305 | 305 | } else { |
@@ -320,24 +320,24 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp = false) |
322 | 322 | { |
323 | - if(isset($this->_published[$md5sum])) |
|
323 | + if (isset($this->_published[$md5sum])) |
|
324 | 324 | return $this->_published[$md5sum]; |
325 | - elseif(($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
325 | + elseif (($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
326 | 326 | throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
327 | 327 | else |
328 | 328 | { |
329 | 329 | $dir = $this->hash(dirname($fullpath)); |
330 | 330 | $fileName = basename($fullpath); |
331 | - $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
|
332 | - if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
331 | + $dst = $this->_basePath.DIRECTORY_SEPARATOR.$dir; |
|
332 | + if (!is_file($dst.DIRECTORY_SEPARATOR.$fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
333 | 333 | { |
334 | - if(@filemtime($dst . DIRECTORY_SEPARATOR . $fileName) < @filemtime($fullpath)) |
|
334 | + if (@filemtime($dst.DIRECTORY_SEPARATOR.$fileName) < @filemtime($fullpath)) |
|
335 | 335 | { |
336 | 336 | $this->copyFile($fullpath, $dst); |
337 | 337 | $this->deployTarFile($tarfile, $dst); |
338 | 338 | } |
339 | 339 | } |
340 | - return $this->_published[$md5sum] = $this->_baseUrl . '/' . $dir; |
|
340 | + return $this->_published[$md5sum] = $this->_baseUrl.'/'.$dir; |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | */ |
351 | 351 | protected function deployTarFile($path, $destination) |
352 | 352 | { |
353 | - if(($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
353 | + if (($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
354 | 354 | throw new TIOException('assetmanager_tarfile_invalid', $path); |
355 | 355 | else |
356 | 356 | { |
@@ -89,12 +89,15 @@ discard block |
||
89 | 89 | public function init($config) |
90 | 90 | { |
91 | 91 | $application = $this->getApplication(); |
92 | - if($this->_basePath === null) |
|
93 | - $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
94 | - if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) |
|
95 | - throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
|
96 | - if($this->_baseUrl === null) |
|
97 | - $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
92 | + if($this->_basePath === null) { |
|
93 | + $this->_basePath = dirname($application->getRequest()->getApplicationFilePath()) . DIRECTORY_SEPARATOR . self::DEFAULT_BASEPATH; |
|
94 | + } |
|
95 | + if(!is_writable($this->_basePath) || !is_dir($this->_basePath)) { |
|
96 | + throw new TConfigurationException('assetmanager_basepath_invalid', $this->_basePath); |
|
97 | + } |
|
98 | + if($this->_baseUrl === null) { |
|
99 | + $this->_baseUrl = rtrim(dirname($application->getRequest()->getApplicationUrl()), '/\\') . '/' . self::DEFAULT_BASEPATH; |
|
100 | + } |
|
98 | 101 | $application->setAssetManager($this); |
99 | 102 | $this->_initialized = true; |
100 | 103 | } |
@@ -115,13 +118,14 @@ discard block |
||
115 | 118 | */ |
116 | 119 | public function setBasePath($value) |
117 | 120 | { |
118 | - if($this->_initialized) |
|
119 | - throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
120 | - else |
|
121 | + if($this->_initialized) { |
|
122 | + throw new TInvalidOperationException('assetmanager_basepath_unchangeable'); |
|
123 | + } else |
|
121 | 124 | { |
122 | 125 | $this->_basePath = Prado::getPathOfNamespace($value); |
123 | - if($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) |
|
124 | - throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
|
126 | + if($this->_basePath === null || !is_dir($this->_basePath) || !is_writable($this->_basePath)) { |
|
127 | + throw new TInvalidDataValueException('assetmanager_basepath_invalid', $value); |
|
128 | + } |
|
125 | 129 | } |
126 | 130 | } |
127 | 131 | |
@@ -139,10 +143,11 @@ discard block |
||
139 | 143 | */ |
140 | 144 | public function setBaseUrl($value) |
141 | 145 | { |
142 | - if($this->_initialized) |
|
143 | - throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
144 | - else |
|
145 | - $this->_baseUrl = rtrim($value, '/'); |
|
146 | + if($this->_initialized) { |
|
147 | + throw new TInvalidOperationException('assetmanager_baseurl_unchangeable'); |
|
148 | + } else { |
|
149 | + $this->_baseUrl = rtrim($value, '/'); |
|
150 | + } |
|
146 | 151 | } |
147 | 152 | |
148 | 153 | /** |
@@ -161,20 +166,20 @@ discard block |
||
161 | 166 | */ |
162 | 167 | public function publishFilePath($path, $checkTimestamp = false) |
163 | 168 | { |
164 | - if(isset($this->_published[$path])) |
|
165 | - return $this->_published[$path]; |
|
166 | - elseif(empty($path) || ($fullpath = realpath($path)) === false) |
|
167 | - throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
|
168 | - elseif(is_file($fullpath)) |
|
169 | + if(isset($this->_published[$path])) { |
|
170 | + return $this->_published[$path]; |
|
171 | + } elseif(empty($path) || ($fullpath = realpath($path)) === false) { |
|
172 | + throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path); |
|
173 | + } elseif(is_file($fullpath)) |
|
169 | 174 | { |
170 | 175 | $dir = $this->hash(dirname($fullpath)); |
171 | 176 | $fileName = basename($fullpath); |
172 | 177 | $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir; |
173 | - if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
174 | - $this->copyFile($fullpath, $dst); |
|
178 | + if(!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) { |
|
179 | + $this->copyFile($fullpath, $dst); |
|
180 | + } |
|
175 | 181 | return $this->_published[$path] = $this->_baseUrl . '/' . $dir . '/' . $fileName; |
176 | - } |
|
177 | - else |
|
182 | + } else |
|
178 | 183 | { |
179 | 184 | $dir = $this->hash($fullpath); |
180 | 185 | if(!is_dir($this->_basePath . DIRECTORY_SEPARATOR . $dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) |
@@ -214,10 +219,11 @@ discard block |
||
214 | 219 | public function getPublishedPath($path) |
215 | 220 | { |
216 | 221 | $path = realpath($path); |
217 | - if(is_file($path)) |
|
218 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
219 | - else |
|
220 | - return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
222 | + if(is_file($path)) { |
|
223 | + return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash(dirname($path)) . DIRECTORY_SEPARATOR . basename($path); |
|
224 | + } else { |
|
225 | + return $this->_basePath . DIRECTORY_SEPARATOR . $this->hash($path); |
|
226 | + } |
|
221 | 227 | } |
222 | 228 | |
223 | 229 | /** |
@@ -230,10 +236,11 @@ discard block |
||
230 | 236 | public function getPublishedUrl($path) |
231 | 237 | { |
232 | 238 | $path = realpath($path); |
233 | - if(is_file($path)) |
|
234 | - return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
235 | - else |
|
236 | - return $this->_baseUrl . '/' . $this->hash($path); |
|
239 | + if(is_file($path)) { |
|
240 | + return $this->_baseUrl . '/' . $this->hash(dirname($path)) . '/' . basename($path); |
|
241 | + } else { |
|
242 | + return $this->_baseUrl . '/' . $this->hash($path); |
|
243 | + } |
|
237 | 244 | } |
238 | 245 | |
239 | 246 | /** |
@@ -288,18 +295,18 @@ discard block |
||
288 | 295 | { |
289 | 296 | while($file = @readdir($folder)) |
290 | 297 | { |
291 | - if($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') |
|
292 | - continue; |
|
293 | - elseif(is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
298 | + if($file === '.' || $file === '..' || $file === '.svn' || $file === '.git') { |
|
299 | + continue; |
|
300 | + } elseif(is_file($src . DIRECTORY_SEPARATOR . $file)) |
|
294 | 301 | { |
295 | 302 | if(@filemtime($dst . DIRECTORY_SEPARATOR . $file) < @filemtime($src . DIRECTORY_SEPARATOR . $file)) |
296 | 303 | { |
297 | 304 | @copy($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
298 | 305 | @chmod($dst . DIRECTORY_SEPARATOR . $file, PRADO_CHMOD); |
299 | 306 | } |
307 | + } else { |
|
308 | + $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
300 | 309 | } |
301 | - else |
|
302 | - $this->copyDirectory($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file); |
|
303 | 310 | } |
304 | 311 | closedir($folder); |
305 | 312 | } else { |
@@ -320,11 +327,11 @@ discard block |
||
320 | 327 | */ |
321 | 328 | public function publishTarFile($tarfile, $md5sum, $checkTimestamp = false) |
322 | 329 | { |
323 | - if(isset($this->_published[$md5sum])) |
|
324 | - return $this->_published[$md5sum]; |
|
325 | - elseif(($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) |
|
326 | - throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
|
327 | - else |
|
330 | + if(isset($this->_published[$md5sum])) { |
|
331 | + return $this->_published[$md5sum]; |
|
332 | + } elseif(($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) { |
|
333 | + throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum); |
|
334 | + } else |
|
328 | 335 | { |
329 | 336 | $dir = $this->hash(dirname($fullpath)); |
330 | 337 | $fileName = basename($fullpath); |
@@ -350,9 +357,9 @@ discard block |
||
350 | 357 | */ |
351 | 358 | protected function deployTarFile($path, $destination) |
352 | 359 | { |
353 | - if(($fullpath = realpath($path)) === false || !is_file($fullpath)) |
|
354 | - throw new TIOException('assetmanager_tarfile_invalid', $path); |
|
355 | - else |
|
360 | + if(($fullpath = realpath($path)) === false || !is_file($fullpath)) { |
|
361 | + throw new TIOException('assetmanager_tarfile_invalid', $path); |
|
362 | + } else |
|
356 | 363 | { |
357 | 364 | $tar = new TTarFileExtractor($fullpath); |
358 | 365 | return $tar->extract($destination); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function getValue($key) |
141 | 141 | { |
142 | - $result = $this->request('GET', $this->_dir . '/' . $key); |
|
142 | + $result = $this->request('GET', $this->_dir.'/'.$key); |
|
143 | 143 | return property_exists($result, 'errorCode') ? false : unserialize($result->node->value); |
144 | 144 | } |
145 | 145 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | $value = ['value' => serialize($value)]; |
158 | 158 | if ($expire > 0) $value['ttl'] = $expire; |
159 | - $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
|
159 | + $result = $this->request('PUT', $this->_dir.'/'.$key, $value); |
|
160 | 160 | return !property_exists($result, 'errorCode'); |
161 | 161 | } |
162 | 162 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | { |
174 | 174 | $value = ['value' => serialize($value), 'prevExist' => 'false']; |
175 | 175 | if ($expire > 0) $value['ttl'] = $expire; |
176 | - $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
|
176 | + $result = $this->request('PUT', $this->_dir.'/'.$key, $value); |
|
177 | 177 | return !property_exists($result, 'errorCode'); |
178 | 178 | } |
179 | 179 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function deleteValue($key) |
187 | 187 | { |
188 | - $this->request('DELETE', $this->_dir . '/' . $key); |
|
188 | + $this->request('DELETE', $this->_dir.'/'.$key); |
|
189 | 189 | return true; |
190 | 190 | } |
191 | 191 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function flush() |
197 | 197 | { |
198 | - $this->request('DELETE', $this->_dir . '?recursive=true'); |
|
198 | + $this->request('DELETE', $this->_dir.'?recursive=true'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -79,7 +79,9 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function init($config) |
81 | 81 | { |
82 | - if (!function_exists('curl_version')) throw new TConfigurationException('curl_extension_required'); |
|
82 | + if (!function_exists('curl_version')) { |
|
83 | + throw new TConfigurationException('curl_extension_required'); |
|
84 | + } |
|
83 | 85 | parent::init($config); |
84 | 86 | } |
85 | 87 | |
@@ -155,7 +157,9 @@ discard block |
||
155 | 157 | protected function setValue($key, $value, $expire) |
156 | 158 | { |
157 | 159 | $value = ['value' => serialize($value)]; |
158 | - if ($expire > 0) $value['ttl'] = $expire; |
|
160 | + if ($expire > 0) { |
|
161 | + $value['ttl'] = $expire; |
|
162 | + } |
|
159 | 163 | $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
160 | 164 | return !property_exists($result, 'errorCode'); |
161 | 165 | } |
@@ -172,7 +176,9 @@ discard block |
||
172 | 176 | protected function addValue($key, $value, $expire) |
173 | 177 | { |
174 | 178 | $value = ['value' => serialize($value), 'prevExist' => 'false']; |
175 | - if ($expire > 0) $value['ttl'] = $expire; |
|
179 | + if ($expire > 0) { |
|
180 | + $value['ttl'] = $expire; |
|
181 | + } |
|
176 | 182 | $result = $this->request('PUT', $this->_dir . '/' . $key, $value); |
177 | 183 | return !property_exists($result, 'errorCode'); |
178 | 184 | } |
@@ -197,7 +197,7 @@ |
||
197 | 197 | */ |
198 | 198 | public function setSocket($value) |
199 | 199 | { |
200 | - if($this->_initialized) |
|
200 | + if ($this->_initialized) |
|
201 | 201 | throw new TInvalidOperationException('rediscache_socket_unchangeable'); |
202 | 202 | else |
203 | 203 | $this->_socket = TPropertyValue::ensureString($value); |
@@ -113,8 +113,9 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function __destruct() |
115 | 115 | { |
116 | - if ($this->_cache instanceof \Redis) |
|
117 | - $this->_cache->close(); |
|
116 | + if ($this->_cache instanceof \Redis) { |
|
117 | + $this->_cache->close(); |
|
118 | + } |
|
118 | 119 | } |
119 | 120 | |
120 | 121 | /** |
@@ -126,13 +127,15 @@ discard block |
||
126 | 127 | */ |
127 | 128 | public function init($config) |
128 | 129 | { |
129 | - if (!extension_loaded('redis') || !class_exists('\Redis', false)) |
|
130 | - throw new TConfigurationException('rediscache_extension_required'); |
|
130 | + if (!extension_loaded('redis') || !class_exists('\Redis', false)) { |
|
131 | + throw new TConfigurationException('rediscache_extension_required'); |
|
132 | + } |
|
131 | 133 | $this->_cache = new \Redis(); |
132 | - if ($this->_socket !== null) |
|
133 | - $this->_cache->connect($this->_socket); |
|
134 | - else |
|
135 | - $this->_cache->connect($this->_host, $this->_port); |
|
134 | + if ($this->_socket !== null) { |
|
135 | + $this->_cache->connect($this->_socket); |
|
136 | + } else { |
|
137 | + $this->_cache->connect($this->_host, $this->_port); |
|
138 | + } |
|
136 | 139 | $this->_cache->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); |
137 | 140 | $this->_cache->select($this->_index); |
138 | 141 | parent::init($config); |
@@ -157,10 +160,11 @@ discard block |
||
157 | 160 | */ |
158 | 161 | public function setHost($value) |
159 | 162 | { |
160 | - if ($this->_initialized) |
|
161 | - throw new TInvalidOperationException('rediscache_host_unchangeable'); |
|
162 | - else |
|
163 | - $this->_host = $value; |
|
163 | + if ($this->_initialized) { |
|
164 | + throw new TInvalidOperationException('rediscache_host_unchangeable'); |
|
165 | + } else { |
|
166 | + $this->_host = $value; |
|
167 | + } |
|
164 | 168 | } |
165 | 169 | |
166 | 170 | /** |
@@ -177,10 +181,11 @@ discard block |
||
177 | 181 | */ |
178 | 182 | public function setPort($value) |
179 | 183 | { |
180 | - if ($this->_initialized) |
|
181 | - throw new TInvalidOperationException('rediscache_port_unchangeable'); |
|
182 | - else |
|
183 | - $this->_port = TPropertyValue::ensureInteger($value); |
|
184 | + if ($this->_initialized) { |
|
185 | + throw new TInvalidOperationException('rediscache_port_unchangeable'); |
|
186 | + } else { |
|
187 | + $this->_port = TPropertyValue::ensureInteger($value); |
|
188 | + } |
|
184 | 189 | } |
185 | 190 | |
186 | 191 | /** |
@@ -197,10 +202,11 @@ discard block |
||
197 | 202 | */ |
198 | 203 | public function setSocket($value) |
199 | 204 | { |
200 | - if($this->_initialized) |
|
201 | - throw new TInvalidOperationException('rediscache_socket_unchangeable'); |
|
202 | - else |
|
203 | - $this->_socket = TPropertyValue::ensureString($value); |
|
205 | + if($this->_initialized) { |
|
206 | + throw new TInvalidOperationException('rediscache_socket_unchangeable'); |
|
207 | + } else { |
|
208 | + $this->_socket = TPropertyValue::ensureString($value); |
|
209 | + } |
|
204 | 210 | } |
205 | 211 | |
206 | 212 | /** |
@@ -217,10 +223,11 @@ discard block |
||
217 | 223 | */ |
218 | 224 | public function setIndex($value) |
219 | 225 | { |
220 | - if ($this->_initialized) |
|
221 | - throw new TInvalidOperationException('rediscache_index_unchangeable'); |
|
222 | - else |
|
223 | - $this->_index = TPropertyValue::ensureInteger($value); |
|
226 | + if ($this->_initialized) { |
|
227 | + throw new TInvalidOperationException('rediscache_index_unchangeable'); |
|
228 | + } else { |
|
229 | + $this->_index = TPropertyValue::ensureInteger($value); |
|
230 | + } |
|
224 | 231 | } |
225 | 232 | |
226 | 233 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function init($config) |
58 | 58 | { |
59 | - if(!function_exists('eaccelerator_get')) |
|
59 | + if (!function_exists('eaccelerator_get')) |
|
60 | 60 | throw new TConfigurationException('eacceleratorcache_extension_required'); |
61 | 61 | parent::init($config); |
62 | 62 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | eaccelerator_gc(); |
123 | 123 | // now, remove leftover cache-keys |
124 | 124 | $keys = eaccelerator_list_keys(); |
125 | - foreach($keys as $key) |
|
125 | + foreach ($keys as $key) |
|
126 | 126 | $this->deleteValue(substr($key['name'], 1)); |
127 | 127 | return true; |
128 | 128 | } |
@@ -56,8 +56,9 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function init($config) |
58 | 58 | { |
59 | - if(!function_exists('eaccelerator_get')) |
|
60 | - throw new TConfigurationException('eacceleratorcache_extension_required'); |
|
59 | + if(!function_exists('eaccelerator_get')) { |
|
60 | + throw new TConfigurationException('eacceleratorcache_extension_required'); |
|
61 | + } |
|
61 | 62 | parent::init($config); |
62 | 63 | } |
63 | 64 | |
@@ -122,8 +123,9 @@ discard block |
||
122 | 123 | eaccelerator_gc(); |
123 | 124 | // now, remove leftover cache-keys |
124 | 125 | $keys = eaccelerator_list_keys(); |
125 | - foreach($keys as $key) |
|
126 | - $this->deleteValue(substr($key['name'], 1)); |
|
126 | + foreach($keys as $key) { |
|
127 | + $this->deleteValue(substr($key['name'], 1)); |
|
128 | + } |
|
127 | 129 | return true; |
128 | 130 | } |
129 | 131 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function __destruct() |
139 | 139 | { |
140 | - if($this->_cache !== null && !$this->_useMemcached) |
|
140 | + if ($this->_cache !== null && !$this->_useMemcached) |
|
141 | 141 | $this->_cache->close(); |
142 | 142 | } |
143 | 143 | |
@@ -152,30 +152,30 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function init($config) |
154 | 154 | { |
155 | - if(!extension_loaded('memcache') && !$this->_useMemcached) |
|
155 | + if (!extension_loaded('memcache') && !$this->_useMemcached) |
|
156 | 156 | throw new TConfigurationException('memcache_extension_required'); |
157 | - if(!extension_loaded('memcached') && $this->_useMemcached) |
|
157 | + if (!extension_loaded('memcached') && $this->_useMemcached) |
|
158 | 158 | throw new TConfigurationException('memcached_extension_required'); |
159 | 159 | |
160 | 160 | $this->_cache = $this->_useMemcached ? new Memcached : new Memcache; |
161 | 161 | $this->loadConfig($config); |
162 | - if(count($this->_servers)) |
|
162 | + if (count($this->_servers)) |
|
163 | 163 | { |
164 | - foreach($this->_servers as $server) |
|
164 | + foreach ($this->_servers as $server) |
|
165 | 165 | { |
166 | - Prado::trace('Adding server ' . $server['Host'] . ' from serverlist', '\Prado\Caching\TMemCache'); |
|
167 | - if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
166 | + Prado::trace('Adding server '.$server['Host'].' from serverlist', '\Prado\Caching\TMemCache'); |
|
167 | + if ($this->_cache->addServer($server['Host'], $server['Port'], $server['Persistent'], |
|
168 | 168 | $server['Weight'], $server['Timeout'], $server['RetryInterval']) === false) |
169 | 169 | throw new TConfigurationException('memcache_connection_failed', $server['Host'], $server['Port']); |
170 | 170 | } |
171 | 171 | } |
172 | 172 | else |
173 | 173 | { |
174 | - Prado::trace('Adding server ' . $this->_host, '\Prado\Caching\TMemCache'); |
|
175 | - if($this->_cache->addServer($this->_host, $this->_port) === false) |
|
174 | + Prado::trace('Adding server '.$this->_host, '\Prado\Caching\TMemCache'); |
|
175 | + if ($this->_cache->addServer($this->_host, $this->_port) === false) |
|
176 | 176 | throw new TConfigurationException('memcache_connection_failed', $this->_host, $this->_port); |
177 | 177 | } |
178 | - if($this->_threshold !== 0) |
|
178 | + if ($this->_threshold !== 0) |
|
179 | 179 | $this->_cache->setCompressThreshold($this->_threshold, $this->_minSavings); |
180 | 180 | $this->_initialized = true; |
181 | 181 | parent::init($config); |
@@ -188,29 +188,29 @@ discard block |
||
188 | 188 | */ |
189 | 189 | private function loadConfig($xml) |
190 | 190 | { |
191 | - if($xml instanceof TXmlElement) |
|
191 | + if ($xml instanceof TXmlElement) |
|
192 | 192 | { |
193 | - foreach($xml->getElementsByTagName('server') as $serverConfig) |
|
193 | + foreach ($xml->getElementsByTagName('server') as $serverConfig) |
|
194 | 194 | { |
195 | 195 | $properties = $serverConfig->getAttributes(); |
196 | - if(($host = $properties->remove('Host')) === null) |
|
196 | + if (($host = $properties->remove('Host')) === null) |
|
197 | 197 | throw new TConfigurationException('memcache_serverhost_required'); |
198 | - if(($port = $properties->remove('Port')) === null) |
|
198 | + if (($port = $properties->remove('Port')) === null) |
|
199 | 199 | throw new TConfigurationException('memcache_serverport_required'); |
200 | - if(!is_numeric($port)) |
|
200 | + if (!is_numeric($port)) |
|
201 | 201 | throw new TConfigurationException('memcache_serverport_invalid'); |
202 | - $server = ['Host' => $host,'Port' => $port,'Weight' => 1,'Timeout' => 1800,'RetryInterval' => 15,'Persistent' => true]; |
|
202 | + $server = ['Host' => $host, 'Port' => $port, 'Weight' => 1, 'Timeout' => 1800, 'RetryInterval' => 15, 'Persistent' => true]; |
|
203 | 203 | $checks = [ |
204 | 204 | 'Weight' => 'memcache_serverweight_invalid', |
205 | 205 | 'Timeout' => 'memcache_servertimeout_invalid', |
206 | 206 | 'RetryInterval' => 'memcach_serverretryinterval_invalid' |
207 | 207 | ]; |
208 | - foreach($checks as $property => $exception) |
|
208 | + foreach ($checks as $property => $exception) |
|
209 | 209 | { |
210 | 210 | $value = $properties->remove($property); |
211 | - if($value !== null && is_numeric($value)) |
|
211 | + if ($value !== null && is_numeric($value)) |
|
212 | 212 | $server[$property] = $value; |
213 | - elseif($value !== null) |
|
213 | + elseif ($value !== null) |
|
214 | 214 | throw new TConfigurationException($exception); |
215 | 215 | } |
216 | 216 | $server['Persistent'] = TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function setHost($value) |
235 | 235 | { |
236 | - if($this->_initialized) |
|
236 | + if ($this->_initialized) |
|
237 | 237 | throw new TInvalidOperationException('memcache_host_unchangeable'); |
238 | 238 | else |
239 | 239 | $this->_host = $value; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function setPort($value) |
255 | 255 | { |
256 | - if($this->_initialized) |
|
256 | + if ($this->_initialized) |
|
257 | 257 | throw new TInvalidOperationException('memcache_port_unchangeable'); |
258 | 258 | else |
259 | 259 | $this->_port = TPropertyValue::ensureInteger($value); |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | public function setUseMemcached($value) |
275 | 275 | { |
276 | - if($this->_initialized) |
|
276 | + if ($this->_initialized) |
|
277 | 277 | throw new TInvalidOperationException('memcache_host_unchangeable'); |
278 | 278 | else |
279 | 279 | $this->_useMemcached = $value; |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | */ |
294 | 294 | public function setThreshold($value) |
295 | 295 | { |
296 | - if($this->_initialized) |
|
296 | + if ($this->_initialized) |
|
297 | 297 | throw new TInvalidOperationException('memcache_threshold_unchangeable'); |
298 | 298 | else |
299 | 299 | $this->_threshold = TPropertyValue::ensureInteger($value); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function setMinSavings($value) |
315 | 315 | { |
316 | - if($this->_initialized) |
|
316 | + if ($this->_initialized) |
|
317 | 317 | throw new TInvalidOperationException('memcache_min_savings_unchangeable'); |
318 | 318 | else |
319 | 319 | $this->_minSavings = TPropertyValue::ensureFloat($value); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | protected function setValue($key, $value, $expire) |
343 | 343 | { |
344 | - if($this->_useMemcached) { |
|
344 | + if ($this->_useMemcached) { |
|
345 | 345 | return $this->_cache->set($key, $value, $expire); |
346 | 346 | } else { |
347 | 347 | return $this->_cache->set($key, $value, 0, $expire); |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | protected function addValue($key, $value, $expire) |
361 | 361 | { |
362 | - if($this->_useMemcached) { |
|
362 | + if ($this->_useMemcached) { |
|
363 | 363 | $this->_cache->add($key, $value, $expire); |
364 | 364 | } else { |
365 | 365 | return $this->_cache->add($key, $value, 0, $expire); |
@@ -137,8 +137,9 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function __destruct() |
139 | 139 | { |
140 | - if($this->_cache !== null && !$this->_useMemcached) |
|
141 | - $this->_cache->close(); |
|
140 | + if($this->_cache !== null && !$this->_useMemcached) { |
|
141 | + $this->_cache->close(); |
|
142 | + } |
|
142 | 143 | } |
143 | 144 | |
144 | 145 | /** |
@@ -152,10 +153,12 @@ discard block |
||
152 | 153 | */ |
153 | 154 | public function init($config) |
154 | 155 | { |
155 | - if(!extension_loaded('memcache') && !$this->_useMemcached) |
|
156 | - throw new TConfigurationException('memcache_extension_required'); |
|
157 | - if(!extension_loaded('memcached') && $this->_useMemcached) |
|
158 | - throw new TConfigurationException('memcached_extension_required'); |
|
156 | + if(!extension_loaded('memcache') && !$this->_useMemcached) { |
|
157 | + throw new TConfigurationException('memcache_extension_required'); |
|
158 | + } |
|
159 | + if(!extension_loaded('memcached') && $this->_useMemcached) { |
|
160 | + throw new TConfigurationException('memcached_extension_required'); |
|
161 | + } |
|
159 | 162 | |
160 | 163 | $this->_cache = $this->_useMemcached ? new Memcached : new Memcache; |
161 | 164 | $this->loadConfig($config); |
@@ -165,18 +168,20 @@ discard block |
||
165 | 168 | { |
166 | 169 | Prado::trace('Adding server ' . $server['Host'] . ' from serverlist', '\Prado\Caching\TMemCache'); |
167 | 170 | if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
168 | - $server['Weight'], $server['Timeout'], $server['RetryInterval']) === false) |
|
169 | - throw new TConfigurationException('memcache_connection_failed', $server['Host'], $server['Port']); |
|
171 | + $server['Weight'], $server['Timeout'], $server['RetryInterval']) === false) { |
|
172 | + throw new TConfigurationException('memcache_connection_failed', $server['Host'], $server['Port']); |
|
173 | + } |
|
170 | 174 | } |
171 | - } |
|
172 | - else |
|
175 | + } else |
|
173 | 176 | { |
174 | 177 | Prado::trace('Adding server ' . $this->_host, '\Prado\Caching\TMemCache'); |
175 | - if($this->_cache->addServer($this->_host, $this->_port) === false) |
|
176 | - throw new TConfigurationException('memcache_connection_failed', $this->_host, $this->_port); |
|
178 | + if($this->_cache->addServer($this->_host, $this->_port) === false) { |
|
179 | + throw new TConfigurationException('memcache_connection_failed', $this->_host, $this->_port); |
|
180 | + } |
|
181 | + } |
|
182 | + if($this->_threshold !== 0) { |
|
183 | + $this->_cache->setCompressThreshold($this->_threshold, $this->_minSavings); |
|
177 | 184 | } |
178 | - if($this->_threshold !== 0) |
|
179 | - $this->_cache->setCompressThreshold($this->_threshold, $this->_minSavings); |
|
180 | 185 | $this->_initialized = true; |
181 | 186 | parent::init($config); |
182 | 187 | } |
@@ -193,12 +198,15 @@ discard block |
||
193 | 198 | foreach($xml->getElementsByTagName('server') as $serverConfig) |
194 | 199 | { |
195 | 200 | $properties = $serverConfig->getAttributes(); |
196 | - if(($host = $properties->remove('Host')) === null) |
|
197 | - throw new TConfigurationException('memcache_serverhost_required'); |
|
198 | - if(($port = $properties->remove('Port')) === null) |
|
199 | - throw new TConfigurationException('memcache_serverport_required'); |
|
200 | - if(!is_numeric($port)) |
|
201 | - throw new TConfigurationException('memcache_serverport_invalid'); |
|
201 | + if(($host = $properties->remove('Host')) === null) { |
|
202 | + throw new TConfigurationException('memcache_serverhost_required'); |
|
203 | + } |
|
204 | + if(($port = $properties->remove('Port')) === null) { |
|
205 | + throw new TConfigurationException('memcache_serverport_required'); |
|
206 | + } |
|
207 | + if(!is_numeric($port)) { |
|
208 | + throw new TConfigurationException('memcache_serverport_invalid'); |
|
209 | + } |
|
202 | 210 | $server = ['Host' => $host,'Port' => $port,'Weight' => 1,'Timeout' => 1800,'RetryInterval' => 15,'Persistent' => true]; |
203 | 211 | $checks = [ |
204 | 212 | 'Weight' => 'memcache_serverweight_invalid', |
@@ -208,10 +216,11 @@ discard block |
||
208 | 216 | foreach($checks as $property => $exception) |
209 | 217 | { |
210 | 218 | $value = $properties->remove($property); |
211 | - if($value !== null && is_numeric($value)) |
|
212 | - $server[$property] = $value; |
|
213 | - elseif($value !== null) |
|
214 | - throw new TConfigurationException($exception); |
|
219 | + if($value !== null && is_numeric($value)) { |
|
220 | + $server[$property] = $value; |
|
221 | + } elseif($value !== null) { |
|
222 | + throw new TConfigurationException($exception); |
|
223 | + } |
|
215 | 224 | } |
216 | 225 | $server['Persistent'] = TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
217 | 226 | $this->_servers[] = $server; |
@@ -233,10 +242,11 @@ discard block |
||
233 | 242 | */ |
234 | 243 | public function setHost($value) |
235 | 244 | { |
236 | - if($this->_initialized) |
|
237 | - throw new TInvalidOperationException('memcache_host_unchangeable'); |
|
238 | - else |
|
239 | - $this->_host = $value; |
|
245 | + if($this->_initialized) { |
|
246 | + throw new TInvalidOperationException('memcache_host_unchangeable'); |
|
247 | + } else { |
|
248 | + $this->_host = $value; |
|
249 | + } |
|
240 | 250 | } |
241 | 251 | |
242 | 252 | /** |
@@ -253,10 +263,11 @@ discard block |
||
253 | 263 | */ |
254 | 264 | public function setPort($value) |
255 | 265 | { |
256 | - if($this->_initialized) |
|
257 | - throw new TInvalidOperationException('memcache_port_unchangeable'); |
|
258 | - else |
|
259 | - $this->_port = TPropertyValue::ensureInteger($value); |
|
266 | + if($this->_initialized) { |
|
267 | + throw new TInvalidOperationException('memcache_port_unchangeable'); |
|
268 | + } else { |
|
269 | + $this->_port = TPropertyValue::ensureInteger($value); |
|
270 | + } |
|
260 | 271 | } |
261 | 272 | |
262 | 273 | /** |
@@ -273,10 +284,11 @@ discard block |
||
273 | 284 | */ |
274 | 285 | public function setUseMemcached($value) |
275 | 286 | { |
276 | - if($this->_initialized) |
|
277 | - throw new TInvalidOperationException('memcache_host_unchangeable'); |
|
278 | - else |
|
279 | - $this->_useMemcached = $value; |
|
287 | + if($this->_initialized) { |
|
288 | + throw new TInvalidOperationException('memcache_host_unchangeable'); |
|
289 | + } else { |
|
290 | + $this->_useMemcached = $value; |
|
291 | + } |
|
280 | 292 | } |
281 | 293 | |
282 | 294 | /** |
@@ -293,10 +305,11 @@ discard block |
||
293 | 305 | */ |
294 | 306 | public function setThreshold($value) |
295 | 307 | { |
296 | - if($this->_initialized) |
|
297 | - throw new TInvalidOperationException('memcache_threshold_unchangeable'); |
|
298 | - else |
|
299 | - $this->_threshold = TPropertyValue::ensureInteger($value); |
|
308 | + if($this->_initialized) { |
|
309 | + throw new TInvalidOperationException('memcache_threshold_unchangeable'); |
|
310 | + } else { |
|
311 | + $this->_threshold = TPropertyValue::ensureInteger($value); |
|
312 | + } |
|
300 | 313 | } |
301 | 314 | |
302 | 315 | /** |
@@ -313,10 +326,11 @@ discard block |
||
313 | 326 | */ |
314 | 327 | public function setMinSavings($value) |
315 | 328 | { |
316 | - if($this->_initialized) |
|
317 | - throw new TInvalidOperationException('memcache_min_savings_unchangeable'); |
|
318 | - else |
|
319 | - $this->_minSavings = TPropertyValue::ensureFloat($value); |
|
329 | + if($this->_initialized) { |
|
330 | + throw new TInvalidOperationException('memcache_min_savings_unchangeable'); |
|
331 | + } else { |
|
332 | + $this->_minSavings = TPropertyValue::ensureFloat($value); |
|
333 | + } |
|
320 | 334 | } |
321 | 335 | |
322 | 336 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function getDependencies() |
38 | 38 | { |
39 | - if($this->_dependencies === null) |
|
39 | + if ($this->_dependencies === null) |
|
40 | 40 | $this->_dependencies = new TCacheDependencyList; |
41 | 41 | return $this->_dependencies; |
42 | 42 | } |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function getHasChanged() |
51 | 51 | { |
52 | - if($this->_dependencies !== null) |
|
52 | + if ($this->_dependencies !== null) |
|
53 | 53 | { |
54 | - foreach($this->_dependencies as $dependency) |
|
55 | - if($dependency->getHasChanged()) |
|
54 | + foreach ($this->_dependencies as $dependency) |
|
55 | + if ($dependency->getHasChanged()) |
|
56 | 56 | return true; |
57 | 57 | } |
58 | 58 | return false; |
@@ -36,8 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function getDependencies() |
38 | 38 | { |
39 | - if($this->_dependencies === null) |
|
40 | - $this->_dependencies = new TCacheDependencyList; |
|
39 | + if($this->_dependencies === null) { |
|
40 | + $this->_dependencies = new TCacheDependencyList; |
|
41 | + } |
|
41 | 42 | return $this->_dependencies; |
42 | 43 | } |
43 | 44 | |
@@ -51,9 +52,10 @@ discard block |
||
51 | 52 | { |
52 | 53 | if($this->_dependencies !== null) |
53 | 54 | { |
54 | - foreach($this->_dependencies as $dependency) |
|
55 | - if($dependency->getHasChanged()) |
|
55 | + foreach($this->_dependencies as $dependency) { |
|
56 | + if($dependency->getHasChanged()) |
|
56 | 57 | return true; |
58 | + } |
|
57 | 59 | } |
58 | 60 | return false; |
59 | 61 | } |