@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | * @package System.Web |
| 67 | 67 | * @since 3.0 |
| 68 | 68 | */ |
| 69 | -class THttpRequest extends TApplicationComponent implements IteratorAggregate,ArrayAccess,Countable,IModule |
|
| 69 | +class THttpRequest extends TApplicationComponent implements IteratorAggregate, ArrayAccess, Countable, IModule |
|
| 70 | 70 | { |
| 71 | - const CGIFIX__PATH_INFO = 1; |
|
| 72 | - const CGIFIX__SCRIPT_NAME = 2; |
|
| 71 | + const CGIFIX__PATH_INFO=1; |
|
| 72 | + const CGIFIX__SCRIPT_NAME=2; |
|
| 73 | 73 | /** |
| 74 | 74 | * @var TUrlManager the URL manager module |
| 75 | 75 | */ |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | if(isset($_SERVER['REQUEST_URI'])) |
| 173 | 173 | $this->_requestUri=$_SERVER['REQUEST_URI']; |
| 174 | 174 | else // TBD: in this case, SCRIPT_NAME need to be escaped |
| 175 | - $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING']); |
|
| 175 | + $this->_requestUri=$_SERVER['SCRIPT_NAME'].(empty($_SERVER['QUERY_STRING']) ? '' : '?'.$_SERVER['QUERY_STRING']); |
|
| 176 | 176 | |
| 177 | - if($this->_cgiFix&self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
| 177 | + if($this->_cgiFix & self::CGIFIX__PATH_INFO && isset($_SERVER['ORIG_PATH_INFO'])) |
|
| 178 | 178 | $this->_pathInfo=substr($_SERVER['ORIG_PATH_INFO'], strlen($_SERVER['SCRIPT_NAME'])); |
| 179 | 179 | elseif(isset($_SERVER['PATH_INFO'])) |
| 180 | 180 | $this->_pathInfo=$_SERVER['PATH_INFO']; |
| 181 | - else if(strpos($_SERVER['PHP_SELF'],$_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
| 182 | - $this->_pathInfo=substr($_SERVER['PHP_SELF'],strlen($_SERVER['SCRIPT_NAME'])); |
|
| 181 | + else if(strpos($_SERVER['PHP_SELF'], $_SERVER['SCRIPT_NAME'])===0 && $_SERVER['PHP_SELF']!==$_SERVER['SCRIPT_NAME']) |
|
| 182 | + $this->_pathInfo=substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])); |
|
| 183 | 183 | else |
| 184 | 184 | $this->_pathInfo=''; |
| 185 | 185 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | public function stripSlashes(&$data) |
| 208 | 208 | { |
| 209 | - return is_array($data)?array_map(array($this,'stripSlashes'),$data):stripslashes($data); |
|
| 209 | + return is_array($data) ? array_map(array($this, 'stripSlashes'), $data) : stripslashes($data); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | if($this->_url===null) |
| 218 | 218 | { |
| 219 | 219 | $secure=$this->getIsSecureConnection(); |
| 220 | - $url=$secure?'https://':'http://'; |
|
| 220 | + $url=$secure ? 'https://' : 'http://'; |
|
| 221 | 221 | if(empty($_SERVER['HTTP_HOST'])) |
| 222 | 222 | { |
| 223 | 223 | $url.=$_SERVER['SERVER_NAME']; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function setEnableCache($value) |
| 242 | 242 | { |
| 243 | - $this->_enableCache = TPropertyValue::ensureBoolean($value); |
|
| 243 | + $this->_enableCache=TPropertyValue::ensureBoolean($value); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -264,15 +264,15 @@ discard block |
||
| 264 | 264 | { |
| 265 | 265 | if($this->getEnableCache()) |
| 266 | 266 | { |
| 267 | - $cache = $this->getApplication()->getCache(); |
|
| 268 | - if($cache !== null) |
|
| 267 | + $cache=$this->getApplication()->getCache(); |
|
| 268 | + if($cache!==null) |
|
| 269 | 269 | { |
| 270 | - $dependencies = null; |
|
| 271 | - if($this->getApplication()->getMode() !== TApplicationMode::Performance) |
|
| 272 | - if ($manager instanceof TUrlMapping && $fn = $manager->getConfigFile()) |
|
| 270 | + $dependencies=null; |
|
| 271 | + if($this->getApplication()->getMode()!==TApplicationMode::Performance) |
|
| 272 | + if($manager instanceof TUrlMapping && $fn=$manager->getConfigFile()) |
|
| 273 | 273 | { |
| 274 | - $fn = Prado::getPathOfNamespace($fn,$this->getApplication()->getConfigurationFileExt()); |
|
| 275 | - $dependencies = new TFileCacheDependency($fn); |
|
| 274 | + $fn=Prado::getPathOfNamespace($fn, $this->getApplication()->getConfigurationFileExt()); |
|
| 275 | + $dependencies=new TFileCacheDependency($fn); |
|
| 276 | 276 | } |
| 277 | 277 | return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); |
| 278 | 278 | } |
@@ -288,10 +288,10 @@ discard block |
||
| 288 | 288 | { |
| 289 | 289 | if($this->getEnableCache()) |
| 290 | 290 | { |
| 291 | - $cache = $this->getApplication()->getCache(); |
|
| 292 | - if($cache !== null) |
|
| 291 | + $cache=$this->getApplication()->getCache(); |
|
| 292 | + if($cache!==null) |
|
| 293 | 293 | { |
| 294 | - $manager = $cache->get($this->getCacheKey()); |
|
| 294 | + $manager=$cache->get($this->getCacheKey()); |
|
| 295 | 295 | if($manager instanceof TUrlManager) |
| 296 | 296 | return $manager; |
| 297 | 297 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | { |
| 328 | 328 | if($this->_urlManager===null) |
| 329 | 329 | { |
| 330 | - if(($this->_urlManager = $this->loadCachedUrlManager())===null) |
|
| 330 | + if(($this->_urlManager=$this->loadCachedUrlManager())===null) |
|
| 331 | 331 | { |
| 332 | 332 | if(empty($this->_urlManagerID)) |
| 333 | 333 | { |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | { |
| 339 | 339 | $this->_urlManager=$this->getApplication()->getModule($this->_urlManagerID); |
| 340 | 340 | if($this->_urlManager===null) |
| 341 | - throw new TConfigurationException('httprequest_urlmanager_inexist',$this->_urlManagerID); |
|
| 341 | + throw new TConfigurationException('httprequest_urlmanager_inexist', $this->_urlManagerID); |
|
| 342 | 342 | if(!($this->_urlManager instanceof TUrlManager)) |
| 343 | - throw new TConfigurationException('httprequest_urlmanager_invalid',$this->_urlManagerID); |
|
| 343 | + throw new TConfigurationException('httprequest_urlmanager_invalid', $this->_urlManagerID); |
|
| 344 | 344 | } |
| 345 | 345 | $this->cacheUrlManager($this->_urlManager); |
| 346 | 346 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | public function setUrlFormat($value) |
| 368 | 368 | { |
| 369 | - $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat'); |
|
| 369 | + $this->_urlFormat=TPropertyValue::ensureEnum($value, 'THttpRequestUrlFormat'); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -394,19 +394,19 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | public function getRequestType() |
| 396 | 396 | { |
| 397 | - return isset($_SERVER['REQUEST_METHOD'])?$_SERVER['REQUEST_METHOD']:null; |
|
| 397 | + return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | 401 | * @param boolean $mimetypeOnly whether to return only the mimetype (default: true) |
| 402 | 402 | * @return string content type (e.g. 'application/json' or 'text/html; encoding=gzip') or null if not specified |
| 403 | 403 | */ |
| 404 | - public function getContentType($mimetypeOnly = true) |
|
| 404 | + public function getContentType($mimetypeOnly=true) |
|
| 405 | 405 | { |
| 406 | 406 | if(!isset($_SERVER['CONTENT_TYPE'])) |
| 407 | 407 | return null; |
| 408 | 408 | |
| 409 | - if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) |
|
| 409 | + if($mimetypeOnly===true && ($_pos=strpos(';', $_SERVER['CONTENT_TYPE']))!==false) |
|
| 410 | 410 | return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); |
| 411 | 411 | |
| 412 | 412 | return $_SERVER['CONTENT_TYPE']; |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | public function getIsSecureConnection() |
| 419 | 419 | { |
| 420 | - return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off'); |
|
| 420 | + return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off'); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | */ |
| 434 | 434 | public function getQueryString() |
| 435 | 435 | { |
| 436 | - return isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:null; |
|
| 436 | + return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | */ |
| 442 | 442 | public function getHttpProtocolVersion() |
| 443 | 443 | { |
| 444 | - return isset($_SERVER['SERVER_PROTOCOL'])?$_SERVER['SERVER_PROTOCOL']:null; |
|
| 444 | + return isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -452,19 +452,19 @@ discard block |
||
| 452 | 452 | { |
| 453 | 453 | static $result; |
| 454 | 454 | |
| 455 | - if($result === null && function_exists('apache_request_headers')) { |
|
| 456 | - $result = apache_request_headers(); |
|
| 455 | + if($result===null && function_exists('apache_request_headers')) { |
|
| 456 | + $result=apache_request_headers(); |
|
| 457 | 457 | } |
| 458 | - elseif($result === null) { |
|
| 459 | - $result = array(); |
|
| 458 | + elseif($result===null) { |
|
| 459 | + $result=array(); |
|
| 460 | 460 | foreach($_SERVER as $key=>$value) { |
| 461 | - if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; |
|
| 462 | - $key = str_replace(' ','-', ucwords(strtolower(str_replace('_',' ', substr($key, 5))))); |
|
| 463 | - $result[$key] = $value; |
|
| 461 | + if(strncasecmp($key, 'HTTP_', 5)!==0) continue; |
|
| 462 | + $key=str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5))))); |
|
| 463 | + $result[$key]=$value; |
|
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if($case !== null) |
|
| 467 | + if($case!==null) |
|
| 468 | 468 | return array_change_key_case($result, $case); |
| 469 | 469 | |
| 470 | 470 | return $result; |
@@ -488,9 +488,9 @@ discard block |
||
| 488 | 488 | public function getBaseUrl($forceSecureConnection=null) |
| 489 | 489 | { |
| 490 | 490 | $url=$this->getUrl(); |
| 491 | - $scheme=($forceSecureConnection)?"https": (($forceSecureConnection === null)?$url->getScheme():'http'); |
|
| 491 | + $scheme=($forceSecureConnection) ? "https" : (($forceSecureConnection===null) ? $url->getScheme() : 'http'); |
|
| 492 | 492 | $host=$url->getHost(); |
| 493 | - if (($port=$url->getPort())) $host.=':'.$port; |
|
| 493 | + if(($port=$url->getPort())) $host.=':'.$port; |
|
| 494 | 494 | return $scheme.'://'.$host; |
| 495 | 495 | } |
| 496 | 496 | |
@@ -499,10 +499,10 @@ discard block |
||
| 499 | 499 | */ |
| 500 | 500 | public function getApplicationUrl() |
| 501 | 501 | { |
| 502 | - if($this->_cgiFix&self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
| 502 | + if($this->_cgiFix & self::CGIFIX__SCRIPT_NAME && isset($_SERVER['ORIG_SCRIPT_NAME'])) |
|
| 503 | 503 | return $_SERVER['ORIG_SCRIPT_NAME']; |
| 504 | 504 | |
| 505 | - return isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:null; |
|
| 505 | + return isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | */ |
| 515 | 515 | public function getAbsoluteApplicationUrl($forceSecureConnection=null) |
| 516 | 516 | { |
| 517 | - return $this->getBaseUrl($forceSecureConnection) . $this->getApplicationUrl(); |
|
| 517 | + return $this->getBaseUrl($forceSecureConnection).$this->getApplicationUrl(); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | */ |
| 523 | 523 | public function getApplicationFilePath() |
| 524 | 524 | { |
| 525 | - return realpath(isset($_SERVER['SCRIPT_FILENAME'])?$_SERVER['SCRIPT_FILENAME']:null); |
|
| 525 | + return realpath(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : null); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | */ |
| 531 | 531 | public function getServerName() |
| 532 | 532 | { |
| 533 | - return isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:null; |
|
| 533 | + return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | public function getServerSoftware() |
| 541 | 541 | { |
| 542 | - return isset($_SERVER['SERVER_SOFTWARE'])?$_SERVER['SERVER_SOFTWARE']:null; |
|
| 542 | + return isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | */ |
| 548 | 548 | public function getServerPort() |
| 549 | 549 | { |
| 550 | - return isset($_SERVER['SERVER_PORT'])?$_SERVER['SERVER_PORT']:null; |
|
| 550 | + return isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | */ |
| 556 | 556 | public function getUrlReferrer() |
| 557 | 557 | { |
| 558 | - return isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:null; |
|
| 558 | + return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | */ |
| 580 | 580 | public function getUserAgent() |
| 581 | 581 | { |
| 582 | - return isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:null; |
|
| 582 | + return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function getUserHostAddress() |
| 589 | 589 | { |
| 590 | - return isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:null; |
|
| 590 | + return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | */ |
| 596 | 596 | public function getUserHost() |
| 597 | 597 | { |
| 598 | - return isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:null; |
|
| 598 | + return isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : null; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | public function getAcceptTypes() |
| 605 | 605 | { |
| 606 | 606 | // TBD: break it into array?? |
| 607 | - return isset($_SERVER['HTTP_ACCEPT'])?$_SERVER['HTTP_ACCEPT']:null; |
|
| 607 | + return isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -669,13 +669,13 @@ discard block |
||
| 669 | 669 | foreach($_COOKIE as $key=>$value) |
| 670 | 670 | { |
| 671 | 671 | if(($value=$sm->validateData($value))!==false) |
| 672 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 672 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
| 673 | 673 | } |
| 674 | 674 | } |
| 675 | 675 | else |
| 676 | 676 | { |
| 677 | 677 | foreach($_COOKIE as $key=>$value) |
| 678 | - $this->_cookies->add(new THttpCookie($key,$value)); |
|
| 678 | + $this->_cookies->add(new THttpCookie($key, $value)); |
|
| 679 | 679 | } |
| 680 | 680 | } |
| 681 | 681 | return $this->_cookies; |
@@ -722,13 +722,13 @@ discard block |
||
| 722 | 722 | * @return string URL |
| 723 | 723 | * @see TUrlManager::constructUrl |
| 724 | 724 | */ |
| 725 | - public function constructUrl($serviceID,$serviceParam,$getItems=null,$encodeAmpersand=true,$encodeGetItems=true) |
|
| 725 | + public function constructUrl($serviceID, $serviceParam, $getItems=null, $encodeAmpersand=true, $encodeGetItems=true) |
|
| 726 | 726 | { |
| 727 | - if ($this->_cookieOnly===null) |
|
| 728 | - $this->_cookieOnly=(int)ini_get('session.use_cookies') && (int)ini_get('session.use_only_cookies'); |
|
| 729 | - $url=$this->getUrlManagerModule()->constructUrl($serviceID,$serviceParam,$getItems,$encodeAmpersand,$encodeGetItems); |
|
| 730 | - if(defined('SID') && SID != '' && !$this->_cookieOnly) |
|
| 731 | - return $url . (strpos($url,'?')===false? '?' : ($encodeAmpersand?'&':'&')) . SID; |
|
| 727 | + if($this->_cookieOnly===null) |
|
| 728 | + $this->_cookieOnly=(int) ini_get('session.use_cookies') && (int) ini_get('session.use_only_cookies'); |
|
| 729 | + $url=$this->getUrlManagerModule()->constructUrl($serviceID, $serviceParam, $getItems, $encodeAmpersand, $encodeGetItems); |
|
| 730 | + if(defined('SID') && SID!='' && !$this->_cookieOnly) |
|
| 731 | + return $url.(strpos($url, '?')===false ? '?' : ($encodeAmpersand ? '&' : '&')).SID; |
|
| 732 | 732 | else |
| 733 | 733 | return $url; |
| 734 | 734 | } |
@@ -756,11 +756,11 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | public function resolveRequest($serviceIDs) |
| 758 | 758 | { |
| 759 | - Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'],'System.Web.THttpRequest'); |
|
| 759 | + Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'], 'System.Web.THttpRequest'); |
|
| 760 | 760 | $getParams=$this->parseUrl(); |
| 761 | 761 | foreach($getParams as $name=>$value) |
| 762 | 762 | $_GET[$name]=$value; |
| 763 | - $this->_items=array_merge($_GET,$_POST); |
|
| 763 | + $this->_items=array_merge($_GET, $_POST); |
|
| 764 | 764 | $this->_requestResolved=true; |
| 765 | 765 | foreach($serviceIDs as $serviceID) |
| 766 | 766 | { |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | * @param mixed key |
| 872 | 872 | * @param mixed value |
| 873 | 873 | */ |
| 874 | - public function add($key,$value) |
|
| 874 | + public function add($key, $value) |
|
| 875 | 875 | { |
| 876 | 876 | $this->_items[$key]=$value; |
| 877 | 877 | } |
@@ -884,7 +884,7 @@ discard block |
||
| 884 | 884 | */ |
| 885 | 885 | public function remove($key) |
| 886 | 886 | { |
| 887 | - if(isset($this->_items[$key]) || array_key_exists($key,$this->_items)) |
|
| 887 | + if(isset($this->_items[$key]) || array_key_exists($key, $this->_items)) |
|
| 888 | 888 | { |
| 889 | 889 | $value=$this->_items[$key]; |
| 890 | 890 | unset($this->_items[$key]); |
@@ -909,7 +909,7 @@ discard block |
||
| 909 | 909 | */ |
| 910 | 910 | public function contains($key) |
| 911 | 911 | { |
| 912 | - return isset($this->_items[$key]) || array_key_exists($key,$this->_items); |
|
| 912 | + return isset($this->_items[$key]) || array_key_exists($key, $this->_items); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | /** |
@@ -948,9 +948,9 @@ discard block |
||
| 948 | 948 | * @param integer the offset to set element |
| 949 | 949 | * @param mixed the element value |
| 950 | 950 | */ |
| 951 | - public function offsetSet($offset,$item) |
|
| 951 | + public function offsetSet($offset, $item) |
|
| 952 | 952 | { |
| 953 | - $this->add($offset,$item); |
|
| 953 | + $this->add($offset, $item); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
@@ -1003,11 +1003,11 @@ discard block |
||
| 1003 | 1003 | * @param mixed new item |
| 1004 | 1004 | * @throws TInvalidDataTypeException if the item to be inserted is not a THttpCookie object. |
| 1005 | 1005 | */ |
| 1006 | - public function insertAt($index,$item) |
|
| 1006 | + public function insertAt($index, $item) |
|
| 1007 | 1007 | { |
| 1008 | 1008 | if($item instanceof THttpCookie) |
| 1009 | 1009 | { |
| 1010 | - parent::insertAt($index,$item); |
|
| 1010 | + parent::insertAt($index, $item); |
|
| 1011 | 1011 | if($this->_o instanceof THttpResponse) |
| 1012 | 1012 | $this->_o->addCookie($item); |
| 1013 | 1013 | } |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | * @param string name of this cookie |
| 1103 | 1103 | * @param string value of this cookie |
| 1104 | 1104 | */ |
| 1105 | - public function __construct($name,$value) |
|
| 1105 | + public function __construct($name, $value) |
|
| 1106 | 1106 | { |
| 1107 | 1107 | $this->_name=$name; |
| 1108 | 1108 | $this->_value=$value; |
@@ -1153,7 +1153,7 @@ discard block |
||
| 1153 | 1153 | */ |
| 1154 | 1154 | public function setHttpOnly($value) |
| 1155 | 1155 | { |
| 1156 | - $this->_httpOnly = TPropertyValue::ensureBoolean($value); |
|
| 1156 | + $this->_httpOnly=TPropertyValue::ensureBoolean($value); |
|
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | 1159 | /** |
@@ -1303,19 +1303,19 @@ discard block |
||
| 1303 | 1303 | if(($ret=@parse_url($uri))!==false) |
| 1304 | 1304 | { |
| 1305 | 1305 | // decoding??? |
| 1306 | - $this->_scheme=isset($ret['scheme'])?$ret['scheme']:''; |
|
| 1307 | - $this->_host=isset($ret['host'])?$ret['host']:''; |
|
| 1308 | - $this->_port=isset($ret['port'])?$ret['port']:''; |
|
| 1309 | - $this->_user=isset($ret['user'])?$ret['user']:''; |
|
| 1310 | - $this->_pass=isset($ret['pass'])?$ret['pass']:''; |
|
| 1311 | - $this->_path=isset($ret['path'])?$ret['path']:''; |
|
| 1312 | - $this->_query=isset($ret['query'])?$ret['query']:''; |
|
| 1313 | - $this->_fragment=isset($ret['fragment'])?$ret['fragment']:''; |
|
| 1306 | + $this->_scheme=isset($ret['scheme']) ? $ret['scheme'] : ''; |
|
| 1307 | + $this->_host=isset($ret['host']) ? $ret['host'] : ''; |
|
| 1308 | + $this->_port=isset($ret['port']) ? $ret['port'] : ''; |
|
| 1309 | + $this->_user=isset($ret['user']) ? $ret['user'] : ''; |
|
| 1310 | + $this->_pass=isset($ret['pass']) ? $ret['pass'] : ''; |
|
| 1311 | + $this->_path=isset($ret['path']) ? $ret['path'] : ''; |
|
| 1312 | + $this->_query=isset($ret['query']) ? $ret['query'] : ''; |
|
| 1313 | + $this->_fragment=isset($ret['fragment']) ? $ret['fragment'] : ''; |
|
| 1314 | 1314 | $this->_uri=$uri; |
| 1315 | 1315 | } |
| 1316 | 1316 | else |
| 1317 | 1317 | { |
| 1318 | - throw new TInvalidDataValueException('uri_format_invalid',$uri); |
|
| 1318 | + throw new TInvalidDataValueException('uri_format_invalid', $uri); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | } |
| 1321 | 1321 | |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | class THttpResponse extends TModule implements ITextWriter |
| 66 | 66 | { |
| 67 | - const DEFAULT_CONTENTTYPE = 'text/html'; |
|
| 68 | - const DEFAULT_CHARSET = 'UTF-8'; |
|
| 67 | + const DEFAULT_CONTENTTYPE='text/html'; |
|
| 68 | + const DEFAULT_CHARSET='UTF-8'; |
|
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | 71 | * @var The differents defined status code by RFC 2616 {@link http://www.faqs.org/rfcs/rfc2616} |
| 72 | 72 | */ |
| 73 | - private static $HTTP_STATUS_CODES = array( |
|
| 73 | + private static $HTTP_STATUS_CODES=array( |
|
| 74 | 74 | 100 => 'Continue', 101 => 'Switching Protocols', |
| 75 | 75 | 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', |
| 76 | 76 | 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function setCacheControl($value) |
| 203 | 203 | { |
| 204 | - session_cache_limiter(TPropertyValue::ensureEnum($value,array('none','nocache','private','private_no_expire','public'))); |
|
| 204 | + session_cache_limiter(TPropertyValue::ensureEnum($value, array('none', 'nocache', 'private', 'private_no_expire', 'public'))); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function setContentType($type) |
| 211 | 211 | { |
| 212 | - if ($this->_contentTypeHeaderSent) |
|
| 212 | + if($this->_contentTypeHeaderSent) |
|
| 213 | 213 | throw new Exception('Unable to alter content-type as it has been already sent'); |
| 214 | - $this->_contentType = $type; |
|
| 214 | + $this->_contentType=$type; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | public function setCharset($charset) |
| 237 | 237 | { |
| 238 | - $this->_charset = (strToLower($charset) === 'false') ? false : (string)$charset; |
|
| 238 | + $this->_charset=(strToLower($charset)==='false') ? false : (string) $charset; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -276,12 +276,12 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function setStatusCode($status, $reason=null) |
| 278 | 278 | { |
| 279 | - if ($this->_httpHeaderSent) |
|
| 279 | + if($this->_httpHeaderSent) |
|
| 280 | 280 | throw new Exception('Unable to alter response as HTTP header already sent'); |
| 281 | 281 | $status=TPropertyValue::ensureInteger($status); |
| 282 | 282 | if(isset(self::$HTTP_STATUS_CODES[$status])) { |
| 283 | 283 | $this->_reason=self::$HTTP_STATUS_CODES[$status]; |
| 284 | - }else{ |
|
| 284 | + } else { |
|
| 285 | 285 | if($reason===null || $reason==='') { |
| 286 | 286 | throw new TInvalidDataValueException("response_status_reason_missing"); |
| 287 | 287 | } |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | public function write($str) |
| 320 | 320 | { |
| 321 | 321 | // when starting output make sure we send the headers first |
| 322 | - if (!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
| 322 | + if(!$this->_bufferOutput and !$this->_httpHeaderSent) |
|
| 323 | 323 | $this->ensureHeadersSent(); |
| 324 | 324 | echo $str; |
| 325 | 325 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * @param integer size of file or content in bytes if already known. Defaults to 'null' means auto-detect. |
| 337 | 337 | * @throws TInvalidDataValueException if the file cannot be found |
| 338 | 338 | */ |
| 339 | - public function writeFile($fileName,$content=null,$mimeType=null,$headers=null,$forceDownload=true,$clientFileName=null,$fileSize=null) |
|
| 339 | + public function writeFile($fileName, $content=null, $mimeType=null, $headers=null, $forceDownload=true, $clientFileName=null, $fileSize=null) |
|
| 340 | 340 | { |
| 341 | 341 | static $defaultMimeTypes=array( |
| 342 | 342 | 'css'=>'text/css', |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | $mimeType='text/plain'; |
| 357 | 357 | if(function_exists('mime_content_type')) |
| 358 | 358 | $mimeType=mime_content_type($fileName); |
| 359 | - else if(($ext=strrchr($fileName,'.'))!==false) |
|
| 359 | + else if(($ext=strrchr($fileName, '.'))!==false) |
|
| 360 | 360 | { |
| 361 | - $ext=substr($ext,1); |
|
| 361 | + $ext=substr($ext, 1); |
|
| 362 | 362 | if(isset($defaultMimeTypes[$ext])) |
| 363 | 363 | $mimeType=$defaultMimeTypes[$ext]; |
| 364 | 364 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | $clientFileName=basename($clientFileName); |
| 371 | 371 | |
| 372 | 372 | if($fileSize===null || $fileSize < 0) |
| 373 | - $fileSize = ($content===null?filesize($fileName):strlen($content)); |
|
| 373 | + $fileSize=($content===null ? filesize($fileName) : strlen($content)); |
|
| 374 | 374 | |
| 375 | 375 | $this->sendHttpHeader(); |
| 376 | 376 | if(is_array($headers)) |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | header('Expires: 0'); |
| 385 | 385 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 386 | 386 | header("Content-Type: $mimeType"); |
| 387 | - $this->_contentTypeHeaderSent = true; |
|
| 387 | + $this->_contentTypeHeaderSent=true; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | header('Content-Length: '.$fileSize); |
| 391 | - header("Content-Disposition: " . ($forceDownload ? 'attachment' : 'inline') . "; filename=\"$clientFileName\""); |
|
| 391 | + header("Content-Disposition: ".($forceDownload ? 'attachment' : 'inline')."; filename=\"$clientFileName\""); |
|
| 392 | 392 | header('Content-Transfer-Encoding: binary'); |
| 393 | 393 | if($content===null) |
| 394 | 394 | readfile($fileName); |
@@ -428,25 +428,25 @@ discard block |
||
| 428 | 428 | |
| 429 | 429 | // Under IIS, explicitly send an HTTP response including the status code |
| 430 | 430 | // this is handled automatically by PHP on Apache and others |
| 431 | - $isIIS = (stripos($this->getRequest()->getServerSoftware(), "microsoft-iis") !== false); |
|
| 431 | + $isIIS=(stripos($this->getRequest()->getServerSoftware(), "microsoft-iis")!==false); |
|
| 432 | 432 | if($url[0]==='/') |
| 433 | 433 | $url=$this->getRequest()->getBaseUrl().$url; |
| 434 | - if ($this->_status >= 300 && $this->_status < 400) |
|
| 434 | + if($this->_status >= 300 && $this->_status < 400) |
|
| 435 | 435 | { |
| 436 | 436 | // The status code has been modified to a valid redirection status, send it |
| 437 | 437 | if($isIIS) |
| 438 | 438 | { |
| 439 | - header('HTTP/1.1 ' . $this->_status . ' ' . self::$HTTP_STATUS_CODES[ |
|
| 439 | + header('HTTP/1.1 '.$this->_status.' '.self::$HTTP_STATUS_CODES[ |
|
| 440 | 440 | array_key_exists($this->_status, self::$HTTP_STATUS_CODES) |
| 441 | 441 | ? $this->_status |
| 442 | 442 | : 302 |
| 443 | 443 | ]); |
| 444 | 444 | } |
| 445 | - header('Location: '.str_replace('&','&',$url), true, $this->_status); |
|
| 445 | + header('Location: '.str_replace('&', '&', $url), true, $this->_status); |
|
| 446 | 446 | } else { |
| 447 | 447 | if($isIIS) |
| 448 | 448 | header('HTTP/1.1 302 '.self::$HTTP_STATUS_CODES[302]); |
| 449 | - header('Location: '.str_replace('&','&',$url)); |
|
| 449 | + header('Location: '.str_replace('&', '&', $url)); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | if(!$this->getApplication()->getRequestCompleted()) |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | /** |
| 469 | 469 | * Flush the response contents and headers. |
| 470 | 470 | */ |
| 471 | - public function flush($continueBuffering = true) |
|
| 471 | + public function flush($continueBuffering=true) |
|
| 472 | 472 | { |
| 473 | 473 | if($this->getHasAdapter()) |
| 474 | 474 | $this->_adapter->flushContent($continueBuffering); |
@@ -490,18 +490,18 @@ discard block |
||
| 490 | 490 | * This method is used internally. Please use {@link flush} instead. |
| 491 | 491 | * @param boolean whether to continue buffering after flush if buffering was active |
| 492 | 492 | */ |
| 493 | - public function flushContent($continueBuffering = true) |
|
| 493 | + public function flushContent($continueBuffering=true) |
|
| 494 | 494 | { |
| 495 | - Prado::trace("Flushing output",'System.Web.THttpResponse'); |
|
| 495 | + Prado::trace("Flushing output", 'System.Web.THttpResponse'); |
|
| 496 | 496 | $this->ensureHeadersSent(); |
| 497 | 497 | if($this->_bufferOutput) |
| 498 | 498 | { |
| 499 | 499 | // avoid forced send of http headers (ob_flush() does that) if there's no output yet |
| 500 | - if (ob_get_length()>0) |
|
| 500 | + if(ob_get_length() > 0) |
|
| 501 | 501 | { |
| 502 | - if (!$continueBuffering) |
|
| 502 | + if(!$continueBuffering) |
|
| 503 | 503 | { |
| 504 | - $this->_bufferOutput = false; |
|
| 504 | + $this->_bufferOutput=false; |
|
| 505 | 505 | ob_end_flush(); |
| 506 | 506 | } |
| 507 | 507 | else |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | */ |
| 519 | 519 | protected function ensureHttpHeaderSent() |
| 520 | 520 | { |
| 521 | - if (!$this->_httpHeaderSent) |
|
| 521 | + if(!$this->_httpHeaderSent) |
|
| 522 | 522 | $this->sendHttpHeader(); |
| 523 | 523 | } |
| 524 | 524 | |
@@ -528,15 +528,15 @@ discard block |
||
| 528 | 528 | protected function sendHttpHeader() |
| 529 | 529 | { |
| 530 | 530 | $protocol=$this->getRequest()->getHttpProtocolVersion(); |
| 531 | - if($this->getRequest()->getHttpProtocolVersion() === null) |
|
| 531 | + if($this->getRequest()->getHttpProtocolVersion()===null) |
|
| 532 | 532 | $protocol='HTTP/1.1'; |
| 533 | 533 | |
| 534 | - $phpSapiName = substr(php_sapi_name(), 0, 3); |
|
| 535 | - $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; |
|
| 534 | + $phpSapiName=substr(php_sapi_name(), 0, 3); |
|
| 535 | + $cgi=$phpSapiName=='cgi' || $phpSapiName=='fpm'; |
|
| 536 | 536 | |
| 537 | 537 | header(($cgi ? 'Status:' : $protocol).' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
| 538 | 538 | |
| 539 | - $this->_httpHeaderSent = true; |
|
| 539 | + $this->_httpHeaderSent=true; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | protected function ensureContentTypeHeaderSent() |
| 546 | 546 | { |
| 547 | - if (!$this->_contentTypeHeaderSent) |
|
| 547 | + if(!$this->_contentTypeHeaderSent) |
|
| 548 | 548 | $this->sendContentTypeHeader(); |
| 549 | 549 | } |
| 550 | 550 | |
@@ -553,9 +553,9 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | protected function sendContentTypeHeader() |
| 555 | 555 | { |
| 556 | - $contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType; |
|
| 556 | + $contentType=$this->_contentType===null ? self::DEFAULT_CONTENTTYPE : $this->_contentType; |
|
| 557 | 557 | $charset=$this->getCharset(); |
| 558 | - if($charset === false) { |
|
| 558 | + if($charset===false) { |
|
| 559 | 559 | $this->appendHeader('Content-Type: '.$contentType); |
| 560 | 560 | return; |
| 561 | 561 | } |
@@ -563,10 +563,10 @@ discard block |
||
| 563 | 563 | if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) |
| 564 | 564 | $charset=$globalization->getCharset(); |
| 565 | 565 | |
| 566 | - if($charset==='') $charset = self::DEFAULT_CHARSET; |
|
| 566 | + if($charset==='') $charset=self::DEFAULT_CHARSET; |
|
| 567 | 567 | $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
| 568 | 568 | |
| 569 | - $this->_contentTypeHeaderSent = true; |
|
| 569 | + $this->_contentTypeHeaderSent=true; |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /** |
@@ -577,8 +577,8 @@ discard block |
||
| 577 | 577 | */ |
| 578 | 578 | public function getContents() |
| 579 | 579 | { |
| 580 | - Prado::trace("Retrieving output",'System.Web.THttpResponse'); |
|
| 581 | - return $this->_bufferOutput?ob_get_contents():''; |
|
| 580 | + Prado::trace("Retrieving output", 'System.Web.THttpResponse'); |
|
| 581 | + return $this->_bufferOutput ? ob_get_contents() : ''; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | { |
| 589 | 589 | if($this->_bufferOutput) |
| 590 | 590 | ob_clean(); |
| 591 | - Prado::trace("Clearing output",'System.Web.THttpResponse'); |
|
| 591 | + Prado::trace("Clearing output", 'System.Web.THttpResponse'); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -597,19 +597,19 @@ discard block |
||
| 597 | 597 | */ |
| 598 | 598 | public function getHeaders($case=null) |
| 599 | 599 | { |
| 600 | - $result = array(); |
|
| 601 | - $headers = headers_list(); |
|
| 600 | + $result=array(); |
|
| 601 | + $headers=headers_list(); |
|
| 602 | 602 | foreach($headers as $header) { |
| 603 | - $tmp = explode(':', $header); |
|
| 604 | - $key = trim(array_shift($tmp)); |
|
| 605 | - $value = trim(implode(':', $tmp)); |
|
| 603 | + $tmp=explode(':', $header); |
|
| 604 | + $key=trim(array_shift($tmp)); |
|
| 605 | + $value=trim(implode(':', $tmp)); |
|
| 606 | 606 | if(isset($result[$key])) |
| 607 | - $result[$key] .= ', ' . $value; |
|
| 607 | + $result[$key].=', '.$value; |
|
| 608 | 608 | else |
| 609 | - $result[$key] = $value; |
|
| 609 | + $result[$key]=$value; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - if($case !== null) |
|
| 612 | + if($case!==null) |
|
| 613 | 613 | return array_change_key_case($result, $case); |
| 614 | 614 | |
| 615 | 615 | return $result; |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | public function appendHeader($value, $replace=true) |
| 624 | 624 | { |
| 625 | - Prado::trace("Sending header '$value'",'System.Web.THttpResponse'); |
|
| 625 | + Prado::trace("Sending header '$value'", 'System.Web.THttpResponse'); |
|
| 626 | 626 | header($value, $replace); |
| 627 | 627 | } |
| 628 | 628 | |
@@ -635,9 +635,9 @@ discard block |
||
| 635 | 635 | * @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. |
| 636 | 636 | * @see http://us2.php.net/manual/en/function.error-log.php |
| 637 | 637 | */ |
| 638 | - public function appendLog($message,$messageType=0,$destination='',$extraHeaders='') |
|
| 638 | + public function appendLog($message, $messageType=0, $destination='', $extraHeaders='') |
|
| 639 | 639 | { |
| 640 | - error_log($message,$messageType,$destination,$extraHeaders); |
|
| 640 | + error_log($message, $messageType, $destination, $extraHeaders); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |