|
16 | 16 | */ |
17 | 17 | enum RequestMethod: string |
18 | 18 | { |
19 | | - /** @var string The HEAD method requests the headers for a given resource without the response body. */ |
20 | | - case HEAD = 'HEAD'; |
| 19 | + /** The HEAD method requests the headers for a given resource without the response body. */ |
| 20 | + case Head = 'HEAD'; |
21 | 21 |
|
22 | | - /** @var string The GET method requests a representation of the specified resource. It MUST NOT have side-effects. */ |
23 | | - case GET = 'GET'; |
| 22 | + /** The GET method requests a representation of the specified resource. It MUST NOT have side-effects. */ |
| 23 | + case Get = 'GET'; |
24 | 24 |
|
25 | | - /** @var string The POST method submits data to be processed, often causing a change in state or side-effects. */ |
26 | | - case POST = 'POST'; |
| 25 | + /** The POST method submits data to be processed, often causing a change in state or side-effects. */ |
| 26 | + case Post = 'POST'; |
27 | 27 |
|
28 | | - /** @var string The PUT method replaces the target resource with the request payload. */ |
29 | | - case PUT = 'PUT'; |
| 28 | + /** The PUT method replaces the target resource with the request payload. */ |
| 29 | + case Put = 'PUT'; |
30 | 30 |
|
31 | | - /** @var string The PATCH method applies partial modifications to the target resource. */ |
32 | | - case PATCH = 'PATCH'; |
| 31 | + /** The PATCH method applies partial modifications to the target resource. */ |
| 32 | + case Patch = 'PATCH'; |
33 | 33 |
|
34 | | - /** @var string The DELETE method removes the specified resource. */ |
35 | | - case DELETE = 'DELETE'; |
| 34 | + /** The DELETE method removes the specified resource. */ |
| 35 | + case Delete = 'DELETE'; |
36 | 36 |
|
37 | | - /** @var string The PURGE method requests that a cached resource be removed, often used with proxy servers. */ |
38 | | - case PURGE = 'PURGE'; |
| 37 | + /** The PURGE method requests that a cached resource be removed, often used with proxy servers. */ |
| 38 | + case Purge = 'PURGE'; |
39 | 39 |
|
40 | | - /** @var string The OPTIONS method describes the communication options for the target resource. */ |
41 | | - case OPTIONS = 'OPTIONS'; |
| 40 | + /** The OPTIONS method describes the communication options for the target resource. */ |
| 41 | + case Options = 'OPTIONS'; |
42 | 42 |
|
43 | | - /** @var string The TRACE method performs a message loop-back test along the path to the target resource. */ |
44 | | - case TRACE = 'TRACE'; |
| 43 | + /** The TRACE method performs a message loop-back test along the path to the target resource. */ |
| 44 | + case Trace = 'TRACE'; |
45 | 45 |
|
46 | | - /** @var string The CONNECT method establishes a tunnel to the target resource, often used with HTTPS proxies. */ |
47 | | - case CONNECT = 'CONNECT'; |
| 46 | + /** The CONNECT method establishes a tunnel to the target resource, often used with HTTPS proxies. */ |
| 47 | + case Connect = 'CONNECT'; |
| 48 | + |
| 49 | + /** |
| 50 | + * Returns true if the method is considered safe (does not modify server state). |
| 51 | + * |
| 52 | + * @return bool |
| 53 | + */ |
| 54 | + public function isSafe(): bool |
| 55 | + { |
| 56 | + return in_array($this, [self::Get, self::Head, self::Options, self::Trace], true); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Returns true if the method is idempotent (multiple identical requests have the same effect as a single one). |
| 61 | + * |
| 62 | + * @return bool |
| 63 | + */ |
| 64 | + public function isIdempotent(): bool |
| 65 | + { |
| 66 | + return in_array($this, [self::Get, self::Head, self::Put, self::Delete, self::Options, self::Trace], true); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Returns true if the method is considered cacheable by default. |
| 71 | + * |
| 72 | + * @return bool |
| 73 | + */ |
| 74 | + public function isCacheable(): bool |
| 75 | + { |
| 76 | + return in_array($this, [self::Get, self::Head], true); |
| 77 | + } |
48 | 78 | } |
0 commit comments