1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Psr\Servlet\ServletResponseWrapper |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io-psr/servlet |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Psr\Servlet; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* A servlet response implementation. |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/appserver-io-psr/servlet |
30
|
|
|
* @link http://www.appserver.io |
31
|
|
|
*/ |
32
|
|
|
class ServletResponseWrapper implements ServletResponseInterface |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The response instance. |
37
|
|
|
* |
38
|
|
|
* @var \AppserverIo\Psr\Servlet\ServletResponseInterface |
39
|
|
|
*/ |
40
|
|
|
protected $response; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Injects the passed response instance into this servlet response. |
44
|
|
|
* |
45
|
|
|
* @param \AppserverIo\Psr\Servlet\ServletResponseInterface $response The response instance used for initialization |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
2 |
|
public function injectResponse(ServletResponseInterface $response) |
50
|
|
|
{ |
51
|
2 |
|
$this->response = $response; |
52
|
2 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the response that will be send back to the client. |
56
|
|
|
* |
57
|
|
|
* @return \AppserverIo\Psr\Servlet\ServletResponseInterface The response instance |
58
|
|
|
*/ |
59
|
1 |
|
public function getResponse() |
60
|
|
|
{ |
61
|
1 |
|
return $this->response; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Appends body stream with content. |
66
|
|
|
* |
67
|
|
|
* @param string $content The content to append |
68
|
|
|
* |
69
|
|
|
* @return integer The number of written bytes |
70
|
|
|
*/ |
71
|
|
|
public function appendBodyStream($content) |
72
|
|
|
{ |
73
|
|
|
return $this->getResponse()->appendBodyStream($content); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Copies a source stream to body stream. |
78
|
|
|
* |
79
|
|
|
* @param resource $sourceStream The file pointer to source stream |
80
|
|
|
* @param integer $maxlength The max length to read from source stream |
81
|
|
|
* @param integer $offset The offset from source stream to read |
82
|
|
|
* |
83
|
|
|
* @return integer the total number of bytes copied |
84
|
|
|
*/ |
85
|
|
|
public function copyBodyStream($sourceStream, $maxlength = null, $offset = null) |
86
|
|
|
{ |
87
|
|
|
return $this->getResponse()->copyBodyStream($sourceStream, $maxlength, $offset); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns the body stream as a resource. |
92
|
|
|
* |
93
|
|
|
* @return resource The body stream |
94
|
|
|
*/ |
95
|
1 |
|
public function getBodyStream() |
96
|
|
|
{ |
97
|
1 |
|
return $this->getResponse()->getBodyStream(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the body content |
102
|
|
|
* |
103
|
|
|
* @return string $content |
104
|
|
|
*/ |
105
|
|
|
public function getBodyContent() |
106
|
|
|
{ |
107
|
|
|
return $this->getResponse()->getBodyContent(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Reset the body stream |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
public function resetBodyStream() |
116
|
|
|
{ |
117
|
|
|
$this->getResponse()->resetBodyStream(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Resets the stream resource pointing to body content. |
122
|
|
|
* |
123
|
|
|
* @param resource $bodyStream The body content stream resource |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
|
|
public function setBodyStream($bodyStream) |
128
|
|
|
{ |
129
|
|
|
$this->getResponse()->setBodyStream($bodyStream); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|