├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json └── src ├── RequestMethodInterface.php └── StatusCodeInterface.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file, in reverse chronological order by release. 4 | 5 | ## 1.1.5 - 2020-11-24 6 | 7 | ### Added 8 | 9 | - [#19](https://github.com/php-fig/http-message-util/pull/19) adds support for PHP 8. 10 | 11 | ### Changed 12 | 13 | - Nothing. 14 | 15 | ### Deprecated 16 | 17 | - Nothing. 18 | 19 | ### Removed 20 | 21 | - Nothing. 22 | 23 | ### Fixed 24 | 25 | - Nothing. 26 | 27 | ## 1.1.4 - 2020-02-05 28 | 29 | ### Added 30 | 31 | - Nothing. 32 | 33 | ### Changed 34 | 35 | - Nothing. 36 | 37 | ### Deprecated 38 | 39 | - Nothing. 40 | 41 | ### Removed 42 | 43 | - [#15](https://github.com/php-fig/http-message-util/pull/15) removes the dependency on psr/http-message, as it is not technically necessary for usage of this package. 44 | 45 | ### Fixed 46 | 47 | - Nothing. 48 | 49 | ## 1.1.3 - 2018-11-19 50 | 51 | ### Added 52 | 53 | - [#10](https://github.com/php-fig/http-message-util/pull/10) adds the constants `StatusCodeInterface::STATUS_EARLY_HINTS` (103) and 54 | `StatusCodeInterface::STATUS_TOO_EARLY` (425). 55 | 56 | ### Changed 57 | 58 | - Nothing. 59 | 60 | ### Deprecated 61 | 62 | - Nothing. 63 | 64 | ### Removed 65 | 66 | - Nothing. 67 | 68 | ### Fixed 69 | 70 | - Nothing. 71 | 72 | ## 1.1.2 - 2017-02-09 73 | 74 | ### Added 75 | 76 | - [#4](https://github.com/php-fig/http-message-util/pull/4) adds the constant 77 | `StatusCodeInterface::STATUS_MISDIRECTED_REQUEST` (421). 78 | 79 | ### Deprecated 80 | 81 | - Nothing. 82 | 83 | ### Removed 84 | 85 | - Nothing. 86 | 87 | ### Fixed 88 | 89 | - Nothing. 90 | 91 | ## 1.1.1 - 2017-02-06 92 | 93 | ### Added 94 | 95 | - [#3](https://github.com/php-fig/http-message-util/pull/3) adds the constant 96 | `StatusCodeInterface::STATUS_IM_A_TEAPOT` (418). 97 | 98 | ### Deprecated 99 | 100 | - Nothing. 101 | 102 | ### Removed 103 | 104 | - Nothing. 105 | 106 | ### Fixed 107 | 108 | - Nothing. 109 | 110 | ## 1.1.0 - 2016-09-19 111 | 112 | ### Added 113 | 114 | - [#1](https://github.com/php-fig/http-message-util/pull/1) adds 115 | `Fig\Http\Message\StatusCodeInterface`, with constants named after common 116 | status reason phrases, with values indicating the status codes themselves. 117 | 118 | ### Deprecated 119 | 120 | - Nothing. 121 | 122 | ### Removed 123 | 124 | - Nothing. 125 | 126 | ### Fixed 127 | 128 | - Nothing. 129 | 130 | ## 1.0.0 - 2017-08-05 131 | 132 | ### Added 133 | 134 | - Adds `Fig\Http\Message\RequestMethodInterface`, with constants covering the 135 | most common HTTP request methods as specified by the IETF. 136 | 137 | ### Deprecated 138 | 139 | - Nothing. 140 | 141 | ### Removed 142 | 143 | - Nothing. 144 | 145 | ### Fixed 146 | 147 | - Nothing. 148 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 PHP Framework Interoperability Group 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PSR Http Message Util 2 | 3 | This repository holds utility classes and constants to facilitate common 4 | operations of [PSR-7](https://www.php-fig.org/psr/psr-7/); the primary purpose is 5 | to provide constants for referring to request methods, response status codes and 6 | messages, and potentially common headers. 7 | 8 | Implementation of PSR-7 interfaces is **not** within the scope of this package. 9 | 10 | ## Installation 11 | 12 | Install by adding the package as a [Composer](https://getcomposer.org) 13 | requirement: 14 | 15 | ```bash 16 | $ composer require fig/http-message-util 17 | ``` 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fig/http-message-util", 3 | "description": "Utility classes and constants for use with PSR-7 (psr/http-message)", 4 | "keywords": ["psr", "psr-7", "http", "http-message", "request", "response"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "PHP-FIG", 9 | "homepage": "https://www.php-fig.org/" 10 | } 11 | ], 12 | "require": { 13 | "php": "^5.3 || ^7.0 || ^8.0" 14 | }, 15 | "suggest": { 16 | "psr/http-message": "The package containing the PSR-7 interfaces" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Fig\\Http\\Message\\": "src/" 21 | } 22 | }, 23 | "extra": { 24 | "branch-alias": { 25 | "dev-master": "1.1.x-dev" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/RequestMethodInterface.php: -------------------------------------------------------------------------------- 1 | 11 | * class RequestFactory implements RequestMethodInterface 12 | * { 13 | * public static function factory( 14 | * $uri = '/', 15 | * $method = self::METHOD_GET, 16 | * $data = [] 17 | * ) { 18 | * } 19 | * } 20 | * 21 | */ 22 | interface RequestMethodInterface 23 | { 24 | const METHOD_HEAD = 'HEAD'; 25 | const METHOD_GET = 'GET'; 26 | const METHOD_POST = 'POST'; 27 | const METHOD_PUT = 'PUT'; 28 | const METHOD_PATCH = 'PATCH'; 29 | const METHOD_DELETE = 'DELETE'; 30 | const METHOD_PURGE = 'PURGE'; 31 | const METHOD_OPTIONS = 'OPTIONS'; 32 | const METHOD_TRACE = 'TRACE'; 33 | const METHOD_CONNECT = 'CONNECT'; 34 | } 35 | -------------------------------------------------------------------------------- /src/StatusCodeInterface.php: -------------------------------------------------------------------------------- 1 | 29 | * class ResponseFactory implements StatusCodeInterface 30 | * { 31 | * public function createResponse($code = self::STATUS_OK) 32 | * { 33 | * } 34 | * } 35 | * 36 | */ 37 | interface StatusCodeInterface 38 | { 39 | // Informational 1xx 40 | const STATUS_CONTINUE = 100; 41 | const STATUS_SWITCHING_PROTOCOLS = 101; 42 | const STATUS_PROCESSING = 102; 43 | const STATUS_EARLY_HINTS = 103; 44 | // Successful 2xx 45 | const STATUS_OK = 200; 46 | const STATUS_CREATED = 201; 47 | const STATUS_ACCEPTED = 202; 48 | const STATUS_NON_AUTHORITATIVE_INFORMATION = 203; 49 | const STATUS_NO_CONTENT = 204; 50 | const STATUS_RESET_CONTENT = 205; 51 | const STATUS_PARTIAL_CONTENT = 206; 52 | const STATUS_MULTI_STATUS = 207; 53 | const STATUS_ALREADY_REPORTED = 208; 54 | const STATUS_IM_USED = 226; 55 | // Redirection 3xx 56 | const STATUS_MULTIPLE_CHOICES = 300; 57 | const STATUS_MOVED_PERMANENTLY = 301; 58 | const STATUS_FOUND = 302; 59 | const STATUS_SEE_OTHER = 303; 60 | const STATUS_NOT_MODIFIED = 304; 61 | const STATUS_USE_PROXY = 305; 62 | const STATUS_RESERVED = 306; 63 | const STATUS_TEMPORARY_REDIRECT = 307; 64 | const STATUS_PERMANENT_REDIRECT = 308; 65 | // Client Errors 4xx 66 | const STATUS_BAD_REQUEST = 400; 67 | const STATUS_UNAUTHORIZED = 401; 68 | const STATUS_PAYMENT_REQUIRED = 402; 69 | const STATUS_FORBIDDEN = 403; 70 | const STATUS_NOT_FOUND = 404; 71 | const STATUS_METHOD_NOT_ALLOWED = 405; 72 | const STATUS_NOT_ACCEPTABLE = 406; 73 | const STATUS_PROXY_AUTHENTICATION_REQUIRED = 407; 74 | const STATUS_REQUEST_TIMEOUT = 408; 75 | const STATUS_CONFLICT = 409; 76 | const STATUS_GONE = 410; 77 | const STATUS_LENGTH_REQUIRED = 411; 78 | const STATUS_PRECONDITION_FAILED = 412; 79 | const STATUS_PAYLOAD_TOO_LARGE = 413; 80 | const STATUS_URI_TOO_LONG = 414; 81 | const STATUS_UNSUPPORTED_MEDIA_TYPE = 415; 82 | const STATUS_RANGE_NOT_SATISFIABLE = 416; 83 | const STATUS_EXPECTATION_FAILED = 417; 84 | const STATUS_IM_A_TEAPOT = 418; 85 | const STATUS_MISDIRECTED_REQUEST = 421; 86 | const STATUS_UNPROCESSABLE_ENTITY = 422; 87 | const STATUS_LOCKED = 423; 88 | const STATUS_FAILED_DEPENDENCY = 424; 89 | const STATUS_TOO_EARLY = 425; 90 | const STATUS_UPGRADE_REQUIRED = 426; 91 | const STATUS_PRECONDITION_REQUIRED = 428; 92 | const STATUS_TOO_MANY_REQUESTS = 429; 93 | const STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; 94 | const STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451; 95 | // Server Errors 5xx 96 | const STATUS_INTERNAL_SERVER_ERROR = 500; 97 | const STATUS_NOT_IMPLEMENTED = 501; 98 | const STATUS_BAD_GATEWAY = 502; 99 | const STATUS_SERVICE_UNAVAILABLE = 503; 100 | const STATUS_GATEWAY_TIMEOUT = 504; 101 | const STATUS_VERSION_NOT_SUPPORTED = 505; 102 | const STATUS_VARIANT_ALSO_NEGOTIATES = 506; 103 | const STATUS_INSUFFICIENT_STORAGE = 507; 104 | const STATUS_LOOP_DETECTED = 508; 105 | const STATUS_NOT_EXTENDED = 510; 106 | const STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511; 107 | } 108 | --------------------------------------------------------------------------------