1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Resilient\Traits; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Routeable trait. |
7
|
|
|
*/ |
8
|
|
|
trait Routeable |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* get function. |
12
|
|
|
* |
13
|
|
|
* @access public |
14
|
|
|
* @param string $pattern |
15
|
|
|
* @param mixed $handler |
16
|
|
|
* @return Route |
17
|
|
|
*/ |
18
|
|
|
public function get(string $pattern, $handler) |
19
|
|
|
{ |
20
|
|
|
return $this->map('GET', $pattern, $handler); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* post function. |
25
|
|
|
* |
26
|
|
|
* @access public |
27
|
|
|
* @param string $pattern |
28
|
|
|
* @param mixed $handler |
29
|
|
|
* @return Route |
30
|
|
|
*/ |
31
|
|
|
public function post(string $pattern, $handler) |
32
|
|
|
{ |
33
|
|
|
return $this->map('POST', $pattern, $handler); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* put function. |
38
|
|
|
* |
39
|
|
|
* @access public |
40
|
|
|
* @param string $pattern |
41
|
|
|
* @param mixed $handler |
42
|
|
|
* @return Route |
43
|
|
|
*/ |
44
|
|
|
public function put(string $pattern, $handler) |
45
|
|
|
{ |
46
|
|
|
return $this->map('PUT', $pattern, $handler); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* patch function. |
51
|
|
|
* |
52
|
|
|
* @access public |
53
|
|
|
* @param string $pattern |
54
|
|
|
* @param mixed $handler |
55
|
|
|
* @return Route |
56
|
|
|
*/ |
57
|
|
|
public function patch(string $pattern, $handler) |
58
|
|
|
{ |
59
|
|
|
return $this->map('PATCH', $pattern, $handler); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* delete function. |
64
|
|
|
* |
65
|
|
|
* @access public |
66
|
|
|
* @param string $pattern |
67
|
|
|
* @param mixed $handler |
68
|
|
|
* @return Route |
69
|
|
|
*/ |
70
|
|
|
public function delete(string $pattern, $handler) |
71
|
|
|
{ |
72
|
|
|
return $this->map('DELETE', $pattern, $handler); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* options function. |
77
|
|
|
* |
78
|
|
|
* @access public |
79
|
|
|
* @param string $pattern |
80
|
|
|
* @param mixed $handler |
81
|
|
|
* @return Route |
82
|
|
|
*/ |
83
|
|
|
public function options(string $pattern, $handler) |
84
|
|
|
{ |
85
|
|
|
return $this->map('OPTIONS', $pattern, $handler); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* any function. |
90
|
|
|
* |
91
|
|
|
* @access public |
92
|
|
|
* @param string $pattern |
93
|
|
|
* @param mixed $handler |
94
|
|
|
* @return Route |
95
|
|
|
*/ |
96
|
|
|
public function any(string $pattern, $handler) |
97
|
|
|
{ |
98
|
|
|
return $this->map(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], $pattern, $handler); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* map function. |
103
|
|
|
* |
104
|
|
|
* @access public |
105
|
|
|
* @abstract |
106
|
|
|
* @param mixed $methods |
107
|
|
|
* @param string $pattern |
108
|
|
|
* @param mixed $handler |
109
|
|
|
* @return Route |
110
|
|
|
*/ |
111
|
|
|
abstract public function map($methods, string $pattern, $handler); |
112
|
|
|
} |
113
|
|
|
|