Completed
Push — master ( e4371e...91317b )
by Fabio
21:45 queued 12:25
created
framework/Web/THttpResponse.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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('&amp;','&',$url), true, $this->_status);
446
+			header('Location: '.str_replace('&amp;', '&', $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('&amp;','&',$url));
450
+			header('Location: '.str_replace('&amp;', '&', $url));
451 451
 		}
452 452
 
453 453
 		if(!$this->getApplication()->getRequestCompleted())
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,12 +529,12 @@  discard block
 block discarded – undo
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 535
 		header($protocol.' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status));
536 536
 
537
-		$this->_httpHeaderSent = true;
537
+		$this->_httpHeaderSent=true;
538 538
 	}
539 539
 
540 540
 	/**
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 	 */
543 543
 	protected function ensureContentTypeHeaderSent()
544 544
 	{
545
-		if (!$this->_contentTypeHeaderSent)
545
+		if(!$this->_contentTypeHeaderSent)
546 546
 			$this->sendContentTypeHeader();
547 547
 	}
548 548
 
@@ -551,9 +551,9 @@  discard block
 block discarded – undo
551 551
 	 */
552 552
 	protected function sendContentTypeHeader()
553 553
 	{
554
-		$contentType=$this->_contentType===null?self::DEFAULT_CONTENTTYPE:$this->_contentType;
554
+		$contentType=$this->_contentType===null ? self::DEFAULT_CONTENTTYPE : $this->_contentType;
555 555
 		$charset=$this->getCharset();
556
-		if($charset === false) {
556
+		if($charset===false) {
557 557
 			$this->appendHeader('Content-Type: '.$contentType);
558 558
 			return;
559 559
 		}
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
 		if($charset==='' && ($globalization=$this->getApplication()->getGlobalization(false))!==null)
562 562
 			$charset=$globalization->getCharset();
563 563
 
564
-		if($charset==='') $charset = self::DEFAULT_CHARSET;
564
+		if($charset==='') $charset=self::DEFAULT_CHARSET;
565 565
 		$this->appendHeader('Content-Type: '.$contentType.';charset='.$charset);
566 566
 
567
-		$this->_contentTypeHeaderSent = true;
567
+		$this->_contentTypeHeaderSent=true;
568 568
 	}
569 569
 
570 570
 	/**
@@ -575,8 +575,8 @@  discard block
 block discarded – undo
575 575
 	 */
576 576
 	public function getContents()
577 577
 	{
578
-		Prado::trace("Retrieving output",'Prado\Web\THttpResponse');
579
-		return $this->_bufferOutput?ob_get_contents():'';
578
+		Prado::trace("Retrieving output", 'Prado\Web\THttpResponse');
579
+		return $this->_bufferOutput ? ob_get_contents() : '';
580 580
 	}
581 581
 
582 582
 	/**
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 	{
587 587
 		if($this->_bufferOutput)
588 588
 			ob_clean();
589
-		Prado::trace("Clearing output",'Prado\Web\THttpResponse');
589
+		Prado::trace("Clearing output", 'Prado\Web\THttpResponse');
590 590
 	}
591 591
 
592 592
 	/**
@@ -595,19 +595,19 @@  discard block
 block discarded – undo
595 595
 	 */
596 596
 	public function getHeaders($case=null)
597 597
 	{
598
-		$result = array();
599
-		$headers = headers_list();
598
+		$result=array();
599
+		$headers=headers_list();
600 600
 		foreach($headers as $header) {
601
-			$tmp = explode(':', $header);
602
-			$key = trim(array_shift($tmp));
603
-			$value = trim(implode(':', $tmp));
601
+			$tmp=explode(':', $header);
602
+			$key=trim(array_shift($tmp));
603
+			$value=trim(implode(':', $tmp));
604 604
 			if(isset($result[$key]))
605
-				$result[$key] .= ', ' . $value;
605
+				$result[$key].=', '.$value;
606 606
 			else
607
-				$result[$key] = $value;
607
+				$result[$key]=$value;
608 608
 		}
609 609
 
610
-		if($case !== null)
610
+		if($case!==null)
611 611
 			return array_change_key_case($result, $case);
612 612
 
613 613
 		return $result;
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
 	 */
621 621
 	public function appendHeader($value, $replace=true)
622 622
 	{
623
-		Prado::trace("Sending header '$value'",'Prado\Web\THttpResponse');
623
+		Prado::trace("Sending header '$value'", 'Prado\Web\THttpResponse');
624 624
 		header($value, $replace);
625 625
 	}
626 626
 
@@ -633,9 +633,9 @@  discard block
 block discarded – undo
633 633
 	 * @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.
634 634
 	 * @see http://us2.php.net/manual/en/function.error-log.php
635 635
 	 */
636
-	public function appendLog($message,$messageType=0,$destination='',$extraHeaders='')
636
+	public function appendLog($message, $messageType=0, $destination='', $extraHeaders='')
637 637
 	{
638
-		error_log($message,$messageType,$destination,$extraHeaders);
638
+		error_log($message, $messageType, $destination, $extraHeaders);
639 639
 	}
640 640
 
641 641
 	/**
Please login to merge, or discard this patch.