|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Utility - Collection of various PHP utility functions. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Eric Sizemore <[email protected]> |
|
9
|
|
|
* @version 2.0.0 |
|
10
|
|
|
* @copyright (C) 2017 - 2024 Eric Sizemore |
|
11
|
|
|
* @license The MIT License (MIT) |
|
12
|
|
|
* |
|
13
|
|
|
* Copyright (C) 2017 - 2024 Eric Sizemore <https://www.secondversion.com>. |
|
14
|
|
|
* |
|
15
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
16
|
|
|
* of this software and associated documentation files (the "Software"), to |
|
17
|
|
|
* deal in the Software without restriction, including without limitation the |
|
18
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
19
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is |
|
20
|
|
|
* furnished to do so, subject to the following conditions: |
|
21
|
|
|
* |
|
22
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
23
|
|
|
* all copies or substantial portions of the Software. |
|
24
|
|
|
* |
|
25
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
26
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
27
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
28
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
29
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
30
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
31
|
|
|
* THE SOFTWARE. |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Esi\Utility\Enums\Http is a fork of Crell/EnumTools (https://github.com/Crell/EnumTools) |
|
36
|
|
|
* which is also licensed under the MIT license. |
|
37
|
|
|
* Crell/EnumTools Copyright 2021 Larry Garfield<[email protected]> |
|
38
|
|
|
* |
|
39
|
|
|
* For changes made in Esi\Utility\Enums\Http compared to the original Crell/EnumTools, see CHANGELOG.md#2.0.0 |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
namespace Esi\Utility\Enums\Http; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Enum of all official HTTP methods as registered with IANA. |
|
46
|
|
|
* |
|
47
|
|
|
* @see http://www.iana.org/assignments/http-methods/http-methods.xhtml |
|
48
|
|
|
* @since 2.0.0 |
|
49
|
|
|
*/ |
|
50
|
|
|
enum Methods: string |
|
51
|
|
|
{ |
|
52
|
|
|
// RFC3744, Section 8.1 |
|
53
|
|
|
case ACL = 'ACL'; |
|
54
|
|
|
// RFC3253, Section 12.6 |
|
55
|
|
|
case BASELINE_CONTROL = 'BASELINE-CONTROL'; |
|
56
|
|
|
// RFC5842, Section 5842, Section 4 |
|
57
|
|
|
case BIND = 'BIND'; |
|
58
|
|
|
// RFC3253, Section 4.4, Section 9.4 |
|
59
|
|
|
case CHECKIN = 'CHECKIN'; |
|
60
|
|
|
// RFC3253, Section 4.3, Section 8.8 |
|
61
|
|
|
case CHECKOUT = 'CHECKOUT'; |
|
62
|
|
|
// RFC7231, Section 4.3.9 |
|
63
|
|
|
case CONNECT = 'CONNECT'; |
|
64
|
|
|
// RFC4918, Section 9.8 |
|
65
|
|
|
case COPY = 'COPY'; |
|
66
|
|
|
// RFC7231, Section 4.3.5 |
|
67
|
|
|
case DELETE = 'DELETE'; |
|
68
|
|
|
// RFC7231, Section 4.3.1 |
|
69
|
|
|
case GET = 'GET'; |
|
70
|
|
|
// RFC7231, Section 4.3.2 |
|
71
|
|
|
case HEAD = 'HEAD'; |
|
72
|
|
|
// RFC3253, Section 8.2 |
|
73
|
|
|
case LABEL = 'LABEL'; |
|
74
|
|
|
// RFC2068, Section 19.6.1.2 |
|
75
|
|
|
case LINK = 'LINK'; |
|
76
|
|
|
// RFC4918, Section 9.10 |
|
77
|
|
|
case LOCK = 'LOCK'; |
|
78
|
|
|
// RFC3253, Section 11.2 |
|
79
|
|
|
case MERGE = 'MERGE'; |
|
80
|
|
|
// RFC3253, Section 13.5 |
|
81
|
|
|
case MKACTIVITY = 'MKACTIVITY'; |
|
82
|
|
|
// RFC4791, Section 5.3.1. RFC8144, Section 2.3. |
|
83
|
|
|
case MKCALENDAR = 'MKCALENDAR'; |
|
84
|
|
|
// RFC4918, Section 9.3. RFC5689, Section 3. RFC8144, Section 2.3. |
|
85
|
|
|
case MKCOL = 'MKCOL'; |
|
86
|
|
|
// RFC4437, Section 6 |
|
87
|
|
|
case MKREDIRECTREF = 'MKREDIRECTREF'; |
|
88
|
|
|
// RFC3253, Section 6.3 |
|
89
|
|
|
case MKWORKSPACE = 'MKWORKSPACE'; |
|
90
|
|
|
// RFC4918, Section 9.9 |
|
91
|
|
|
case MOVE = 'MOVE'; |
|
92
|
|
|
// RFC7231, Section 4.3.7 |
|
93
|
|
|
case OPTIONS = 'OPTIONS'; |
|
94
|
|
|
// RFC3648, Section 7 |
|
95
|
|
|
case ORDERPATCH = 'ORDERPATCH'; |
|
96
|
|
|
// RFC5789, Section 2 |
|
97
|
|
|
case PATCH = 'PATCH'; |
|
98
|
|
|
// RFC7231, Section 4.3.3 |
|
99
|
|
|
case POST = 'POST'; |
|
100
|
|
|
// RFC7540, Section 3.5 |
|
101
|
|
|
case PRI = 'PRI'; |
|
102
|
|
|
// RFC4918, Section 9.1. RFC8144, Section 2.1. |
|
103
|
|
|
case PROPFIND = 'PROPFIND'; |
|
104
|
|
|
// RFC4918, Section 9.2. RFC8144, Section 2.2. |
|
105
|
|
|
case PROPPATCH = 'PROPPATCH'; |
|
106
|
|
|
// RFC7231, Section 4.3.4 |
|
107
|
|
|
case PUT = 'PUT'; |
|
108
|
|
|
// RFC5842, Section 6 |
|
109
|
|
|
case REBIND = 'REBIND'; |
|
110
|
|
|
// // RFC3253, Section 3.6. RFC8144, Section 2.1 |
|
111
|
|
|
case REPORT = 'REPORT'; |
|
112
|
|
|
// RFC5323, Section 2 |
|
113
|
|
|
case SEARCH = 'SEARCH'; |
|
114
|
|
|
// RFC7231, Section 4.3.8 |
|
115
|
|
|
case TRACE = 'TRACE'; |
|
116
|
|
|
// RFC5842, Section 5 |
|
117
|
|
|
case UNBIND = 'UNBIND'; |
|
118
|
|
|
// RFC3253, Section 4.5 |
|
119
|
|
|
case UNCHECKOUT = 'UNCHECKOUT'; |
|
120
|
|
|
// RFC2068, Section 19.6.1.3 |
|
121
|
|
|
case UNLINK = 'UNLINK'; |
|
122
|
|
|
// RFC4918, Section 9.11 |
|
123
|
|
|
case UNLOCK = 'UNLOCK'; |
|
124
|
|
|
// RFC3253, Section 7.1 |
|
125
|
|
|
case UPDATE = 'UPDATE'; |
|
126
|
|
|
// RFC4437, Section 7 |
|
127
|
|
|
case UPDATEREDIRECTREF = 'UPDATEREDIRECTREF'; |
|
128
|
|
|
// RFC3253, Section 3.5 |
|
129
|
|
|
case VERSION_CONTROL = 'VERSION-CONTROL'; |
|
130
|
|
|
// These are quasi-official, as they're defined by the HTCPCP RFC. |
|
131
|
|
|
case BREW = 'BREW'; |
|
132
|
|
|
case WHEN = 'WHEN'; |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Returns the value of a given case. |
|
136
|
|
|
* eg: Methods::UNCHECKOUT->getValue() // UNCHECKOUT |
|
137
|
|
|
* |
|
138
|
|
|
* @return string Value |
|
139
|
|
|
*/ |
|
140
|
3 |
|
public function getValue(): string |
|
141
|
|
|
{ |
|
142
|
3 |
|
return $this->value; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Returns the name of a given case. |
|
147
|
|
|
* eg: Methods::UNCHECKOUT->getName() // UNCHECKOUT |
|
148
|
|
|
* |
|
149
|
|
|
* @return string Case name |
|
150
|
|
|
*/ |
|
151
|
2 |
|
public function getName(): string |
|
152
|
|
|
{ |
|
153
|
2 |
|
return $this->name; |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Determines if this method is considered safe. |
|
158
|
|
|
* |
|
159
|
|
|
* A safe method is one that does not have user-affecting side-effects |
|
160
|
|
|
* other than information retrieval. |
|
161
|
|
|
* |
|
162
|
|
|
* @return bool |
|
163
|
|
|
*/ |
|
164
|
1 |
|
public function isSafe(): bool |
|
165
|
|
|
{ |
|
166
|
1 |
|
return match ($this) { |
|
167
|
1 |
|
self::GET, self::HEAD, self::OPTIONS, self::PRI, self::PROPFIND, self::REPORT, self::SEARCH, self::TRACE => true, |
|
168
|
1 |
|
default => false, |
|
169
|
1 |
|
}; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Determines if this method is idempotent. |
|
174
|
|
|
* |
|
175
|
|
|
* A method is idempotent if issuing the same command multiple times |
|
176
|
|
|
* will result in the same end condition each time. |
|
177
|
|
|
* |
|
178
|
|
|
* @return bool |
|
179
|
|
|
*/ |
|
180
|
1 |
|
public function isIdempotent(): bool |
|
181
|
|
|
{ |
|
182
|
1 |
|
return match ($this) { |
|
183
|
1 |
|
self::CONNECT, self::LOCK, self::PATCH, self::POST => false, |
|
184
|
1 |
|
default => true, |
|
185
|
1 |
|
}; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|