1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Simply\Router; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Provides valid values for the HTTP request method. |
7
|
|
|
* @author Riikka Kalliomäki <[email protected]> |
8
|
|
|
* @copyright Copyright (c) 2018-2019 Riikka Kalliomäki |
9
|
|
|
* @license http://opensource.org/licenses/mit-license.php MIT License |
10
|
|
|
*/ |
11
|
|
|
class HttpMethod |
12
|
|
|
{ |
13
|
|
|
/** The HTTP GET request method */ |
14
|
|
|
public const GET = 'GET'; |
15
|
|
|
|
16
|
|
|
/** The HTTP HEAD request method */ |
17
|
|
|
public const HEAD = 'HEAD'; |
18
|
|
|
|
19
|
|
|
/** The HTTP POST request method */ |
20
|
|
|
public const POST = 'POST'; |
21
|
|
|
|
22
|
|
|
/** The HTTP PUT request method */ |
23
|
|
|
public const PUT = 'PUT'; |
24
|
|
|
|
25
|
|
|
/** The HTTP DELETE request method */ |
26
|
|
|
public const DELETE = 'DELETE'; |
27
|
|
|
|
28
|
|
|
/** The HTTP CONNECT request method */ |
29
|
|
|
public const CONNECT = 'CONNECT'; |
30
|
|
|
|
31
|
|
|
/** The HTTP OPTIONS request method */ |
32
|
|
|
public const OPTIONS = 'OPTIONS'; |
33
|
|
|
|
34
|
|
|
/** The HTTP TRACE request method */ |
35
|
|
|
public const TRACE = 'TRACE'; |
36
|
|
|
|
37
|
|
|
/** The HTTP PATCH request method */ |
38
|
|
|
public const PATCH = 'PATCH'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Tells if the given string is a valid HTTP request method. |
42
|
|
|
* @param string $method The string to test |
43
|
|
|
* @return bool True if it is a valid HTTP request method, false if not |
44
|
|
|
*/ |
45
|
32 |
|
public static function isValid(string $method): bool |
46
|
|
|
{ |
47
|
32 |
|
return \in_array($method, self::getAll(), true); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns list of all valid HTTP request methods. |
52
|
|
|
* @return string[] List of all valid HTTP request methods |
53
|
|
|
*/ |
54
|
32 |
|
public static function getAll(): array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
32 |
|
self::GET, |
58
|
32 |
|
self::HEAD, |
59
|
32 |
|
self::POST, |
60
|
32 |
|
self::PUT, |
61
|
32 |
|
self::DELETE, |
62
|
32 |
|
self::CONNECT, |
63
|
32 |
|
self::OPTIONS, |
64
|
32 |
|
self::TRACE, |
65
|
32 |
|
self::PATCH, |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|