ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Response.php
Go to the documentation of this file.
1<?php
2namespace GuzzleHttp\Psr7;
3
6
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->statusCode = (int) $status;
97
98 if ($body !== '' && $body !== null) {
99 $this->stream = stream_for($body);
100 }
101
102 $this->setHeaders($headers);
103 if ($reason == '' && isset(self::$phrases[$this->statusCode])) {
104 $this->reasonPhrase = self::$phrases[$this->statusCode];
105 } else {
106 $this->reasonPhrase = (string) $reason;
107 }
108
109 $this->protocol = $version;
110 }
111
112 public function getStatusCode()
113 {
114 return $this->statusCode;
115 }
116
117 public function getReasonPhrase()
118 {
119 return $this->reasonPhrase;
120 }
121
122 public function withStatus($code, $reasonPhrase = '')
123 {
124 $new = clone $this;
125 $new->statusCode = (int) $code;
126 if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) {
127 $reasonPhrase = self::$phrases[$new->statusCode];
128 }
129 $new->reasonPhrase = $reasonPhrase;
130 return $new;
131 }
132}
$version
Definition: build.php:27
An exception for terminatinating execution or to throw for unit testing.
PSR-7 response implementation.
Definition: Response.php:11
__construct( $status=200, array $headers=[], $body=null, $version='1.1', $reason=null)
Definition: Response.php:89
getReasonPhrase()
Gets the response reason phrase associated with the status code.
Definition: Response.php:117
withStatus($code, $reasonPhrase='')
Return an instance with the specified status code and, optionally, reason phrase.
Definition: Response.php:122
getStatusCode()
Gets the response status code.
Definition: Response.php:112
$code
Definition: example_050.php:99
Representation of an outgoing, server-side response.
Describes a data stream.
stream_for($resource='', array $options=[])
Create a new stream based on the input type.
Definition: functions.php:78
trait MessageTrait
Trait implementing functionality common to requests and responses.
setHeaders(array $headers)