Skip to content

Commit df0c6b7

Browse files
committed
initial commit
0 parents  commit df0c6b7

File tree

9 files changed

+402
-0
lines changed

9 files changed

+402
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Akihito Koriyama
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
13+
all 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
21+
THE SOFTWARE.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Koriym.HttpConstants
2+
3+
Contains the values of status codes, request method, and headers for the Hypertext Transfer Protocol (HTTP).
4+
Constants only.
5+
6+
## Example
7+
8+
```php
9+
10+
use Koriym\HttpConstants\HttpStatusCode;
11+
12+
http_response_code(StatusCode::BAD_REQUEST);
13+
header(ResponseHeaders::CACHE_CONTROL. ': max-age=3600');
14+
```
15+
16+
### Install
17+
18+
$ composer require koriym/http-constants
19+
20+

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "koriym/http-constants",
3+
"description":"Constatnts for the HTTP protocol",
4+
"require": {
5+
"php": ">=5.3.0"
6+
},
7+
"keywords":[
8+
"http",
9+
"consntats"
10+
],
11+
"license": "MIT",
12+
"autoload":{
13+
"psr-4":{
14+
"Koriym\\HttpConstants\\": "src/"
15+
}
16+
}
17+
}

docs/example.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Koriym\HttpConstants\StatusCode;
4+
5+
require dirname(__DIR__).'/vendor/autoload.php';
6+
7+
echo sprintf(
8+
"%s %s\n",
9+
StatusCode::BAD_REQUEST,
10+
(new StatusCode)->statusText[StatusCode::BAD_REQUEST]
11+
);
12+
13+
// 400 Bad Request

src/MediaType.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Koriym.HttpConstants.
5+
*
6+
* @license http://opensource.org/licenses/MIT MIT
7+
*/
8+
namespace Koriym\HttpConstants;
9+
10+
/**
11+
* Media Type
12+
*/
13+
final class MediaType
14+
{
15+
// generic
16+
const MULTIPART_FORM_DATA = 'multipart/form-data';
17+
const TEXT_PLAIN = 'text/plain';
18+
const TEXT_XML = 'text/xml';
19+
const TEXT_HTML = 'text/html';
20+
const WILDCARD = "*/*";
21+
22+
// application
23+
const APPLICATION_ATOM_XML = "application/atom+xml";
24+
const APPLICATION_FORM_URLENCODED = 'application/x-www-form-urlencoded';
25+
const APPLICATION_JSON = 'application/json';
26+
const APPLICATION_XML = 'application/xml';
27+
const APPLICATION_SVG_XML = 'application/svg+xml';
28+
const APPLICATION_XHTML_XML = "application/xhtml+xml";
29+
const APPLICATION_RDF_XML = "application/rdf+xml";
30+
const APPLICATION_OCTET_STREAM = 'application/octet-stream';
31+
32+
// JSON hyper media
33+
const APPLICATION_HAL = 'application/hal+json';
34+
const APPLICATION_JSON_API = 'application/vnd.api+json';
35+
const APPLICATION_JSON_LD = 'application/ld+json';
36+
const APPLICATION_COLLECTION_JSON = 'application/vnd.collection+json';
37+
const APPLICATION_SIREN = 'application/vnd.siren+json';
38+
const APPLICATION_UBER = 'application/vnd.uber+json';
39+
}

src/Method.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Koriym.HttpConstants.
5+
*
6+
* @license http://opensource.org/licenses/MIT MIT
7+
*/
8+
namespace Koriym\HttpConstants;
9+
10+
/**
11+
* HTTP Request Methods.
12+
*
13+
* @see http://www.ietf.org/rfc/rfc7231.txt
14+
*/
15+
final class Method
16+
{
17+
const POST = 'POST';
18+
const GET = 'GET';
19+
const OPTIONS = 'OPTIONS';
20+
const HEAD = 'HEAD';
21+
const PUT = 'PUT';
22+
const DELETE = 'DELETE';
23+
const TRACE = 'TRACE';
24+
const CONNECT = 'CONNECT';
25+
const PATCH = 'PATCH';
26+
const LINK = 'LINK';
27+
const UNLINK = 'UNLINK';
28+
}

src/RequestHeaders.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Koriym.HttpConstants.
5+
*
6+
* @license http://opensource.org/licenses/MIT MIT
7+
*/
8+
namespace Koriym\HttpConstants;
9+
10+
/**
11+
* HTTP request header field names.
12+
*/
13+
final class RequestHeaders
14+
{
15+
// Standard (RFC) Request Fields
16+
const ACCEPT = 'Accept';
17+
const ACCEPT_CHARSET = 'Accept-Charset';
18+
const ACCEPT_ENCODING = 'Accept-Encoding';
19+
const ACCEPT_LANGUAGE = 'Accept-Language';
20+
const ACCEPT_DATETIME = 'Accept-Datetime';
21+
const AUTHORIZATION = 'Authorization';
22+
const CACHE_CONTROL = 'Cache-Control';
23+
const CONNECTION = 'Connection';
24+
const COOKIE = 'Cookie';
25+
const CONTENT_LENGTH = 'Content-Length';
26+
const CONTENT_MD5 = 'Content-MD5';
27+
const DATE = 'Date';
28+
const EXPECT = 'Expect';
29+
const FROM = 'From';
30+
const HOST = 'Host';
31+
const IF_MATCH = 'If-Match';
32+
const IF_MODIFIED_SINCE = 'If-Modified-Since';
33+
const IF_NONE_MATCH = 'If-None-Matched';
34+
const IF_RANGE = 'If-Range';
35+
const IF_UNMODIFIED_SINCE = 'If-Unmodified-Since';
36+
const MAX_FORWARDS = 'Max-Forwards';
37+
const ORIGIN = 'Origin';
38+
const PRAGMA = 'Pragma';
39+
const PROXY_AUTHORIZATION = 'Proxy-Authorization';
40+
const RANGE = 'Range';
41+
const REFERER = 'Referer';
42+
const TE = 'TE';
43+
const UPGRADE = 'Upgrade';
44+
const USER_AGENT = 'User-Agent';
45+
const VIA = 'Via';
46+
const WARNING = 'Warning';
47+
// Common Non-Standard Request Fields
48+
const DNT = 'DNT';
49+
const FRONT_END_HTTPS = 'Front-End-Https';
50+
const PROXY_CONNECTION = 'Proxy-Connection';
51+
const X_CSRF_TOKEN = 'X-Csrf-Token';
52+
const X_FORWARDED_FOR = 'X-Forwarded-For';
53+
const X_FORWARDED_HOSTS = 'X-Forwarded-For';
54+
const X_FORWARDED_PROTO = 'X-Forwarded-Proto';
55+
const X_HTTP_METHOD_OVERRIDE = 'X-Http-Method-Override';
56+
const X_REQUESTED_WITH = 'X-Requested-With';
57+
const X_WAP_PROFILE = 'X-Wap-Profile';
58+
}

src/ResponseHeaders.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Koriym.HttpConstants.
5+
*
6+
* @license http://opensource.org/licenses/MIT MIT
7+
*/
8+
namespace Koriym\HttpConstants;
9+
10+
/**
11+
* HTTP response header field names.
12+
*
13+
* @see https://www.ietf.org/rfc/rfc2109.txt
14+
* @see https://www.ietf.org/rfc/rfc2183.txt
15+
* @see https://www.ietf.org/rfc/rfc2616.txt
16+
* @see https://www.ietf.org/rfc/rfc2965.txt
17+
* @see https://www.ietf.org/rfc/rfc5998.txt
18+
*/
19+
final class ResponseHeaders
20+
{
21+
// Standard (RFC) Response Fields
22+
const ACCESS_CONTROL_ALLOW_ORIGIN = 'Access-Control-Allow-Origin';
23+
const ACCEPT_PATCH = 'Accept-Patch';
24+
const ACCEPT_RANGES = 'Accept-Ranges';
25+
const AGE = 'Age';
26+
const ALLOW = 'Allow';
27+
const CACHE_CONTROL = 'Cache-Control';
28+
const CONNECTION = 'Connection';
29+
const CONTENT_DISPOSITION = 'Content-Disposition';
30+
const CONTENT_ENCODING = 'Content-Encoding';
31+
const CONTENT_LANGUAGE = 'Content-Language';
32+
const CONTENT_LENGTH = 'Content-Length';
33+
const CONTENT_LOCATION = 'Content-Location';
34+
const CONTENT_MD5 = 'Content-MD5';
35+
const CONTENT_TYPE = 'Content-Type';
36+
const DATE = 'Date';
37+
const ETAG = 'ETag';
38+
const EXPIRES = 'Expires';
39+
const LAST_MODIFIED = 'Last-Modified';
40+
const P3P = 'P3P';
41+
const PROXY_AUTHENTICATE = 'Proxy-Authenticate';
42+
const PUBLIC_KEY_PINS = 'Public-Key-Pins';
43+
const REFRESH = 'Refresh';
44+
const RETRY_AFTER = 'Retry-After';
45+
const SERVER = 'Server';
46+
const SET_COOKIE = 'Set-Cookie';
47+
const STATUS = 'Status';
48+
const STRICT_TRANSPORT_SECURITY = 'Strict-Transport-Security';
49+
const TRAILER = 'Trailer';
50+
const TRANSFER_ENCODING = 'Transfer-Encoding';
51+
const UPGRADE = 'Upgrade';
52+
const VARY = 'Vary';
53+
const WARNING = 'Warning';
54+
const WWW_AUTHENTICATE = 'WWW-Authenticate';
55+
// Common Non-Standard Request Fields
56+
const CONTENT_SECURITY_POLICY = 'Content-Security-Policy';
57+
const X_XSS_PROTECTION = 'X-XSS-Protection';
58+
const X_CONTENT_TYPE_OPTIONS = 'X-Content-Type-Options';
59+
const X_POWERED_BY = 'X-Powered-By';
60+
const X_UA_COMPATIBLE = 'X-UA-Compatible';
61+
const X_CONTENT_DURATION = 'X-Content-Duration';
62+
}

0 commit comments

Comments
 (0)