1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* THttpResponseAdatper class |
4
|
|
|
* |
5
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
6
|
|
|
* @link https://github.com/pradosoft/prado |
7
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
8
|
|
|
* @package Prado\Web |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Prado\Web; |
12
|
|
|
|
13
|
|
|
use Prado\Exceptions\TInvalidOperationException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* THttpResponseAdapter class. |
17
|
|
|
* |
18
|
|
|
* THttpResponseAdapter allows the base http response class to change behavior |
19
|
|
|
* without change the class hierarchy. |
20
|
|
|
* |
21
|
|
|
* @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
22
|
|
|
* @package Prado\Web |
23
|
|
|
* @since 3.0 |
24
|
|
|
*/ |
25
|
|
|
class THttpResponseAdapter extends \Prado\TApplicationComponent |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var THttpResponse the response object the adapter is attached. |
29
|
|
|
*/ |
30
|
|
|
private $_response; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. Attach a response to be adapted. |
34
|
|
|
* @param THttpResponse $response the response object the adapter is to attach to. |
35
|
|
|
*/ |
36
|
|
|
public function __construct($response) |
37
|
|
|
{ |
38
|
|
|
$this->_response = $response; |
39
|
|
|
parent::__construct(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return THttpResponse the response object adapted. |
44
|
|
|
*/ |
45
|
|
|
public function getResponse() |
46
|
|
|
{ |
47
|
|
|
return $this->_response; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* This method is invoked when the response flushes the content and headers. |
52
|
|
|
* Default implementation calls the attached response flushContent method. |
53
|
|
|
* @param bool $continueBuffering |
54
|
|
|
*/ |
55
|
|
|
public function flushContent($continueBuffering = true) |
56
|
|
|
{ |
57
|
|
|
$this->_response->flushContent($continueBuffering); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* This method is invoked when the response is to redirect to another page. |
62
|
|
|
* @param string $url new url to redirect to. |
63
|
|
|
*/ |
64
|
|
|
public function httpRedirect($url) |
65
|
|
|
{ |
66
|
|
|
$this->_response->httpRedirect($url); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* This method is invoked when a new HtmlWriter needs to be created. |
71
|
|
|
* Default implementation calls the attached response createNewHtmlWriter method. |
72
|
|
|
* @param string $type type of the HTML writer to be created. |
73
|
|
|
* @param \Prado\IO\ITextWriter $writer the writer responsible for holding the content. |
74
|
|
|
*/ |
75
|
|
|
public function createNewHtmlWriter($type, $writer) |
76
|
|
|
{ |
77
|
|
|
return $this->_response->createNewHtmlWriter($type, $writer); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @throws TInvalidOperationException |
82
|
|
|
*/ |
83
|
|
|
public function setResponseData($data) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
throw new TInvalidOperationException('httpresponse_responsedata_method_unavailable', __METHOD__); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @throws TInvalidOperationException |
90
|
|
|
*/ |
91
|
|
|
public function getResponseData() |
92
|
|
|
{ |
93
|
|
|
throw new TInvalidOperationException('httpresponse_responsedata_method_unavailable', __METHOD__); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.