3 namespace MediaWiki\Rest
;
6 use Psr\Http\Message\StreamInterface
;
8 class Response
implements ResponseInterface
{
10 private $statusCode = 200;
13 private $reasonPhrase = 'OK';
16 private $protocolVersion = '1.1';
18 /** @var StreamInterface */
21 /** @var HeaderContainer */
22 private $headerContainer;
25 private $cookies = [];
28 * @internal Use ResponseFactory
29 * @param string $bodyContents
31 public function __construct( $bodyContents = '' ) {
32 $this->body
= new StringStream( $bodyContents );
33 $this->headerContainer
= new HeaderContainer
;
36 public function getStatusCode() {
37 return $this->statusCode
;
40 public function getReasonPhrase() {
41 return $this->reasonPhrase
;
44 public function setStatus( $code, $reasonPhrase = '' ) {
45 $this->statusCode
= $code;
46 if ( $reasonPhrase === '' ) {
47 $reasonPhrase = HttpStatus
::getMessage( $code ) ??
'';
49 $this->reasonPhrase
= $reasonPhrase;
52 public function getProtocolVersion() {
53 return $this->protocolVersion
;
56 public function getHeaders() {
57 return $this->headerContainer
->getHeaders();
60 public function hasHeader( $name ) {
61 return $this->headerContainer
->hasHeader( $name );
64 public function getHeader( $name ) {
65 return $this->headerContainer
->getHeader( $name );
68 public function getHeaderLine( $name ) {
69 return $this->headerContainer
->getHeaderLine( $name );
72 public function getBody() {
76 public function setProtocolVersion( $version ) {
77 $this->protocolVersion
= $version;
80 public function setHeader( $name, $value ) {
81 $this->headerContainer
->setHeader( $name, $value );
84 public function addHeader( $name, $value ) {
85 $this->headerContainer
->addHeader( $name, $value );
88 public function removeHeader( $name ) {
89 $this->headerContainer
->removeHeader( $name );
92 public function setBody( StreamInterface
$body ) {
96 public function getRawHeaderLines() {
97 return $this->headerContainer
->getRawHeaderLines();
100 public function setCookie( $name, $value, $expire = 0, $options = [] ) {
105 'options' => $options
109 public function getCookies() {
110 return $this->cookies
;