-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMethod.php
117 lines (114 loc) · 3.58 KB
/
Method.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php declare(strict_types=1);
/*
* This file is part of Aplus Framework HTTP Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Framework\HTTP;
use InvalidArgumentException;
/**
* Class Method.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
*
* @package http
*/
class Method
{
/**
* The HTTP CONNECT method starts two-way communications with the requested
* resource. It can be used to open a tunnel.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT
*/
public const string CONNECT = 'CONNECT';
/**
* The HTTP DELETE request method deletes the specified resource.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
*/
public const string DELETE = 'DELETE';
/**
* The HTTP GET method requests a representation of the specified resource.
* Requests using GET should only be used to request data (they shouldn't
* include data).
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
*/
public const string GET = 'GET';
/**
* The HTTP HEAD method requests the headers that would be returned if the
* HEAD request's URL was instead requested with the HTTP GET method.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
*/
public const string HEAD = 'HEAD';
/**
* The HTTP OPTIONS method requests permitted communication options for a
* given URL or server. A client can specify a URL with this method, or an
* asterisk (*) to refer to the entire server.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
*/
public const string OPTIONS = 'OPTIONS';
/**
* The HTTP PATCH request method applies partial modifications to a resource.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
*/
public const string PATCH = 'PATCH';
/**
* The HTTP POST method sends data to the server. The type of the body of
* the request is indicated by the Content-Type header.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
* @see Header::CONTENT_TYPE
*/
public const string POST = 'POST';
/**
* The HTTP PUT request method creates a new resource or replaces a
* representation of the target resource with the request payload.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
*/
public const string PUT = 'PUT';
/**
* The HTTP TRACE method performs a message loop-back test along the path to
* the target resource, providing a useful debugging mechanism.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE
*/
public const string TRACE = 'TRACE';
/**
* @var array<string>
*/
protected static array $methods = [
'CONNECT',
'DELETE',
'GET',
'HEAD',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'TRACE',
];
/**
* @param string $method
*
* @throws InvalidArgumentException for invalid method
*
* @return string
*/
public static function validate(string $method) : string
{
$valid = \strtoupper($method);
if (\in_array($valid, static::$methods, true)) {
return $valid;
}
throw new InvalidArgumentException('Invalid request method: ' . $method);
}
}