Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
Response | |
0.00% |
0 / 27 |
|
0.00% |
0 / 18 |
380 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getStatusCode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getReasonPhrase | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setStatus | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getProtocolVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaders | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHeaderLine | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setProtocolVersion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
removeHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRawHeaderLines | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setCookie | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getCookies | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Rest; |
4 | |
5 | use HttpStatus; |
6 | use Psr\Http\Message\StreamInterface; |
7 | |
8 | class Response implements ResponseInterface { |
9 | /** @var int */ |
10 | private $statusCode = 200; |
11 | |
12 | /** @var string */ |
13 | private $reasonPhrase = 'OK'; |
14 | |
15 | /** @var string */ |
16 | private $protocolVersion = '1.1'; |
17 | |
18 | /** @var StreamInterface */ |
19 | private $body; |
20 | |
21 | /** @var HeaderContainer */ |
22 | private $headerContainer; |
23 | |
24 | /** @var array */ |
25 | private $cookies = []; |
26 | |
27 | /** |
28 | * @internal Use ResponseFactory |
29 | * @param string $bodyContents |
30 | */ |
31 | public function __construct( $bodyContents = '' ) { |
32 | $this->body = new StringStream( $bodyContents ); |
33 | $this->headerContainer = new HeaderContainer; |
34 | } |
35 | |
36 | public function getStatusCode() { |
37 | return $this->statusCode; |
38 | } |
39 | |
40 | public function getReasonPhrase() { |
41 | return $this->reasonPhrase; |
42 | } |
43 | |
44 | public function setStatus( $code, $reasonPhrase = '' ) { |
45 | $this->statusCode = $code; |
46 | if ( $reasonPhrase === '' ) { |
47 | $reasonPhrase = HttpStatus::getMessage( $code ) ?? ''; |
48 | } |
49 | $this->reasonPhrase = $reasonPhrase; |
50 | } |
51 | |
52 | public function getProtocolVersion() { |
53 | return $this->protocolVersion; |
54 | } |
55 | |
56 | public function getHeaders() { |
57 | return $this->headerContainer->getHeaders(); |
58 | } |
59 | |
60 | public function hasHeader( $name ) { |
61 | return $this->headerContainer->hasHeader( $name ); |
62 | } |
63 | |
64 | public function getHeader( $name ) { |
65 | return $this->headerContainer->getHeader( $name ); |
66 | } |
67 | |
68 | public function getHeaderLine( $name ) { |
69 | return $this->headerContainer->getHeaderLine( $name ); |
70 | } |
71 | |
72 | public function getBody() { |
73 | return $this->body; |
74 | } |
75 | |
76 | public function setProtocolVersion( $version ) { |
77 | $this->protocolVersion = $version; |
78 | } |
79 | |
80 | public function setHeader( $name, $value ) { |
81 | $this->headerContainer->setHeader( $name, $value ); |
82 | } |
83 | |
84 | public function addHeader( $name, $value ) { |
85 | $this->headerContainer->addHeader( $name, $value ); |
86 | } |
87 | |
88 | public function removeHeader( $name ) { |
89 | $this->headerContainer->removeHeader( $name ); |
90 | } |
91 | |
92 | public function setBody( StreamInterface $body ) { |
93 | $this->body = $body; |
94 | } |
95 | |
96 | public function getRawHeaderLines() { |
97 | return $this->headerContainer->getRawHeaderLines(); |
98 | } |
99 | |
100 | public function setCookie( $name, $value, $expire = 0, $options = [] ) { |
101 | $this->cookies[] = [ |
102 | 'name' => $name, |
103 | 'value' => $value, |
104 | 'expire' => $expire, |
105 | 'options' => $options |
106 | ]; |
107 | } |
108 | |
109 | public function getCookies() { |
110 | return $this->cookies; |
111 | } |
112 | } |