Open Journal Systems  3.3.0
vendor/guzzlehttp/psr7/src/Response.php
1 <?php
2 namespace GuzzleHttp\Psr7;
3 
6 
10 class Response implements ResponseInterface
11 {
12  use MessageTrait;
13 
15  private static $phrases = [
16  100 => 'Continue',
17  101 => 'Switching Protocols',
18  102 => 'Processing',
19  200 => 'OK',
20  201 => 'Created',
21  202 => 'Accepted',
22  203 => 'Non-Authoritative Information',
23  204 => 'No Content',
24  205 => 'Reset Content',
25  206 => 'Partial Content',
26  207 => 'Multi-status',
27  208 => 'Already Reported',
28  300 => 'Multiple Choices',
29  301 => 'Moved Permanently',
30  302 => 'Found',
31  303 => 'See Other',
32  304 => 'Not Modified',
33  305 => 'Use Proxy',
34  306 => 'Switch Proxy',
35  307 => 'Temporary Redirect',
36  400 => 'Bad Request',
37  401 => 'Unauthorized',
38  402 => 'Payment Required',
39  403 => 'Forbidden',
40  404 => 'Not Found',
41  405 => 'Method Not Allowed',
42  406 => 'Not Acceptable',
43  407 => 'Proxy Authentication Required',
44  408 => 'Request Time-out',
45  409 => 'Conflict',
46  410 => 'Gone',
47  411 => 'Length Required',
48  412 => 'Precondition Failed',
49  413 => 'Request Entity Too Large',
50  414 => 'Request-URI Too Large',
51  415 => 'Unsupported Media Type',
52  416 => 'Requested range not satisfiable',
53  417 => 'Expectation Failed',
54  418 => 'I\'m a teapot',
55  422 => 'Unprocessable Entity',
56  423 => 'Locked',
57  424 => 'Failed Dependency',
58  425 => 'Unordered Collection',
59  426 => 'Upgrade Required',
60  428 => 'Precondition Required',
61  429 => 'Too Many Requests',
62  431 => 'Request Header Fields Too Large',
63  451 => 'Unavailable For Legal Reasons',
64  500 => 'Internal Server Error',
65  501 => 'Not Implemented',
66  502 => 'Bad Gateway',
67  503 => 'Service Unavailable',
68  504 => 'Gateway Time-out',
69  505 => 'HTTP Version not supported',
70  506 => 'Variant Also Negotiates',
71  507 => 'Insufficient Storage',
72  508 => 'Loop Detected',
73  511 => 'Network Authentication Required',
74  ];
75 
77  private $reasonPhrase = '';
78 
80  private $statusCode = 200;
81 
89  public function __construct(
90  $status = 200,
91  array $headers = [],
92  $body = null,
93  $version = '1.1',
94  $reason = null
95  ) {
96  $this->assertStatusCodeIsInteger($status);
97  $status = (int) $status;
98  $this->assertStatusCodeRange($status);
99 
100  $this->statusCode = $status;
101 
102  if ($body !== '' && $body !== null) {
103  $this->stream = stream_for($body);
104  }
105 
106  $this->setHeaders($headers);
107  if ($reason == '' && isset(self::$phrases[$this->statusCode])) {
108  $this->reasonPhrase = self::$phrases[$this->statusCode];
109  } else {
110  $this->reasonPhrase = (string) $reason;
111  }
112 
113  $this->protocol = $version;
114  }
115 
116  public function getStatusCode()
117  {
118  return $this->statusCode;
119  }
120 
121  public function getReasonPhrase()
122  {
123  return $this->reasonPhrase;
124  }
125 
126  public function withStatus($code, $reasonPhrase = '')
127  {
128  $this->assertStatusCodeIsInteger($code);
129  $code = (int) $code;
130  $this->assertStatusCodeRange($code);
131 
132  $new = clone $this;
133  $new->statusCode = $code;
134  if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) {
135  $reasonPhrase = self::$phrases[$new->statusCode];
136  }
137  $new->reasonPhrase = $reasonPhrase;
138  return $new;
139  }
140 
141  private function assertStatusCodeIsInteger($statusCode)
142  {
143  if (filter_var($statusCode, FILTER_VALIDATE_INT) === false) {
144  throw new \InvalidArgumentException('Status code must be an integer value.');
145  }
146  }
147 
148  private function assertStatusCodeRange($statusCode)
149  {
150  if ($statusCode < 100 || $statusCode >= 600) {
151  throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
152  }
153  }
154 }
GuzzleHttp\Psr7\Response
Definition: vendor/guzzlehttp/psr7/src/Response.php:10
Psr\Http\Message\StreamInterface
Definition: vendor/psr/http-message/src/StreamInterface.php:12
GuzzleHttp\Psr7\MessageTrait
trait MessageTrait
Definition: MessageTrait.php:10
GuzzleHttp\Psr7\Response\withStatus
withStatus($code, $reasonPhrase='')
Definition: vendor/guzzlehttp/psr7/src/Response.php:132
GuzzleHttp\Psr7
Definition: AppendStream.php:2
Psr\Http\Message\ResponseInterface
Definition: vendor/psr/http-message/src/ResponseInterface.php:20
GuzzleHttp\Psr7\Response\getStatusCode
getStatusCode()
Definition: vendor/guzzlehttp/psr7/src/Response.php:122
GuzzleHttp\Psr7\Response\getReasonPhrase
getReasonPhrase()
Definition: vendor/guzzlehttp/psr7/src/Response.php:127
GuzzleHttp\Psr7\stream_for
stream_for($resource='', array $options=[])
Definition: guzzlehttp/psr7/src/functions.php:78
GuzzleHttp\Psr7\Response\__construct
__construct( $status=200, array $headers=[], $body=null, $version='1.1', $reason=null)
Definition: vendor/guzzlehttp/psr7/src/Response.php:95