|
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 Riikka Kalliomäki |
|
9
|
|
|
* @license http://opensource.org/licenses/mit-license.php MIT License |
|
10
|
|
|
*/ |
|
11
|
|
|
class HttpMethod |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var string The HTTP GET request method */ |
|
14
|
|
|
public const GET = 'GET'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var string The HTTP HEAD request method */ |
|
17
|
|
|
public const HEAD = 'HEAD'; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string The HTTP POST request method */ |
|
20
|
|
|
public const POST = 'POST'; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string The HTTP PUT request method */ |
|
23
|
|
|
public const PUT = 'PUT'; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string The HTTP DELETE request method */ |
|
26
|
|
|
public const DELETE = 'DELETE'; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string The HTTP CONNECT request method */ |
|
29
|
|
|
public const CONNECT = 'CONNECT'; |
|
30
|
|
|
|
|
31
|
|
|
/** @var string The HTTP OPTIONS request method */ |
|
32
|
|
|
public const OPTIONS = 'OPTIONS'; |
|
33
|
|
|
|
|
34
|
|
|
/** @var string The HTTP TRACE request method */ |
|
35
|
|
|
public const TRACE = 'TRACE'; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string 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
|
26 |
|
public static function isValid(string $method): bool |
|
46
|
|
|
{ |
|
47
|
26 |
|
return \in_array($method, self::getAll(), true); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns list of all valid HTTP request methods. |
|
52
|
|
|
* @return array List of all valid HTTP request methods |
|
53
|
|
|
*/ |
|
54
|
26 |
|
public static function getAll(): array |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
26 |
|
self::GET, |
|
58
|
26 |
|
self::HEAD, |
|
59
|
26 |
|
self::POST, |
|
60
|
26 |
|
self::PUT, |
|
61
|
26 |
|
self::DELETE, |
|
62
|
26 |
|
self::CONNECT, |
|
63
|
26 |
|
self::OPTIONS, |
|
64
|
26 |
|
self::TRACE, |
|
65
|
26 |
|
self::PATCH, |
|
66
|
|
|
]; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|