@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | class THttpRequest extends \Prado\TApplicationComponent implements \IteratorAggregate, \ArrayAccess, \Countable, \Prado\IModule |
| 78 | 78 | { |
| 79 | - const CGIFIX__PATH_INFO = 1; |
|
| 80 | - const CGIFIX__SCRIPT_NAME = 2; |
|
| 79 | + const CGIFIX__PATH_INFO=1; |
|
| 80 | + const CGIFIX__SCRIPT_NAME=2; |
|
| 81 | 81 | /** |
| 82 | 82 | * @var TUrlManager the URL manager module |
| 83 | 83 | */ |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | if(isset($_SERVER['REQUEST_URI'])) |
| 181 | 181 | $this->_requestUri=$_SERVER['REQUEST_URI']; |
| 182 | 182 | else // TBD: in this case, SCRIPT_NAME need to be escaped |
| 183 | - $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING']); |
|
| 183 | + $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING']) ? '' : '?'.$_SERVER['QUERY_STRING']); |
|
| 184 | 184 | |
| 185 | - if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
| 185 | + if($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
| 186 | 186 | $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
| 187 | 187 | elseif(isset($_SERVER['PATH_INFO'])) |
| 188 | 188 | $this->_pathInfo=$_SERVER['PATH_INFO']; |
| 189 | - else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
| 190 | - $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
| 189 | + else if(strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
| 190 | + $this->_pathInfo=substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])); |
|
| 191 | 191 | else |
| 192 | 192 | $this->_pathInfo=''; |
| 193 | 193 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function stripSlashes(&$data) |
| 216 | 216 | { |
| 217 | - return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data); |
|
| 217 | + return is_array($data) ? array_map(array($this, 'stripSlashes'), $data) : stripslashes($data); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | if($this->_url===null) |
| 226 | 226 | { |
| 227 | 227 | $secure=$this->getIsSecureConnection(); |
| 228 | - $url=$secure?'https://':'http://'; |
|
| 228 | + $url=$secure ? 'https://' : 'http://'; |
|
| 229 | 229 | if(empty($_SERVER['HTTP_HOST'])) |
| 230 | 230 | { |
| 231 | 231 | $url.=$_SERVER['SERVER_NAME']; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function setEnableCache($value) |
| 250 | 250 | { |
| 251 | - $this->_enableCache = TPropertyValue::ensureBoolean($value); |
|
| 251 | + $this->_enableCache=TPropertyValue::ensureBoolean($value); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -272,15 +272,15 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | if($this->getEnableCache()) |
| 274 | 274 | { |
| 275 | - $cache = $this->getApplication()->getCache(); |
|
| 276 | - if($cache !== null) |
|
| 275 | + $cache=$this->getApplication()->getCache(); |
|
| 276 | + if($cache!==null) |
|
| 277 | 277 | { |
| 278 | - $dependencies = null; |
|
| 279 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
| 280 | - if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
| 278 | + $dependencies=null; |
|
| 279 | + if($this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
| 280 | + if($manager instanceof TUrlMapping && $fn=$manager->getConfigFile()) |
|
| 281 | 281 | { |
| 282 | - $fn = Prado::getPathOfNamespace($fn,$this->getApplication()->getConfigurationFileExt()); |
|
| 283 | - $dependencies = new TFileCacheDependency($fn); |
|
| 282 | + $fn=Prado::getPathOfNamespace($fn, $this->getApplication()->getConfigurationFileExt()); |
|
| 283 | + $dependencies=new TFileCacheDependency($fn); |
|
| 284 | 284 | } |
| 285 | 285 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
| 286 | 286 | } |
@@ -296,10 +296,10 @@ discard block |
||
| 296 | 296 | { |
| 297 | 297 | if($this->getEnableCache()) |
| 298 | 298 | { |
| 299 | - $cache = $this->getApplication()->getCache(); |
|
| 300 | - if($cache !== null) |
|
| 299 | + $cache=$this->getApplication()->getCache(); |
|
| 300 | + if($cache!==null) |
|
| 301 | 301 | { |
| 302 | - $manager = $cache->get($this->getCacheKey()); |
|
| 302 | + $manager=$cache->get($this->getCacheKey()); |
|
| 303 | 303 | if($manager instanceof TUrlManager) |
| 304 | 304 | return $manager; |
| 305 | 305 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | { |
| 336 | 336 | if($this->_urlManager===null) |
| 337 | 337 | { |
| 338 | - if(($this->_urlManager = $this->loadCachedUrlManager())===null) |
|
| 338 | + if(($this->_urlManager=$this->loadCachedUrlManager())===null) |
|
| 339 | 339 | { |
| 340 | 340 | if(empty($this->_urlManagerID)) |
| 341 | 341 | { |
@@ -346,9 +346,9 @@ discard block |
||
| 346 | 346 | { |
| 347 | 347 | $this->_urlManager=$this->getApplication()->getModule($this->_urlManagerID); |
| 348 | 348 | if($this->_urlManager===null) |
| 349 | - throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
| 349 | + throw new TConfigurationException('httprequest_urlmanager_inexist', $this->_urlManagerID); |
|
| 350 | 350 | if(!($this->_urlManager instanceof TUrlManager)) |
| 351 | - throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
| 351 | + throw new TConfigurationException('httprequest_urlmanager_invalid', $this->_urlManagerID); |
|
| 352 | 352 | } |
| 353 | 353 | $this->cacheUrlManager($this->_urlManager); |
| 354 | 354 | } |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | public function setUrlFormat($value) |
| 376 | 376 | { |
| 377 | - $this->_urlFormat=TPropertyValue::ensureEnum($value,'Prado\\Web\\THttpRequestUrlFormat'); |
|
| 377 | + $this->_urlFormat=TPropertyValue::ensureEnum($value, 'Prado\\Web\\THttpRequestUrlFormat'); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -402,19 +402,19 @@ discard block |
||
| 402 | 402 | */ |
| 403 | 403 | public function getRequestType() |
| 404 | 404 | { |
| 405 | - return isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:null; |
|
| 405 | + return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
| 409 | 409 | * @param boolean $mimetypeOnly whether to return only the mimetype (default: true) |
| 410 | 410 | * @return string content type (e.g. 'application/json' or 'text/html; encoding=gzip') or null if not specified |
| 411 | 411 | */ |
| 412 | - public function getContentType($mimetypeOnly = true) |
|
| 412 | + public function getContentType($mimetypeOnly=true) |
|
| 413 | 413 | { |
| 414 | 414 | if(!isset($_SERVER['CONTENT_TYPE'])) |
| 415 | 415 | return null; |
| 416 | 416 | |
| 417 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
| 417 | + if($mimetypeOnly===true && ($_pos=strpos(';', $_SERVER['CONTENT_TYPE']))!==false) |
|
| 418 | 418 | return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
| 419 | 419 | |
| 420 | 420 | return $_SERVER['CONTENT_TYPE']; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | */ |
| 426 | 426 | public function getIsSecureConnection() |
| 427 | 427 | { |
| 428 | - return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off'); |
|
| 428 | + return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off'); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public function getQueryString() |
| 443 | 443 | { |
| 444 | - return isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:null; |
|
| 444 | + return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function getHttpProtocolVersion() |
| 451 | 451 | { |
| 452 | - return isset($_SERVER['SERVER_PROTOCOL'])?$_SERVER['SERVER_PROTOCOL']:null; |
|
| 452 | + return isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -460,19 +460,19 @@ discard block |
||
| 460 | 460 | { |
| 461 | 461 | static $result; |
| 462 | 462 | |
| 463 | - if($result === null && function_exists('apache_request_headers')) { |
|
| 464 | - $result = apache_request_headers(); |
|
| 463 | + if($result===null && function_exists('apache_request_headers')) { |
|
| 464 | + $result=apache_request_headers(); |
|
| 465 | 465 | } |
| 466 | - elseif($result === null) { |
|
| 467 | - $result = array(); |
|
| 466 | + elseif($result===null) { |
|
| 467 | + $result=array(); |
|
| 468 | 468 | foreach($_SERVER as $key=>$value) { |
| 469 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
| 470 | - $key = str_replace(' ','-', ucwords(strtolower(str_replace('_',' ', substr($key, 5))))); |
|
| 471 | - $result[$key] = $value; |
|
| 469 | + if(strncasecmp($key, 'HTTP_', 5)!==0) continue; |
|
| 470 | + $key=str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); |
|
| 471 | + $result[$key]=$value; |
|
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - if($case !== null) |
|
| 475 | + if($case!==null) |
|
| 476 | 476 | return array_change_key_case($result, $case); |
| 477 | 477 | |
| 478 | 478 | return $result; |
@@ -496,9 +496,9 @@ discard block |
||
| 496 | 496 | public function getBaseUrl($forceSecureConnection=null) |
| 497 | 497 | { |
| 498 | 498 | $url=$this->getUrl(); |
| 499 | - $scheme=($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
|
| 499 | + $scheme=($forceSecureConnection) ? "https" : (($forceSecureConnection===null) ? $url->getScheme() : 'http'); |
|
| 500 | 500 | $host=$url->getHost(); |
| 501 | - if (($port=$url->getPort())) $host.=':'.$port; |
|
| 501 | + if(($port=$url->getPort())) $host.=':'.$port; |
|
| 502 | 502 | return $scheme.'://'.$host; |
| 503 | 503 | } |
| 504 | 504 | |
@@ -507,10 +507,10 @@ discard block |
||
| 507 | 507 | */ |
| 508 | 508 | public function getApplicationUrl() |
| 509 | 509 | { |
| 510 | - if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
| 510 | + if($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
| 511 | 511 | return $_SERVER['ORIG_SCRIPT_NAME']; |
| 512 | 512 | |
| 513 | - return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
|
| 513 | + return isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null; |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | public function getAbsoluteApplicationUrl($forceSecureConnection=null) |
| 524 | 524 | { |
| 525 | - return $this->getBaseUrl($forceSecureConnection) . $this->getApplicationUrl(); |
|
| 525 | + return $this->getBaseUrl($forceSecureConnection).$this->getApplicationUrl(); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | */ |
| 531 | 531 | public function getApplicationFilePath() |
| 532 | 532 | { |
| 533 | - return realpath(isset($_SERVER['SCRIPT_FILENAME'])?$_SERVER['SCRIPT_FILENAME']:null); |
|
| 533 | + return realpath(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : null); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | */ |
| 539 | 539 | public function getServerName() |
| 540 | 540 | { |
| 541 | - return isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:null; |
|
| 541 | + return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | */ |
| 547 | 547 | public function getServerPort() |
| 548 | 548 | { |
| 549 | - return isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:null; |
|
| 549 | + return isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | */ |
| 555 | 555 | public function getUrlReferrer() |
| 556 | 556 | { |
| 557 | - return isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:null; |
|
| 557 | + return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | */ |
| 564 | 564 | public function getServerSoftware() |
| 565 | 565 | { |
| 566 | - return isset($_SERVER['SERVER_SOFTWARE'])?$_SERVER['SERVER_SOFTWARE']:null; |
|
| 566 | + return isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function getUserAgent() |
| 589 | 589 | { |
| 590 | - return isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null; |
|
| 590 | + return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | */ |
| 596 | 596 | public function getUserHostAddress() |
| 597 | 597 | { |
| 598 | - return isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:null; |
|
| 598 | + return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | public function getUserHost() |
| 605 | 605 | { |
| 606 | - return isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:null; |
|
| 606 | + return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : null; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | public function getAcceptTypes() |
| 613 | 613 | { |
| 614 | 614 | // TBD: break it into array?? |
| 615 | - return isset($_SERVER['HTTP_ACCEPT'])?$_SERVER['HTTP_ACCEPT']:null; |
|
| 615 | + return isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -677,13 +677,13 @@ discard block |
||
| 677 | 677 | foreach($_COOKIE as $key=>$value) |
| 678 | 678 | { |
| 679 | 679 | if(($value=$sm->validateData($value))!==false) |
| 680 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 680 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
| 681 | 681 | } |
| 682 | 682 | } |
| 683 | 683 | else |
| 684 | 684 | { |
| 685 | 685 | foreach($_COOKIE as $key=>$value) |
| 686 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 686 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | return $this->_cookies; |
@@ -730,13 +730,13 @@ discard block |
||
| 730 | 730 | * @return string URL |
| 731 | 731 | * @see TUrlManager::constructUrl |
| 732 | 732 | */ |
| 733 | - public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=true,$encodeGetItems=true) |
|
| 733 | + public function constructUrl($serviceID, $serviceParam, $getItems=null, $encodeAmpersand=true, $encodeGetItems=true) |
|
| 734 | 734 | { |
| 735 | - if ($this->_cookieOnly===null) |
|
| 736 | - $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
| 737 | - $url=$this->getUrlManagerModule()->constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); |
|
| 738 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
| 739 | - return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
| 735 | + if($this->_cookieOnly===null) |
|
| 736 | + $this->_cookieOnly=(int) ini_get('session.use_cookies') && (int) ini_get('session.use_only_cookies'); |
|
| 737 | + $url=$this->getUrlManagerModule()->constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems); |
|
| 738 | + if(defined('SID') && SID!='' && !$this->_cookieOnly) |
|
| 739 | + return $url.(strpos($url, '?')===false ? '?' : ($encodeAmpersand ? '&' : '&')).SID; |
|
| 740 | 740 | else |
| 741 | 741 | return $url; |
| 742 | 742 | } |
@@ -764,11 +764,11 @@ discard block |
||
| 764 | 764 | */ |
| 765 | 765 | public function resolveRequest($serviceIDs) |
| 766 | 766 | { |
| 767 | - Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'],'Prado\Web\THttpRequest'); |
|
| 767 | + Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'], 'Prado\Web\THttpRequest'); |
|
| 768 | 768 | $getParams=$this->parseUrl(); |
| 769 | 769 | foreach($getParams as $name=>$value) |
| 770 | 770 | $_GET[$name]=$value; |
| 771 | - $this->_items=array_merge($_GET,$_POST); |
|
| 771 | + $this->_items=array_merge($_GET, $_POST); |
|
| 772 | 772 | $this->_requestResolved=true; |
| 773 | 773 | foreach($serviceIDs as $serviceID) |
| 774 | 774 | { |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | * @param mixed key |
| 880 | 880 | * @param mixed value |
| 881 | 881 | */ |
| 882 | - public function add($key,$value) |
|
| 882 | + public function add($key, $value) |
|
| 883 | 883 | { |
| 884 | 884 | $this->_items[$key]=$value; |
| 885 | 885 | } |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | */ |
| 893 | 893 | public function remove($key) |
| 894 | 894 | { |
| 895 | - if(isset($this->_items[$key]) || array_key_exists($key,$this->_items)) |
|
| 895 | + if(isset($this->_items[$key]) || array_key_exists($key, $this->_items)) |
|
| 896 | 896 | { |
| 897 | 897 | $value=$this->_items[$key]; |
| 898 | 898 | unset($this->_items[$key]); |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | */ |
| 918 | 918 | public function contains($key) |
| 919 | 919 | { |
| 920 | - return isset($this->_items[$key]) || array_key_exists($key,$this->_items); |
|
| 920 | + return isset($this->_items[$key]) || array_key_exists($key, $this->_items); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | /** |
@@ -956,9 +956,9 @@ discard block |
||
| 956 | 956 | * @param integer the offset to set element |
| 957 | 957 | * @param mixed the element value |
| 958 | 958 | */ |
| 959 | - public function offsetSet($offset,$item) |
|
| 959 | + public function offsetSet($offset, $item) |
|
| 960 | 960 | { |
| 961 | - $this->add($offset,$item); |
|
| 961 | + $this->add($offset, $item); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | class THttpResponse extends \Prado\TModule implements \Prado\IO\ITextWriter |
| 67 | 67 | { |
| 68 | - const DEFAULT_CONTENTTYPE = 'text/html'; |
|
| 69 | - const DEFAULT_CHARSET = 'UTF-8'; |
|
| 68 | + const DEFAULT_CONTENTTYPE='text/html'; |
|
| 69 | + const DEFAULT_CHARSET='UTF-8'; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616} |
| 73 | 73 | */ |
| 74 | - private static $HTTP_STATUS_CODES = array( |
|
| 74 | + private static $HTTP_STATUS_CODES=array( |
|
| 75 | 75 | 100 => 'Continue', 101 => 'Switching Protocols', |
| 76 | 76 | 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', |
| 77 | 77 | 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | public function setCacheControl($value) |
| 204 | 204 | { |
| 205 | - session_cache_limiter(TPropertyValue::ensureEnum($value,array('none','nocache','private','private_no_expire','public'))); |
|
| 205 | + session_cache_limiter(TPropertyValue::ensureEnum($value, array('none', 'nocache', 'private', 'private_no_expire', 'public'))); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -210,9 +210,9 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | public function setContentType($type) |
| 212 | 212 | { |
| 213 | - if ($this->_contentTypeHeaderSent) |
|
| 213 | + if($this->_contentTypeHeaderSent) |
|
| 214 | 214 | throw new \Exception('Unable to alter content-type as it has been already sent'); |
| 215 | - $this->_contentType = $type; |
|
| 215 | + $this->_contentType=$type; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function setCharset($charset) |
| 238 | 238 | { |
| 239 | - $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset; |
|
| 239 | + $this->_charset=(strToLower($charset)==='false') ? false : (string) $charset; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -277,12 +277,12 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | public function setStatusCode($status, $reason=null) |
| 279 | 279 | { |
| 280 | - if ($this->_httpHeaderSent) |
|
| 280 | + if($this->_httpHeaderSent) |
|
| 281 | 281 | throw new \Exception('Unable to alter response as HTTP header already sent'); |
| 282 | 282 | $status=TPropertyValue::ensureInteger($status); |
| 283 | 283 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
| 284 | 284 | $this->_reason=self::$HTTP_STATUS_CODES[$status]; |
| 285 | - }else{ |
|
| 285 | + } else { |
|
| 286 | 286 | if($reason===null || $reason==='') { |
| 287 | 287 | throw new TInvalidDataValueException("response_status_reason_missing"); |
| 288 | 288 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | public function write($str) |
| 321 | 321 | { |
| 322 | 322 | // when starting output make sure we send the headers first |
| 323 | - if (!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
| 323 | + if(!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
| 324 | 324 | $this->ensureHeadersSent(); |
| 325 | 325 | echo $str; |
| 326 | 326 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @param integer size of file or content in bytes if already known. Defaults to 'null' means auto-detect. |
| 338 | 338 | * @throws TInvalidDataValueException if the file cannot be found |
| 339 | 339 | */ |
| 340 | - public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null) |
|
| 340 | + public function writeFile($fileName, $content=null, $mimeType=null, $headers=null, $forceDownload=true, $clientFileName=null, $fileSize=null) |
|
| 341 | 341 | { |
| 342 | 342 | static $defaultMimeTypes=array( |
| 343 | 343 | 'css'=>'text/css', |
@@ -357,9 +357,9 @@ discard block |
||
| 357 | 357 | $mimeType='text/plain'; |
| 358 | 358 | if(function_exists('mime_content_type')) |
| 359 | 359 | $mimeType=mime_content_type($fileName); |
| 360 | - else if(($ext=strrchr($fileName,'.'))!==false) |
|
| 360 | + else if(($ext=strrchr($fileName, '.'))!==false) |
|
| 361 | 361 | { |
| 362 | - $ext=substr($ext,1); |
|
| 362 | + $ext=substr($ext, 1); |
|
| 363 | 363 | if(isset($defaultMimeTypes[$ext])) |
| 364 | 364 | $mimeType=$defaultMimeTypes[$ext]; |
| 365 | 365 | } |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | $clientFileName=basename($clientFileName); |
| 372 | 372 | |
| 373 | 373 | if($fileSize===null || $fileSize < 0) |
| 374 | - $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
| 374 | + $fileSize=($content===null ? filesize($fileName) : strlen($content)); |
|
| 375 | 375 | |
| 376 | 376 | $this->sendHttpHeader(); |
| 377 | 377 | if(is_array($headers)) |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | header('Expires: 0'); |
| 386 | 386 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 387 | 387 | header("Content-Type: $mimeType"); |
| 388 | - $this->_contentTypeHeaderSent = true; |
|
| 388 | + $this->_contentTypeHeaderSent=true; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | header('Content-Length: '.$fileSize); |
| 392 | - header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
|
| 392 | + header("Content-Disposition: ".($forceDownload ? 'attachment' : 'inline')."; filename=\"$clientFileName\""); |
|
| 393 | 393 | header('Content-Transfer-Encoding: binary'); |
| 394 | 394 | if($content===null) |
| 395 | 395 | readfile($fileName); |
@@ -429,25 +429,25 @@ discard block |
||
| 429 | 429 | |
| 430 | 430 | // Under IIS, explicitly send an HTTP response including the status code |
| 431 | 431 | // this is handled automatically by PHP on Apache and others |
| 432 | - $isIIS = (stripos($this->getRequest()->getServerSoftware(), "microsoft-iis") !== false); |
|
| 432 | + $isIIS=(stripos($this->getRequest()->getServerSoftware(), "microsoft-iis")!==false); |
|
| 433 | 433 | if($url[0]==='/') |
| 434 | 434 | $url=$this->getRequest()->getBaseUrl().$url; |
| 435 | - if ($this->_status >= 300 && $this->_status < 400) |
|
| 435 | + if($this->_status >= 300 && $this->_status < 400) |
|
| 436 | 436 | { |
| 437 | 437 | // The status code has been modified to a valid redirection status, send it |
| 438 | 438 | if($isIIS) |
| 439 | 439 | { |
| 440 | - header('HTTP/1.1 ' . $this->_status . ' ' . self::$HTTP_STATUS_CODES[ |
|
| 440 | + header('HTTP/1.1 '.$this->_status.' '.self::$HTTP_STATUS_CODES[ |
|
| 441 | 441 | array_key_exists($this->_status, self::$HTTP_STATUS_CODES) |
| 442 | 442 | ? $this->_status |
| 443 | 443 | : 302 |
| 444 | 444 | ]); |
| 445 | 445 | } |
| 446 | - header('Location: '.str_replace('&','&',$url), true, $this->_status); |
|
| 446 | + header('Location: '.str_replace('&', '&', $url), true, $this->_status); |
|
| 447 | 447 | } else { |
| 448 | 448 | if($isIIS) |
| 449 | 449 | header('HTTP/1.1 302 '.self::$HTTP_STATUS_CODES[302]); |
| 450 | - header('Location: '.str_replace('&','&',$url)); |
|
| 450 | + header('Location: '.str_replace('&', '&', $url)); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | if(!$this->getApplication()->getRequestCompleted()) |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | /** |
| 470 | 470 | * Flush the response contents and headers. |
| 471 | 471 | */ |
| 472 | - public function flush($continueBuffering = true) |
|
| 472 | + public function flush($continueBuffering=true) |
|
| 473 | 473 | { |
| 474 | 474 | if($this->getHasAdapter()) |
| 475 | 475 | $this->_adapter->flushContent($continueBuffering); |
@@ -491,18 +491,18 @@ discard block |
||
| 491 | 491 | * This method is used internally. Please use {@link flush} instead. |
| 492 | 492 | * @param boolean whether to continue buffering after flush if buffering was active |
| 493 | 493 | */ |
| 494 | - public function flushContent($continueBuffering = true) |
|
| 494 | + public function flushContent($continueBuffering=true) |
|
| 495 | 495 | { |
| 496 | - Prado::trace("Flushing output",'Prado\Web\THttpResponse'); |
|
| 496 | + Prado::trace("Flushing output", 'Prado\Web\THttpResponse'); |
|
| 497 | 497 | $this->ensureHeadersSent(); |
| 498 | 498 | if($this->_bufferOutput) |
| 499 | 499 | { |
| 500 | 500 | // avoid forced send of http headers (ob_flush() does that) if there's no output yet |
| 501 | - if (ob_get_length()>0) |
|
| 501 | + if(ob_get_length() > 0) |
|
| 502 | 502 | { |
| 503 | - if (!$continueBuffering) |
|
| 503 | + if(!$continueBuffering) |
|
| 504 | 504 | { |
| 505 | - $this->_bufferOutput = false; |
|
| 505 | + $this->_bufferOutput=false; |
|
| 506 | 506 | ob_end_flush(); |
| 507 | 507 | } |
| 508 | 508 | else |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | */ |
| 520 | 520 | protected function ensureHttpHeaderSent() |
| 521 | 521 | { |
| 522 | - if (!$this->_httpHeaderSent) |
|
| 522 | + if(!$this->_httpHeaderSent) |
|
| 523 | 523 | $this->sendHttpHeader(); |
| 524 | 524 | } |
| 525 | 525 | |
@@ -529,15 +529,15 @@ discard block |
||
| 529 | 529 | protected function sendHttpHeader() |
| 530 | 530 | { |
| 531 | 531 | $protocol=$this->getRequest()->getHttpProtocolVersion(); |
| 532 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
| 532 | + if($this->getRequest()->getHttpProtocolVersion()===null) |
|
| 533 | 533 | $protocol='HTTP/1.1'; |
| 534 | 534 | |
| 535 | - $phpSapiName = substr(php_sapi_name(), 0, 3); |
|
| 536 | - $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; |
|
| 535 | + $phpSapiName=substr(php_sapi_name(), 0, 3); |
|
| 536 | + $cgi=$phpSapiName=='cgi' || $phpSapiName=='fpm'; |
|
| 537 | 537 | |
| 538 | 538 | header(($cgi ? 'Status:' : $protocol).' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
| 539 | 539 | |
| 540 | - $this->_httpHeaderSent = true; |
|
| 540 | + $this->_httpHeaderSent=true; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | protected function ensureContentTypeHeaderSent() |
| 547 | 547 | { |
| 548 | - if (!$this->_contentTypeHeaderSent) |
|
| 548 | + if(!$this->_contentTypeHeaderSent) |
|
| 549 | 549 | $this->sendContentTypeHeader(); |
| 550 | 550 | } |
| 551 | 551 | |
@@ -554,9 +554,9 @@ discard block |
||
| 554 | 554 | */ |
| 555 | 555 | protected function sendContentTypeHeader() |
| 556 | 556 | { |
| 557 | - $contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType; |
|
| 557 | + $contentType=$this->_contentType===null ? self::DEFAULT_CONTENTTYPE : $this->_contentType; |
|
| 558 | 558 | $charset=$this->getCharset(); |
| 559 | - if($charset === false) { |
|
| 559 | + if($charset===false) { |
|
| 560 | 560 | $this->appendHeader('Content-Type: '.$contentType); |
| 561 | 561 | return; |
| 562 | 562 | } |
@@ -564,10 +564,10 @@ discard block |
||
| 564 | 564 | if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) |
| 565 | 565 | $charset=$globalization->getCharset(); |
| 566 | 566 | |
| 567 | - if($charset==='') $charset = self::DEFAULT_CHARSET; |
|
| 567 | + if($charset==='') $charset=self::DEFAULT_CHARSET; |
|
| 568 | 568 | $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
| 569 | 569 | |
| 570 | - $this->_contentTypeHeaderSent = true; |
|
| 570 | + $this->_contentTypeHeaderSent=true; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
@@ -578,8 +578,8 @@ discard block |
||
| 578 | 578 | */ |
| 579 | 579 | public function getContents() |
| 580 | 580 | { |
| 581 | - Prado::trace("Retrieving output",'Prado\Web\THttpResponse'); |
|
| 582 | - return $this->_bufferOutput?ob_get_contents():''; |
|
| 581 | + Prado::trace("Retrieving output", 'Prado\Web\THttpResponse'); |
|
| 582 | + return $this->_bufferOutput ? ob_get_contents() : ''; |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | { |
| 590 | 590 | if($this->_bufferOutput) |
| 591 | 591 | ob_clean(); |
| 592 | - Prado::trace("Clearing output",'Prado\Web\THttpResponse'); |
|
| 592 | + Prado::trace("Clearing output", 'Prado\Web\THttpResponse'); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,19 +598,19 @@ discard block |
||
| 598 | 598 | */ |
| 599 | 599 | public function getHeaders($case=null) |
| 600 | 600 | { |
| 601 | - $result = array(); |
|
| 602 | - $headers = headers_list(); |
|
| 601 | + $result=array(); |
|
| 602 | + $headers=headers_list(); |
|
| 603 | 603 | foreach($headers as $header) { |
| 604 | - $tmp = explode(':', $header); |
|
| 605 | - $key = trim(array_shift($tmp)); |
|
| 606 | - $value = trim(implode(':', $tmp)); |
|
| 604 | + $tmp=explode(':', $header); |
|
| 605 | + $key=trim(array_shift($tmp)); |
|
| 606 | + $value=trim(implode(':', $tmp)); |
|
| 607 | 607 | if(isset($result[$key])) |
| 608 | - $result[$key] .= ', ' . $value; |
|
| 608 | + $result[$key].=', '.$value; |
|
| 609 | 609 | else |
| 610 | - $result[$key] = $value; |
|
| 610 | + $result[$key]=$value; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - if($case !== null) |
|
| 613 | + if($case!==null) |
|
| 614 | 614 | return array_change_key_case($result, $case); |
| 615 | 615 | |
| 616 | 616 | return $result; |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | */ |
| 624 | 624 | public function appendHeader($value, $replace=true) |
| 625 | 625 | { |
| 626 | - Prado::trace("Sending header '$value'",'Prado\Web\THttpResponse'); |
|
| 626 | + Prado::trace("Sending header '$value'", 'Prado\Web\THttpResponse'); |
|
| 627 | 627 | header($value, $replace); |
| 628 | 628 | } |
| 629 | 629 | |
@@ -636,9 +636,9 @@ discard block |
||
| 636 | 636 | * @param string The extra headers. It's used when the message parameter is set to 1. This message type uses the same internal function as mail() does. |
| 637 | 637 | * @see http://us2.php.net/manual/en/function.error-log.php |
| 638 | 638 | */ |
| 639 | - public function appendLog($message,$messageType=0,$destination='',$extraHeaders='') |
|
| 639 | + public function appendLog($message, $messageType=0, $destination='', $extraHeaders='') |
|
| 640 | 640 | { |
| 641 | - error_log($message,$messageType,$destination,$extraHeaders); |
|
| 641 | + error_log($message, $messageType, $destination, $extraHeaders); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |