├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src ├── Contract └── Exception │ ├── Exception.php │ └── HttpException.php ├── Exception ├── AbstractClientErrorException.php ├── AbstractServerErrorException.php ├── BadGatewayException.php ├── BadRequestException.php ├── ConflictException.php ├── ExpectationFailedException.php ├── FailedDependencyException.php ├── ForbiddenException.php ├── GatewayTimeoutException.php ├── GoneException.php ├── HttpVersionNotSupportedException.php ├── ImATeapotException.php ├── InsufficientStorageException.php ├── InternalServerErrorException.php ├── InvalidArgumentException.php ├── LengthRequiredException.php ├── LockedException.php ├── LoopDetectedException.php ├── MethodNotAllowedException.php ├── MisdirectedRequestException.php ├── NetworkAuthenticationRequiredException.php ├── NotAcceptableException.php ├── NotExtendedException.php ├── NotFoundException.php ├── NotImplementedException.php ├── OutOfBoundsException.php ├── PayloadTooLargeException.php ├── PaymentRequiredException.php ├── PreconditionFailedException.php ├── PreconditionRequiredException.php ├── ProxyAuthenticationRequiredException.php ├── RequestHeaderFieldsTooLargeException.php ├── RequestTimeoutException.php ├── RequestUriTooLongException.php ├── RequestedRangeNotSatisfiableException.php ├── ServiceUnavailableException.php ├── TooEarlyException.php ├── TooManyRequestsException.php ├── UnauthorizedException.php ├── UnavailableForLegalReasonsException.php ├── UnprocessableEntityException.php ├── UnsupportedMediaTypeException.php ├── UpgradeRequiredException.php └── VariantAlsoNegotiatesException.php └── HttpStatus.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## NEXT - 2018-31-07 2 | 3 | ### Added 4 | - upgraded the php version to v7.2 5 | - added new status code 425 (Too Early) 6 | 7 | ### Deprecated 8 | - Nothing 9 | 10 | ### Fixed 11 | - Nothing 12 | 13 | ### Removed 14 | - Nothing 15 | 16 | ### Security 17 | - Nothing 18 | 19 | ## NEXT - 2017-08-09 20 | 21 | ### Added 22 | - fixes #23 Add header functions to exceptions 23 | - new HttpException Interface for better exception catching 24 | - added new getStatusCode function to get the http status code 25 | 26 | ### Deprecated 27 | - Nothing 28 | 29 | ### Fixed 30 | - getCode returns now the exception code and not the http status code 31 | 32 | ### Removed 33 | - duplicated tests 34 | 35 | ### Security 36 | - Nothing 37 | 38 | ## NEXT - 2017-02-20 39 | 40 | ### Added 41 | - MisdirectedRequestException, the error code 421 and the status message. 42 | - Support for [http-message-util](//github.com/php-fig/http-message-util) 43 | - Tests against iana.org 44 | 45 | ### Deprecated 46 | - Nothing 47 | 48 | ### Fixed 49 | - Nothing 50 | 51 | ### Removed 52 | - Support for php 5.6 and hhvm 53 | 54 | ### Security 55 | - Nothing 56 | 57 | ## NEXT - 2016-06-22 58 | 59 | ### Added 60 | - HttpStatus::getReasonMessage | returns the status message. 61 | 62 | ### Deprecated 63 | - Nothing 64 | 65 | ### Fixed 66 | - Nothing 67 | 68 | ### Removed 69 | - Nothing 70 | 71 | ### Security 72 | - Nothing 73 | 74 | ## NEXT - 2016-06-01 75 | 76 | ### Added 77 | - HttpStatus::getReasonPhrase | return the status text. 78 | 79 | ### Deprecated 80 | - Nothing 81 | 82 | ### Fixed 83 | - Nothing 84 | 85 | ### Removed 86 | - Nothing 87 | 88 | ### Security 89 | - Nothing 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Narrowspark 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Http Status

2 |

A package for working with HTTP statuses.

3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 |

11 | 12 | Installation 13 | ------------ 14 | 15 | Via Composer 16 | 17 | ```bash 18 | $ composer require narrowspark/http-status 19 | ``` 20 | 21 | Use 22 | ------------ 23 | 24 | ``` php 25 | use Narrowspark\HttpStatus\Contract\Exception\HttpException as HttpExceptionContract; 26 | use Narrowspark\HttpStatus\HttpStatus; 27 | 28 | // get status message from code 29 | echo HttpStatus::getReasonMessage(301); // This and all future requests should be directed to the given URI. 30 | 31 | try { 32 | HttpStatus::getReasonException(301): 33 | } catch(HttpExceptionContract $e) { 34 | echo $e->getMessage(); // 301 Moved Permanently 35 | echo $e->getStatusCode(); // 301 36 | } 37 | ``` 38 | 39 | ### Now we have support for ([http-message-util](//github.com/php-fig/http-message-util)) so you can do something like this: 40 | 41 | ``` php 42 | use Narrowspark\HttpStatus\HttpStatus; 43 | 44 | // get status name from code 45 | echo HttpStatus::getReasonPhrase(HttpStatus::STATUS_MOVED_PERMANENTLY); // Moved Permanently 46 | ``` 47 | 48 | ## HTTP status code classes ([from RFC7231](//tools.ietf.org/html/rfc7231#section-6)) 49 | The first digit of the status-code defines the class of response. 50 | The last two digits do not have any categorization role. There are five values for the first digit: 51 | 52 | Digit | Category | Meaning 53 | ------------- | ------------- | ------------- 54 | 1xx | Informational | The request was received, continuing process 55 | 2xx | Successful | The request was successfully received, understood, and accepted 56 | 3xx | Redirection | Further action needs to be taken in order to complete the request 57 | 4xx | Client Error | The request contains bad syntax or cannot be fulfilled 58 | 5xx | Server Error | The server failed to fulfill an apparently valid request 59 | 60 | 61 | ## Available HTTP status codes 62 | Code | Message | RFC 63 | ------------- | ------------- | ------------- 64 | 100 | Continue | [RFC7231, Section 6.2.1] 65 | 101 | Switching Protocols | [RFC7231, Section 6.2.2] 66 | 102 | Processing | [RFC2518] 67 | 103 | Http Early Hints | [RFC8297] 68 | 104-199 | *Unassigned* | 69 | 200 | OK | [RFC7231, Section 6.3.1] 70 | 201 | Created | [RFC7231, Section 6.3.2] 71 | 202 | Accepted | [RFC7231, Section 6.3.3] 72 | 203 | Non-Authoritative Information | [RFC7231, Section 6.3.4] 73 | 204 | No Content | [RFC7231, Section 6.3.5] 74 | 205 | Reset Content | [RFC7231, Section 6.3.6] 75 | 206 | Partial Content | [RFC7233, Section 4.1] 76 | 207 | Multi-Status | [RFC4918] 77 | 208 | Already Reported | [RFC5842] 78 | 209-225 | *Unassigned* | 79 | 226 | IM Used | [RFC3229] 80 | 227-299 | *Unassigned* | 81 | 300 | Multiple Choices | [RFC7231, Section 6.4.1] 82 | 301 | Moved Permanently | [RFC7231, Section 6.4.2] 83 | 302 | Found | [RFC7231, Section 6.4.3] 84 | 303 | See Other | [RFC7231, Section 6.4.4] 85 | 304 | Not Modified | [RFC7232, Section 4.1] 86 | 305 | Use Proxy | [RFC7231, Section 6.4.5] 87 | 306 | (Unused) | [RFC7231, Section 6.4.6] 88 | 307 | Temporary Redirect | [RFC7231, Section 6.4.7] 89 | 308 | Permanent Redirect | [RFC7538] 90 | 309-399 | *Unassigned* | 91 | 400 | Bad Request | [RFC7231, Section 6.5.1] 92 | 401 | Unauthorized | [RFC7235, Section 3.1] 93 | 402 | Payment Required | [RFC7231, Section 6.5.2] 94 | 403 | Forbidden | [RFC7231, Section 6.5.3] 95 | 404 | Not Found | [RFC7231, Section 6.5.4] 96 | 405 | Method Not Allowed | [RFC7231, Section 6.5.5] 97 | 406 | Not Acceptable | [RFC7231, Section 6.5.6] 98 | 407 | Proxy Authentication Required | [RFC7235, Section 3.2] 99 | 408 | Request Timeout | [RFC7231, Section 6.5.7] 100 | 409 | Conflict | [RFC7231, Section 6.5.8] 101 | 410 | Gone | [RFC7231, Section 6.5.9] 102 | 411 | Length Required | [RFC7231, Section 6.5.10] 103 | 412 | Precondition Failed | [RFC7232, Section 4.2] 104 | 413 | Payload Too Large | [RFC7231, Section 6.5.11] 105 | 414 | URI Too Long | [RFC7231, Section 6.5.12] 106 | 415 | Unsupported Media Type | [RFC7231, Section 6.5.13] 107 | 416 | Range Not Satisfiable | [RFC7233, Section 4.4] 108 | 417 | Expectation Failed | [RFC7231, Section 6.5.14] 109 | 418-420 | *Unassigned* | 110 | 421 | Misdirected Request | [RFC7540, Section 9.1.2] 111 | 422 | Unprocessable Entity | [RFC4918] 112 | 423 | Locked | [RFC4918] 113 | 424 | Failed Dependency | [RFC4918] 114 | 425 | Too Early | [RFC-ietf-httpbis-replay-04] 115 | 426 | Upgrade Required | [RFC7231, Section 6.5.15] 116 | 427 | *Unassigned* | 117 | 428 | Precondition Required | [RFC6585] 118 | 429 | Too Many Requests | [RFC6585] 119 | 430 | *Unassigned* | 120 | 431 | Request Header Fields Too Large | [RFC6585] 121 | 432-450 | *Unassigned* | 122 | 451 | Unavailable For Legal | [RFC7725] 123 | 452-499 | *Unassigned* | 124 | 500 | Internal Server Error | [RFC7231, Section 6.6.1] 125 | 501 | Not Implemented | [RFC7231, Section 6.6.2] 126 | 502 | Bad Gateway | [RFC7231, Section 6.6.3] 127 | 503 | Service Unavailable | [RFC7231, Section 6.6.4] 128 | 504 | Gateway Timeout | [RFC7231, Section 6.6.5] 129 | 505 | HTTP Version Not Supported | [RFC7231, Section 6.6.6] 130 | 506 | Variant Also Negotiates | [RFC2295] 131 | 507 | Insufficient Storage | [RFC4918] 132 | 508 | Loop Detected | [RFC5842] 133 | 509 | *Unassigned* | 134 | 510 | Not Extended | [RFC2774] 135 | 511 | Network Authentication Required | [RFC6585] 136 | 512-599 | *Unassigned* | 137 | 138 | Change log 139 | ------------ 140 | 141 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. 142 | 143 | Testing 144 | ------------ 145 | 146 | ``` bash 147 | $ vendor/bin/phpunit 148 | ``` 149 | 150 | Contributing 151 | ------------ 152 | 153 | If you would like to help take a look at the [list of issues](http://github.com/narrowspark/http-emitter/issues) and check our [Contributing](CONTRIBUTING.md) guild. 154 | 155 | > **Note:** Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. 156 | 157 | 158 | License 159 | --------------- 160 | 161 | The Narrowspark http-emitter is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 162 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "narrowspark/http-status", 3 | "type": "library", 4 | "description": "A psr-7 package for working with HTTP statuses.", 5 | "keywords": [ 6 | "psr-7", 7 | "psr7", 8 | "http", 9 | "status", 10 | "http-status", 11 | "http-status exceptions", 12 | "exception" 13 | ], 14 | "homepage": "https://github.com/narrowspark/http-status", 15 | "license": "MIT", 16 | "authors": [ 17 | { 18 | "name": "Daniel Bannert", 19 | "email": "d.bannert@anolilab.de", 20 | "homepage": "http://anolilab.de", 21 | "role": "Developer" 22 | } 23 | ], 24 | "require": { 25 | "php": "^7.2", 26 | "fig/http-message-util": "^1.1.3" 27 | }, 28 | "provide": { 29 | "psr/http-message-implementation": "^1.0" 30 | }, 31 | "require-dev": { 32 | "narrowspark/coding-standard": "^3.0.0", 33 | "phpunit/phpunit": "^8.4.1" 34 | }, 35 | "config": { 36 | "optimize-autoloader": true, 37 | "preferred-install": "dist" 38 | }, 39 | "extra": { 40 | "branch-alias": { 41 | "dev-master": "5.0-dev" 42 | } 43 | }, 44 | "autoload": { 45 | "psr-4": { 46 | "Narrowspark\\HttpStatus\\": "src/" 47 | }, 48 | "exclude-from-classmap": [ 49 | "/tests/" 50 | ] 51 | }, 52 | "autoload-dev": { 53 | "psr-4": { 54 | "Narrowspark\\HttpStatus\\Tests\\": "tests/" 55 | } 56 | }, 57 | "minimum-stability": "dev", 58 | "prefer-stable": true, 59 | "scripts": { 60 | "coverage": "phpunit --coverage-html=\"build/logs\"", 61 | "cs": "php-cs-fixer fix", 62 | "phpstan": "phpstan analyse -c phpstan.neon src --memory-limit=-1", 63 | "test": "phpunit", 64 | "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend" 65 | }, 66 | "support": { 67 | "issues": "https://github.com/narrowspark/http-status/issues", 68 | "source": "https://github.com/narrowspark/http-status" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Contract/Exception/Exception.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Contract\Exception; 15 | 16 | interface Exception extends \Throwable 17 | { 18 | } 19 | -------------------------------------------------------------------------------- /src/Contract/Exception/HttpException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Contract\Exception; 15 | 16 | interface HttpException extends Exception 17 | { 18 | /** 19 | * Returns the status code. 20 | * 21 | * @return int An HTTP response status code 22 | */ 23 | public function getStatusCode(): int; 24 | 25 | /** 26 | * Returns response headers. 27 | * 28 | * @return string[] Response headers 29 | */ 30 | public function getHeaders(): array; 31 | } 32 | -------------------------------------------------------------------------------- /src/Exception/AbstractClientErrorException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | use Narrowspark\HttpStatus\Contract\Exception\HttpException as HttpExceptionContract; 17 | use RuntimeException as BaseRuntimeException; 18 | use Throwable; 19 | 20 | abstract class AbstractClientErrorException extends BaseRuntimeException implements HttpExceptionContract 21 | { 22 | /** @var string */ 23 | protected $message = 'Client Error 4xx'; 24 | 25 | /** @var int */ 26 | protected $statusCode = 4; 27 | 28 | /** @var array */ 29 | private $headers; 30 | 31 | /** 32 | * Create a new Exception. 33 | * 34 | * @param null|string $message 35 | * @param null|\Throwable $previous 36 | * @param array $headers 37 | * @param int $code 38 | */ 39 | public function __construct(string $message = null, Throwable $previous = null, array $headers = [], int $code = 0) 40 | { 41 | $this->headers = $headers; 42 | $message = $message ?? $this->message; 43 | 44 | parent::__construct($message, $code, $previous); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function getStatusCode(): int 51 | { 52 | return $this->statusCode; 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | * 58 | * @codeCoverageIgnore 59 | */ 60 | public function getHeaders(): array 61 | { 62 | return $this->headers; 63 | } 64 | 65 | /** 66 | * Set response headers. 67 | * 68 | * @param string[] $headers Response headers 69 | * 70 | * @return void 71 | * 72 | * @codeCoverageIgnore 73 | */ 74 | public function setHeaders(array $headers): void 75 | { 76 | $this->headers = $headers; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Exception/AbstractServerErrorException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | use Narrowspark\HttpStatus\Contract\Exception\HttpException as HttpExceptionContract; 17 | use RuntimeException as BaseRuntimeException; 18 | use Throwable; 19 | 20 | abstract class AbstractServerErrorException extends BaseRuntimeException implements HttpExceptionContract 21 | { 22 | /** @var string */ 23 | protected $message = 'Server Error 5xx'; 24 | 25 | /** @var int */ 26 | protected $statusCode = 5; 27 | 28 | /** @var array */ 29 | private $headers; 30 | 31 | /** 32 | * Create a new Exception. 33 | * 34 | * @param null|string $message 35 | * @param null|\Throwable $previous 36 | * @param array $headers 37 | * @param int $code 38 | */ 39 | public function __construct(string $message = null, Throwable $previous = null, array $headers = [], int $code = 0) 40 | { 41 | $this->headers = $headers; 42 | $message = $message ?? $this->message; 43 | 44 | parent::__construct($message, $code, $previous); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function getStatusCode(): int 51 | { 52 | return $this->statusCode; 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | * 58 | * @codeCoverageIgnore 59 | */ 60 | public function getHeaders(): array 61 | { 62 | return $this->headers; 63 | } 64 | 65 | /** 66 | * Set response headers. 67 | * 68 | * @param string[] $headers Response headers 69 | * 70 | * @return void 71 | * 72 | * @codeCoverageIgnore 73 | */ 74 | public function setHeaders(array $headers): void 75 | { 76 | $this->headers = $headers; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Exception/BadGatewayException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class BadGatewayException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '502 Bad Gateway'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 502; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/BadRequestException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class BadRequestException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '400 Bad Request'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 400; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/ConflictException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class ConflictException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '409 Conflict'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 409; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/ExpectationFailedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class ExpectationFailedException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '417 Expectation Failed'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 417; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/FailedDependencyException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class FailedDependencyException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '424 Failed Dependency'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 424; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/ForbiddenException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class ForbiddenException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '403 Forbidden'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 403; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/GatewayTimeoutException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class GatewayTimeoutException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '504 Gateway Timeout'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 504; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/GoneException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class GoneException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '410 Gone'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 410; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/HttpVersionNotSupportedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class HttpVersionNotSupportedException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '505 HTTP Version Not Supported'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 505; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/ImATeapotException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class ImATeapotException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '418 I\'m a teapot'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 418; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/InsufficientStorageException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class InsufficientStorageException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '507 Insufficient Storage'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 507; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/InternalServerErrorException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class InternalServerErrorException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '500 Internal Server Error'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 500; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/InvalidArgumentException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | use InvalidArgumentException as BaseInvalidArgumentException; 17 | use Narrowspark\HttpStatus\Contract\Exception\Exception as ExceptionContract; 18 | 19 | class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionContract 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Exception/LengthRequiredException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class LengthRequiredException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '411 Length Required'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 411; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/LockedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class LockedException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '423 Locked'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 423; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/LoopDetectedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class LoopDetectedException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '508 Loop Detected'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 508; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/MethodNotAllowedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class MethodNotAllowedException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '405 Method Not Allowed'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 405; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/MisdirectedRequestException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class MisdirectedRequestException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '421 Misdirected Request'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 421; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/NetworkAuthenticationRequiredException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class NetworkAuthenticationRequiredException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '511 Network Authentication Required'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 511; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/NotAcceptableException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class NotAcceptableException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '406 Not Acceptable'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 406; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/NotExtendedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class NotExtendedException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '510 Not Extended'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 510; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/NotFoundException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class NotFoundException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '404 Not Found'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 404; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/NotImplementedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class NotImplementedException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '501 Not Implemented'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 501; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/OutOfBoundsException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | use Narrowspark\HttpStatus\Contract\Exception\Exception as ExceptionContract; 17 | use OutOfBoundsException as BaseOutOfBoundsException; 18 | 19 | class OutOfBoundsException extends BaseOutOfBoundsException implements ExceptionContract 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /src/Exception/PayloadTooLargeException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class PayloadTooLargeException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '413 Payload Too Large'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 413; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/PaymentRequiredException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class PaymentRequiredException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '402 Payment Required'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 402; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/PreconditionFailedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class PreconditionFailedException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '412 Precondition Failed'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 412; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/PreconditionRequiredException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class PreconditionRequiredException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '428 Precondition Required'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 428; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/ProxyAuthenticationRequiredException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class ProxyAuthenticationRequiredException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '407 Proxy Authentication Required'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 407; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/RequestHeaderFieldsTooLargeException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class RequestHeaderFieldsTooLargeException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '431 Request Header Fields Too Large'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 431; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/RequestTimeoutException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class RequestTimeoutException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '408 Request Timeout'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 408; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/RequestUriTooLongException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class RequestUriTooLongException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '414 URI Too Long'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 414; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/RequestedRangeNotSatisfiableException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class RequestedRangeNotSatisfiableException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '416 Range Not Satisfiable'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 416; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/ServiceUnavailableException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class ServiceUnavailableException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '503 Service Unavailable'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 503; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/TooEarlyException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class TooEarlyException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '425 Too Early'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 425; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/TooManyRequestsException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class TooManyRequestsException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '429 Too Many Requests'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 429; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/UnauthorizedException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class UnauthorizedException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '401 Unauthorized'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 401; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/UnavailableForLegalReasonsException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class UnavailableForLegalReasonsException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '451 Unavailable For Legal Reasons'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 451; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/UnprocessableEntityException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class UnprocessableEntityException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '422 Unprocessable Entity'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 422; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/UnsupportedMediaTypeException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class UnsupportedMediaTypeException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '415 Unsupported Media Type'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 415; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/UpgradeRequiredException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class UpgradeRequiredException extends AbstractClientErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '426 Upgrade Required'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 426; 23 | } 24 | -------------------------------------------------------------------------------- /src/Exception/VariantAlsoNegotiatesException.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus\Exception; 15 | 16 | class VariantAlsoNegotiatesException extends AbstractServerErrorException 17 | { 18 | /** @var string */ 19 | protected $message = '506 Variant Also Negotiates'; 20 | 21 | /** @var int */ 22 | protected $statusCode = 506; 23 | } 24 | -------------------------------------------------------------------------------- /src/HttpStatus.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * This source file is subject to the MIT license that is bundled 11 | * with this source code in the file LICENSE. 12 | */ 13 | 14 | namespace Narrowspark\HttpStatus; 15 | 16 | use Fig\Http\Message\StatusCodeInterface; 17 | use Narrowspark\HttpStatus\Exception\BadGatewayException; 18 | use Narrowspark\HttpStatus\Exception\BadRequestException; 19 | use Narrowspark\HttpStatus\Exception\ConflictException; 20 | use Narrowspark\HttpStatus\Exception\ExpectationFailedException; 21 | use Narrowspark\HttpStatus\Exception\FailedDependencyException; 22 | use Narrowspark\HttpStatus\Exception\ForbiddenException; 23 | use Narrowspark\HttpStatus\Exception\GatewayTimeoutException; 24 | use Narrowspark\HttpStatus\Exception\GoneException; 25 | use Narrowspark\HttpStatus\Exception\HttpVersionNotSupportedException; 26 | use Narrowspark\HttpStatus\Exception\ImATeapotException; 27 | use Narrowspark\HttpStatus\Exception\InsufficientStorageException; 28 | use Narrowspark\HttpStatus\Exception\InternalServerErrorException; 29 | use Narrowspark\HttpStatus\Exception\InvalidArgumentException; 30 | use Narrowspark\HttpStatus\Exception\LengthRequiredException; 31 | use Narrowspark\HttpStatus\Exception\LockedException; 32 | use Narrowspark\HttpStatus\Exception\LoopDetectedException; 33 | use Narrowspark\HttpStatus\Exception\MethodNotAllowedException; 34 | use Narrowspark\HttpStatus\Exception\MisdirectedRequestException; 35 | use Narrowspark\HttpStatus\Exception\NetworkAuthenticationRequiredException; 36 | use Narrowspark\HttpStatus\Exception\NotAcceptableException; 37 | use Narrowspark\HttpStatus\Exception\NotExtendedException; 38 | use Narrowspark\HttpStatus\Exception\NotFoundException; 39 | use Narrowspark\HttpStatus\Exception\NotImplementedException; 40 | use Narrowspark\HttpStatus\Exception\OutOfBoundsException; 41 | use Narrowspark\HttpStatus\Exception\PayloadTooLargeException; 42 | use Narrowspark\HttpStatus\Exception\PaymentRequiredException; 43 | use Narrowspark\HttpStatus\Exception\PreconditionFailedException; 44 | use Narrowspark\HttpStatus\Exception\PreconditionRequiredException; 45 | use Narrowspark\HttpStatus\Exception\ProxyAuthenticationRequiredException; 46 | use Narrowspark\HttpStatus\Exception\RequestedRangeNotSatisfiableException; 47 | use Narrowspark\HttpStatus\Exception\RequestHeaderFieldsTooLargeException; 48 | use Narrowspark\HttpStatus\Exception\RequestTimeoutException; 49 | use Narrowspark\HttpStatus\Exception\RequestUriTooLongException; 50 | use Narrowspark\HttpStatus\Exception\ServiceUnavailableException; 51 | use Narrowspark\HttpStatus\Exception\TooEarlyException; 52 | use Narrowspark\HttpStatus\Exception\TooManyRequestsException; 53 | use Narrowspark\HttpStatus\Exception\UnauthorizedException; 54 | use Narrowspark\HttpStatus\Exception\UnavailableForLegalReasonsException; 55 | use Narrowspark\HttpStatus\Exception\UnprocessableEntityException; 56 | use Narrowspark\HttpStatus\Exception\UnsupportedMediaTypeException; 57 | use Narrowspark\HttpStatus\Exception\UpgradeRequiredException; 58 | use Narrowspark\HttpStatus\Exception\VariantAlsoNegotiatesException; 59 | 60 | class HttpStatus implements StatusCodeInterface 61 | { 62 | /** 63 | * Allowed range for a valid HTTP status code. 64 | */ 65 | public const MINIMUM = 100; 66 | public const MAXIMUM = 599; 67 | 68 | /** 69 | * Array of standard HTTP status code/reason phrases. 70 | * 71 | * @var array 72 | */ 73 | private static $statusNames = [ 74 | // Informational 1xx 75 | 100 => 'Continue', 76 | 101 => 'Switching Protocols', 77 | 102 => 'Processing', 78 | 103 => 'Early Hints', 79 | // Successful 2xx 80 | 200 => 'OK', 81 | 201 => 'Created', 82 | 202 => 'Accepted', 83 | 203 => 'Non-Authoritative Information', 84 | 204 => 'No Content', 85 | 205 => 'Reset Content', 86 | 206 => 'Partial Content', 87 | 207 => 'Multi-Status', 88 | 208 => 'Already Reported', 89 | 226 => 'IM Used', 90 | // Redirection 3xx 91 | 300 => 'Multiple Choices', 92 | 301 => 'Moved Permanently', 93 | 302 => 'Found', 94 | 303 => 'See Other', 95 | 304 => 'Not Modified', 96 | 305 => 'Use Proxy', 97 | 306 => '(Unused)', 98 | 307 => 'Temporary Redirect', 99 | 308 => 'Permanent Redirect', 100 | // Client Error 4xx 101 | 400 => 'Bad Request', 102 | 401 => 'Unauthorized', 103 | 402 => 'Payment Required', 104 | 403 => 'Forbidden', 105 | 404 => 'Not Found', 106 | 405 => 'Method Not Allowed', 107 | 406 => 'Not Acceptable', 108 | 407 => 'Proxy Authentication Required', 109 | 408 => 'Request Timeout', 110 | 409 => 'Conflict', 111 | 410 => 'Gone', 112 | 411 => 'Length Required', 113 | 412 => 'Precondition Failed', 114 | 413 => 'Payload Too Large', 115 | 414 => 'URI Too Long', 116 | 415 => 'Unsupported Media Type', 117 | 416 => 'Range Not Satisfiable', 118 | 417 => 'Expectation Failed', 119 | 418 => 'I\'m a teapot', 120 | 421 => 'Misdirected Request', 121 | 422 => 'Unprocessable Entity', 122 | 423 => 'Locked', 123 | 424 => 'Failed Dependency', 124 | 425 => 'Too Early', 125 | 426 => 'Upgrade Required', 126 | 428 => 'Precondition Required', 127 | 429 => 'Too Many Requests', 128 | 431 => 'Request Header Fields Too Large', 129 | 451 => 'Unavailable For Legal Reasons', 130 | // Server Error 5xx 131 | 500 => 'Internal Server Error', 132 | 501 => 'Not Implemented', 133 | 502 => 'Bad Gateway', 134 | 503 => 'Service Unavailable', 135 | 504 => 'Gateway Timeout', 136 | 505 => 'HTTP Version Not Supported', 137 | 506 => 'Variant Also Negotiates', 138 | 507 => 'Insufficient Storage', 139 | 508 => 'Loop Detected', 140 | 510 => 'Not Extended', 141 | 511 => 'Network Authentication Required', 142 | ]; 143 | 144 | /** 145 | * Array of standard HTTP status code/reason phrases. 146 | * 147 | * @var array 148 | */ 149 | private static $errorPhrases = [ 150 | // Successful 2xx 151 | 200 => 'Standard response for successful HTTP requests.', 152 | 201 => 'The request has been fulfilled, resulting in the creation of a new resource.', 153 | 202 => 'The request has been accepted for processing, but the processing has not been completed.', 154 | 203 => 'The server is a transforming proxy (e.g. a Web accelerator) that received a 200 OK from its origin, but is returning a modified version of the origin\'s response.', 155 | 204 => 'The server successfully processed the request and is not returning any content.', 156 | 205 => 'The server successfully processed the request, but is not returning any content.', 157 | 206 => 'The server is delivering only part of the resource (byte serving) due to a range header sent by the client.', 158 | 207 => 'The message body that follows is an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.', 159 | 208 => 'The members of a DAV binding have already been enumerated in a previous reply to this request, and are not being included again.', 160 | 226 => 'The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.', 161 | // Redirection 3xx 162 | 300 => 'Indicates multiple options for the resource from which the client may choose.', 163 | 301 => 'This and all future requests should be directed to the given URI.', 164 | 302 => 'This is an example of industry practice contradicting the standard.', 165 | 303 => 'The response to the request can be found under another URI using a GET method.', 166 | 304 => 'Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.', 167 | 305 => 'The requested resource is available only through a proxy, the address for which is provided in the response.', 168 | 306 => 'No longer used.', 169 | 307 => 'In this case, the request should be repeated with another URI; however, future requests should still use the original URI.', 170 | 308 => 'The request and all future requests should be repeated using another URI.', 171 | // Client Error 4xx 172 | 400 => 'The request cannot be fulfilled due to bad syntax.', 173 | 401 => 'Authentication is required and has failed or has not yet been provided.', 174 | 402 => 'Reserved for future use.', 175 | 403 => 'The request was a valid request, but the server is refusing to respond to it.', 176 | 404 => 'The requested resource could not be found but may be available again in the future.', 177 | 405 => 'A request was made of a resource using a request method not supported by that resource.', 178 | 406 => 'The requested resource is only capable of generating content not acceptable.', 179 | 407 => 'Proxy authentication is required to access the requested resource.', 180 | 408 => 'The server did not receive a complete request message in time.', 181 | 409 => 'The request could not be processed because of conflict in the request.', 182 | 410 => 'The requested resource is no longer available and will not be available again.', 183 | 411 => 'The request did not specify the length of its content, which is required by the resource.', 184 | 412 => 'The server does not meet one of the preconditions that the requester put on the request.', 185 | 413 => 'The server cannot process the request because the request payload is too large.', 186 | 414 => 'The request-target is longer than the server is willing to interpret.', 187 | 415 => 'The request entity has a media type which the server or resource does not support.', 188 | 416 => 'The client has asked for a portion of the file, but the server cannot supply that portion.', 189 | 417 => 'The expectation given could not be met by at least one of the inbound servers.', 190 | 418 => 'I\'m a teapot', 191 | 421 => 'The request was directed at a server that is not able to produce a response.', 192 | 422 => 'The request was well-formed but was unable to be followed due to semantic errors.', 193 | 423 => 'The resource that is being accessed is locked.', 194 | 424 => 'The request failed due to failure of a previous request.', 195 | 425 => 'The server is unwilling to risk processing a request that might be replayed.', 196 | 426 => 'The server cannot process the request using the current protocol.', 197 | 428 => 'The origin server requires the request to be conditional.', 198 | 429 => 'The user has sent too many requests in a given amount of time.', 199 | 431 => 'The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large.', 200 | 451 => 'Resource access is denied for legal reasons.', 201 | // Server Error 5xx 202 | 500 => 'An error has occurred and this resource cannot be displayed.', 203 | 501 => 'The server either does not recognize the request method, or it lacks the ability to fulfil the request.', 204 | 502 => 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.', 205 | 503 => 'The server is currently unavailable. It may be overloaded or down for maintenance.', 206 | 504 => 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.', 207 | 505 => 'The server does not support the HTTP protocol version used in the request.', 208 | 506 => 'Transparent content negotiation for the request, results in a circular reference.', 209 | 507 => 'The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. There is insufficient free space left in your storage allocation.', 210 | 508 => 'The server detected an infinite loop while processing the request.', 211 | 510 => 'Further extensions to the request are required for the server to fulfill it.A mandatory extension policy in the request is not accepted by the server for this resource.', 212 | 511 => 'The client needs to authenticate to gain network access.', 213 | ]; 214 | 215 | /** 216 | * Array of standard HTTP status code/reason exceptions. 217 | * 218 | * @var array 219 | */ 220 | private static $phrasesExceptions = [ 221 | 400 => BadRequestException::class, 222 | 401 => UnauthorizedException::class, 223 | 402 => PaymentRequiredException::class, 224 | 403 => ForbiddenException::class, 225 | 404 => NotFoundException::class, 226 | 405 => MethodNotAllowedException::class, 227 | 406 => NotAcceptableException::class, 228 | 407 => ProxyAuthenticationRequiredException::class, 229 | 408 => RequestTimeoutException::class, 230 | 409 => ConflictException::class, 231 | 410 => GoneException::class, 232 | 411 => LengthRequiredException::class, 233 | 412 => PreconditionFailedException::class, 234 | 413 => PayloadTooLargeException::class, 235 | 414 => RequestUriTooLongException::class, 236 | 415 => UnsupportedMediaTypeException::class, 237 | 416 => RequestedRangeNotSatisfiableException::class, 238 | 417 => ExpectationFailedException::class, 239 | 418 => ImATeapotException::class, 240 | 421 => MisdirectedRequestException::class, 241 | 422 => UnprocessableEntityException::class, 242 | 423 => LockedException::class, 243 | 424 => FailedDependencyException::class, 244 | 425 => TooEarlyException::class, 245 | 426 => UpgradeRequiredException::class, 246 | 428 => PreconditionRequiredException::class, 247 | 429 => TooManyRequestsException::class, 248 | 431 => RequestHeaderFieldsTooLargeException::class, 249 | 451 => UnavailableForLegalReasonsException::class, 250 | 500 => InternalServerErrorException::class, 251 | 501 => NotImplementedException::class, 252 | 502 => BadGatewayException::class, 253 | 503 => ServiceUnavailableException::class, 254 | 504 => GatewayTimeoutException::class, 255 | 505 => HttpVersionNotSupportedException::class, 256 | 506 => VariantAlsoNegotiatesException::class, 257 | 507 => InsufficientStorageException::class, 258 | 508 => LoopDetectedException::class, 259 | 510 => NotExtendedException::class, 260 | 511 => NetworkAuthenticationRequiredException::class, 261 | ]; 262 | 263 | /** 264 | * Private constructor; non-instantiable. 265 | * 266 | * @codeCoverageIgnore 267 | */ 268 | private function __construct() 269 | { 270 | } 271 | 272 | /** 273 | * Get the message for a given status code. 274 | * 275 | * @param int $code http status code 276 | * 277 | * @throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException If the requested $code is not valid 278 | * @throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException If the requested $code is not found 279 | * 280 | * @return string Returns message for the given status code 281 | */ 282 | public static function getReasonMessage(int $code): string 283 | { 284 | $code = static::filterStatusCode($code); 285 | 286 | if (! isset(self::$errorPhrases[$code])) { 287 | throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); 288 | } 289 | 290 | return self::$errorPhrases[$code]; 291 | } 292 | 293 | /** 294 | * Get the name for a given status code. 295 | * 296 | * @param int $code http status code 297 | * 298 | * @throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException If the requested $code is not valid 299 | * @throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException If the requested $code is not found 300 | * 301 | * @return string Returns name for the given status code 302 | */ 303 | public static function getReasonPhrase(int $code): string 304 | { 305 | $code = static::filterStatusCode($code); 306 | 307 | if (! isset(self::$statusNames[$code])) { 308 | throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); 309 | } 310 | 311 | return self::$statusNames[$code]; 312 | } 313 | 314 | /** 315 | * Get the text for a given status code. 316 | * 317 | * @param int $code http status code 318 | * 319 | * @throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException 320 | * @throws \Narrowspark\HttpStatus\Exception\BadGatewayException 321 | * @throws \Narrowspark\HttpStatus\Exception\BadRequestException 322 | * @throws \Narrowspark\HttpStatus\Exception\ConflictException 323 | * @throws \Narrowspark\HttpStatus\Exception\ExpectationFailedException 324 | * @throws \Narrowspark\HttpStatus\Exception\FailedDependencyException 325 | * @throws \Narrowspark\HttpStatus\Exception\ForbiddenException 326 | * @throws \Narrowspark\HttpStatus\Exception\GatewayTimeoutException 327 | * @throws \Narrowspark\HttpStatus\Exception\GoneException 328 | * @throws \Narrowspark\HttpStatus\Exception\HttpVersionNotSupportedException 329 | * @throws \Narrowspark\HttpStatus\Exception\ImATeapotException 330 | * @throws \Narrowspark\HttpStatus\Exception\InsufficientStorageException 331 | * @throws \Narrowspark\HttpStatus\Exception\InternalServerErrorException 332 | * @throws \Narrowspark\HttpStatus\Exception\LengthRequiredException 333 | * @throws \Narrowspark\HttpStatus\Exception\LockedException 334 | * @throws \Narrowspark\HttpStatus\Exception\LoopDetectedException 335 | * @throws \Narrowspark\HttpStatus\Exception\MethodNotAllowedException 336 | * @throws \Narrowspark\HttpStatus\Exception\NetworkAuthenticationRequiredException 337 | * @throws \Narrowspark\HttpStatus\Exception\NotAcceptableException 338 | * @throws \Narrowspark\HttpStatus\Exception\NotExtendedException 339 | * @throws \Narrowspark\HttpStatus\Exception\NotFoundException 340 | * @throws \Narrowspark\HttpStatus\Exception\NotImplementedException 341 | * @throws \Narrowspark\HttpStatus\Exception\PaymentRequiredException 342 | * @throws \Narrowspark\HttpStatus\Exception\PreconditionFailedException 343 | * @throws \Narrowspark\HttpStatus\Exception\PreconditionRequiredException 344 | * @throws \Narrowspark\HttpStatus\Exception\ProxyAuthenticationRequiredException 345 | * @throws \Narrowspark\HttpStatus\Exception\RequestedRangeNotSatisfiableException 346 | * @throws \Narrowspark\HttpStatus\Exception\RequestHeaderFieldsTooLargeException 347 | * @throws \Narrowspark\HttpStatus\Exception\RequestTimeoutException 348 | * @throws \Narrowspark\HttpStatus\Exception\RequestUriTooLongException 349 | * @throws \Narrowspark\HttpStatus\Exception\ServiceUnavailableException 350 | * @throws \Narrowspark\HttpStatus\Exception\TooEarlyException 351 | * @throws \Narrowspark\HttpStatus\Exception\TooManyRequestsException 352 | * @throws \Narrowspark\HttpStatus\Exception\UnauthorizedException 353 | * @throws \Narrowspark\HttpStatus\Exception\UnavailableForLegalReasonsException 354 | * @throws \Narrowspark\HttpStatus\Exception\UnprocessableEntityException 355 | * @throws \Narrowspark\HttpStatus\Exception\UnsupportedMediaTypeException 356 | * @throws \Narrowspark\HttpStatus\Exception\UpgradeRequiredException 357 | * @throws \Narrowspark\HttpStatus\Exception\VariantAlsoNegotiatesException 358 | * @throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException 359 | */ 360 | public static function getReasonException(int $code): void 361 | { 362 | $code = static::filterStatusCode($code); 363 | 364 | if (! isset(self::$statusNames[$code])) { 365 | throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); 366 | } 367 | 368 | if (isset(self::$phrasesExceptions[$code])) { 369 | throw new self::$phrasesExceptions[$code](); 370 | } 371 | } 372 | 373 | /** 374 | * Filter a HTTP Status code. 375 | * 376 | * @param int $code 377 | * 378 | * @throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException if the HTTP status code is invalid 379 | * 380 | * @return int 381 | */ 382 | public static function filterStatusCode(int $code): int 383 | { 384 | $filteredCode = \filter_var($code, \FILTER_VALIDATE_INT, ['options' => [ 385 | 'min_range' => self::MINIMUM, 386 | 'max_range' => self::MAXIMUM, 387 | ]]); 388 | 389 | if ($filteredCode === false) { 390 | throw new InvalidArgumentException(\sprintf('The submitted code "%s" must be a positive integer between %s and %s.', $code, self::MINIMUM, self::MAXIMUM)); 391 | } 392 | 393 | return $code; 394 | } 395 | } 396 | --------------------------------------------------------------------------------