|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SimpleRoute; |
|
4
|
|
|
|
|
5
|
|
|
final class Route implements RouteInterface |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var string[] |
|
9
|
|
|
*/ |
|
10
|
|
|
private $methods; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
private $pattern; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var mixed |
|
19
|
|
|
*/ |
|
20
|
|
|
private $handler; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string|string[] $method The HTTP method, or an array of, to match |
|
24
|
|
|
* @param string $pattern The URI pattern |
|
25
|
|
|
* @param mixed $handler The handler |
|
26
|
|
|
*/ |
|
27
|
33 |
|
public function __construct($method, $pattern, $handler) |
|
28
|
|
|
{ |
|
29
|
33 |
|
if (is_array($method)) { |
|
30
|
18 |
|
$this->methods = $method; |
|
31
|
18 |
|
} else { |
|
32
|
15 |
|
$this->methods = array($method); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
33 |
|
$this->pattern = $pattern; |
|
36
|
33 |
|
$this->handler = $handler; |
|
37
|
33 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $pattern The URI pattern |
|
41
|
|
|
* @param mixed $handler The handler |
|
42
|
|
|
* |
|
43
|
|
|
* @return Route |
|
44
|
|
|
*/ |
|
45
|
3 |
|
public static function GET($pattern, $handler) |
|
46
|
|
|
{ |
|
47
|
3 |
|
return new self(['GET'], $pattern, $handler); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $pattern The URI pattern |
|
52
|
|
|
* @param mixed $handler The handler |
|
53
|
|
|
* |
|
54
|
|
|
* @return Route |
|
55
|
|
|
*/ |
|
56
|
3 |
|
public static function POST($pattern, $handler) |
|
57
|
|
|
{ |
|
58
|
3 |
|
return new self(['POST'], $pattern, $handler); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $pattern The URI pattern |
|
63
|
|
|
* @param mixed $handler The handler |
|
64
|
|
|
* |
|
65
|
|
|
* @return Route |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public static function PUT($pattern, $handler) |
|
68
|
|
|
{ |
|
69
|
3 |
|
return new self(['PUT'], $pattern, $handler); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $pattern The URI pattern |
|
74
|
|
|
* @param mixed $handler The handler |
|
75
|
|
|
* |
|
76
|
|
|
* @return Route |
|
77
|
|
|
*/ |
|
78
|
3 |
|
public static function PATCH($pattern, $handler) |
|
79
|
|
|
{ |
|
80
|
3 |
|
return new self(['PATCH'], $pattern, $handler); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param string $pattern The URI pattern |
|
85
|
|
|
* @param mixed $handler The handler |
|
86
|
|
|
* |
|
87
|
|
|
* @return Route |
|
88
|
|
|
*/ |
|
89
|
3 |
|
public static function DELETE($pattern, $handler) |
|
90
|
|
|
{ |
|
91
|
3 |
|
return new self(['DELETE'], $pattern, $handler); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* {@inheritdoc} |
|
98
|
|
|
*/ |
|
99
|
30 |
|
public function getMethods() |
|
100
|
|
|
{ |
|
101
|
30 |
|
return $this->methods; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* {@inheritdoc} |
|
106
|
|
|
*/ |
|
107
|
27 |
|
public function getPattern() |
|
108
|
|
|
{ |
|
109
|
27 |
|
return $this->pattern; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritdoc} |
|
114
|
|
|
*/ |
|
115
|
21 |
|
public function getHandler() |
|
116
|
|
|
{ |
|
117
|
21 |
|
return $this->handler; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|