@@ -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,12 +528,12 @@ 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 | 534 | header($protocol.' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); |
| 535 | 535 | |
| 536 | - $this->_httpHeaderSent = true; |
|
| 536 | + $this->_httpHeaderSent=true; |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | /** |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | */ |
| 542 | 542 | protected function ensureContentTypeHeaderSent() |
| 543 | 543 | { |
| 544 | - if (!$this->_contentTypeHeaderSent) |
|
| 544 | + if(!$this->_contentTypeHeaderSent) |
|
| 545 | 545 | $this->sendContentTypeHeader(); |
| 546 | 546 | } |
| 547 | 547 | |
@@ -550,9 +550,9 @@ discard block |
||
| 550 | 550 | */ |
| 551 | 551 | protected function sendContentTypeHeader() |
| 552 | 552 | { |
| 553 | - $contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType; |
|
| 553 | + $contentType=$this->_contentType===null ? self::DEFAULT_CONTENTTYPE : $this->_contentType; |
|
| 554 | 554 | $charset=$this->getCharset(); |
| 555 | - if($charset === false) { |
|
| 555 | + if($charset===false) { |
|
| 556 | 556 | $this->appendHeader('Content-Type: '.$contentType); |
| 557 | 557 | return; |
| 558 | 558 | } |
@@ -560,10 +560,10 @@ discard block |
||
| 560 | 560 | if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null) |
| 561 | 561 | $charset=$globalization->getCharset(); |
| 562 | 562 | |
| 563 | - if($charset==='') $charset = self::DEFAULT_CHARSET; |
|
| 563 | + if($charset==='') $charset=self::DEFAULT_CHARSET; |
|
| 564 | 564 | $this->appendHeader('Content-Type: '.$contentType.';charset='.$charset); |
| 565 | 565 | |
| 566 | - $this->_contentTypeHeaderSent = true; |
|
| 566 | + $this->_contentTypeHeaderSent=true; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -574,8 +574,8 @@ discard block |
||
| 574 | 574 | */ |
| 575 | 575 | public function getContents() |
| 576 | 576 | { |
| 577 | - Prado::trace("Retrieving output",'System.Web.THttpResponse'); |
|
| 578 | - return $this->_bufferOutput?ob_get_contents():''; |
|
| 577 | + Prado::trace("Retrieving output", 'System.Web.THttpResponse'); |
|
| 578 | + return $this->_bufferOutput ? ob_get_contents() : ''; |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /** |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | { |
| 586 | 586 | if($this->_bufferOutput) |
| 587 | 587 | ob_clean(); |
| 588 | - Prado::trace("Clearing output",'System.Web.THttpResponse'); |
|
| 588 | + Prado::trace("Clearing output", 'System.Web.THttpResponse'); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -594,19 +594,19 @@ discard block |
||
| 594 | 594 | */ |
| 595 | 595 | public function getHeaders($case=null) |
| 596 | 596 | { |
| 597 | - $result = array(); |
|
| 598 | - $headers = headers_list(); |
|
| 597 | + $result=array(); |
|
| 598 | + $headers=headers_list(); |
|
| 599 | 599 | foreach($headers as $header) { |
| 600 | - $tmp = explode(':', $header); |
|
| 601 | - $key = trim(array_shift($tmp)); |
|
| 602 | - $value = trim(implode(':', $tmp)); |
|
| 600 | + $tmp=explode(':', $header); |
|
| 601 | + $key=trim(array_shift($tmp)); |
|
| 602 | + $value=trim(implode(':', $tmp)); |
|
| 603 | 603 | if(isset($result[$key])) |
| 604 | - $result[$key] .= ', ' . $value; |
|
| 604 | + $result[$key].=', '.$value; |
|
| 605 | 605 | else |
| 606 | - $result[$key] = $value; |
|
| 606 | + $result[$key]=$value; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - if($case !== null) |
|
| 609 | + if($case!==null) |
|
| 610 | 610 | return array_change_key_case($result, $case); |
| 611 | 611 | |
| 612 | 612 | return $result; |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | */ |
| 620 | 620 | public function appendHeader($value, $replace=true) |
| 621 | 621 | { |
| 622 | - Prado::trace("Sending header '$value'",'System.Web.THttpResponse'); |
|
| 622 | + Prado::trace("Sending header '$value'", 'System.Web.THttpResponse'); |
|
| 623 | 623 | header($value, $replace); |
| 624 | 624 | } |
| 625 | 625 | |
@@ -632,9 +632,9 @@ discard block |
||
| 632 | 632 | * @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. |
| 633 | 633 | * @see http://us2.php.net/manual/en/function.error-log.php |
| 634 | 634 | */ |
| 635 | - public function appendLog($message,$messageType=0,$destination='',$extraHeaders='') |
|
| 635 | + public function appendLog($message, $messageType=0, $destination='', $extraHeaders='') |
|
| 636 | 636 | { |
| 637 | - error_log($message,$messageType,$destination,$extraHeaders); |
|
| 637 | + error_log($message, $messageType, $destination, $extraHeaders); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |