Chris@0: 'Continue', Chris@0: 101 => 'Switching Protocols', Chris@0: 102 => 'Processing', Chris@0: 200 => 'OK', Chris@0: 201 => 'Created', Chris@0: 202 => 'Accepted', Chris@0: 203 => 'Non-Authoritative Information', Chris@0: 204 => 'No Content', Chris@0: 205 => 'Reset Content', Chris@0: 206 => 'Partial Content', Chris@0: 207 => 'Multi-status', Chris@0: 208 => 'Already Reported', Chris@0: 300 => 'Multiple Choices', Chris@0: 301 => 'Moved Permanently', Chris@0: 302 => 'Found', Chris@0: 303 => 'See Other', Chris@0: 304 => 'Not Modified', Chris@0: 305 => 'Use Proxy', Chris@0: 306 => 'Switch Proxy', Chris@0: 307 => 'Temporary Redirect', Chris@0: 400 => 'Bad Request', Chris@0: 401 => 'Unauthorized', Chris@0: 402 => 'Payment Required', Chris@0: 403 => 'Forbidden', Chris@0: 404 => 'Not Found', Chris@0: 405 => 'Method Not Allowed', Chris@0: 406 => 'Not Acceptable', Chris@0: 407 => 'Proxy Authentication Required', Chris@0: 408 => 'Request Time-out', Chris@0: 409 => 'Conflict', Chris@0: 410 => 'Gone', Chris@0: 411 => 'Length Required', Chris@0: 412 => 'Precondition Failed', Chris@0: 413 => 'Request Entity Too Large', Chris@0: 414 => 'Request-URI Too Large', Chris@0: 415 => 'Unsupported Media Type', Chris@0: 416 => 'Requested range not satisfiable', Chris@0: 417 => 'Expectation Failed', Chris@0: 418 => 'I\'m a teapot', Chris@0: 422 => 'Unprocessable Entity', Chris@0: 423 => 'Locked', Chris@0: 424 => 'Failed Dependency', Chris@0: 425 => 'Unordered Collection', Chris@0: 426 => 'Upgrade Required', Chris@0: 428 => 'Precondition Required', Chris@0: 429 => 'Too Many Requests', Chris@0: 431 => 'Request Header Fields Too Large', Chris@0: 451 => 'Unavailable For Legal Reasons', Chris@0: 500 => 'Internal Server Error', Chris@0: 501 => 'Not Implemented', Chris@0: 502 => 'Bad Gateway', Chris@0: 503 => 'Service Unavailable', Chris@0: 504 => 'Gateway Time-out', Chris@0: 505 => 'HTTP Version not supported', Chris@0: 506 => 'Variant Also Negotiates', Chris@0: 507 => 'Insufficient Storage', Chris@0: 508 => 'Loop Detected', Chris@0: 511 => 'Network Authentication Required', Chris@0: ]; Chris@0: Chris@0: /** @var string */ Chris@0: private $reasonPhrase = ''; Chris@0: Chris@0: /** @var int */ Chris@0: private $statusCode = 200; Chris@0: Chris@0: /** Chris@0: * @param int $status Status code Chris@0: * @param array $headers Response headers Chris@0: * @param string|null|resource|StreamInterface $body Response body Chris@0: * @param string $version Protocol version Chris@0: * @param string|null $reason Reason phrase (when empty a default will be used based on the status code) Chris@0: */ Chris@0: public function __construct( Chris@0: $status = 200, Chris@0: array $headers = [], Chris@0: $body = null, Chris@0: $version = '1.1', Chris@0: $reason = null Chris@0: ) { Chris@17: if (filter_var($status, FILTER_VALIDATE_INT) === false) { Chris@17: throw new \InvalidArgumentException('Status code must be an integer value.'); Chris@17: } Chris@17: Chris@0: $this->statusCode = (int) $status; Chris@0: Chris@0: if ($body !== '' && $body !== null) { Chris@0: $this->stream = stream_for($body); Chris@0: } Chris@0: Chris@0: $this->setHeaders($headers); Chris@0: if ($reason == '' && isset(self::$phrases[$this->statusCode])) { Chris@0: $this->reasonPhrase = self::$phrases[$this->statusCode]; Chris@0: } else { Chris@0: $this->reasonPhrase = (string) $reason; Chris@0: } Chris@0: Chris@0: $this->protocol = $version; Chris@0: } Chris@0: Chris@0: public function getStatusCode() Chris@0: { Chris@0: return $this->statusCode; Chris@0: } Chris@0: Chris@0: public function getReasonPhrase() Chris@0: { Chris@0: return $this->reasonPhrase; Chris@0: } Chris@0: Chris@0: public function withStatus($code, $reasonPhrase = '') Chris@0: { Chris@0: $new = clone $this; Chris@0: $new->statusCode = (int) $code; Chris@0: if ($reasonPhrase == '' && isset(self::$phrases[$new->statusCode])) { Chris@0: $reasonPhrase = self::$phrases[$new->statusCode]; Chris@0: } Chris@0: $new->reasonPhrase = $reasonPhrase; Chris@0: return $new; Chris@0: } Chris@0: }