1 | <?php |
||
11 | trait HasRoutesTrait { |
||
12 | /** |
||
13 | * Array of registered routes |
||
14 | * |
||
15 | * @var RouteInterface[] |
||
16 | */ |
||
17 | protected $routes = []; |
||
18 | |||
19 | /** |
||
20 | * Get registered routes |
||
21 | * |
||
22 | * @return RouteInterface[] |
||
23 | */ |
||
24 | public function getRoutes() { |
||
27 | |||
28 | /** |
||
29 | * Add a route |
||
30 | * |
||
31 | * @param RouteInterface $route |
||
32 | * @return RouteInterface |
||
33 | */ |
||
34 | public function addRoute( $route ) { |
||
38 | |||
39 | /** |
||
40 | * Create and add a new route |
||
41 | * |
||
42 | * @param string[] $methods |
||
43 | * @param mixed $target |
||
44 | * @param string|Closure|null $handler |
||
45 | * @return RouteInterface |
||
46 | */ |
||
47 | public function route( $methods, $target, $handler = null ) { |
||
55 | |||
56 | /** |
||
57 | * Create and add a route group |
||
58 | * |
||
59 | * @param string $target |
||
60 | * @param Closure $callable |
||
61 | * @return RouteInterface |
||
62 | */ |
||
63 | public function group( $target, Closure $callable ) { |
||
67 | |||
68 | /** |
||
69 | * Create and add a route for the GET and HEAD methods |
||
70 | * |
||
71 | * @param mixed $target |
||
72 | * @param string|Closure|null $handler |
||
73 | * @return RouteInterface |
||
74 | */ |
||
75 | public function get( $target, $handler = null ) { |
||
78 | |||
79 | /** |
||
80 | * Create and add a route for the POST method |
||
81 | * |
||
82 | * @param mixed $target |
||
83 | * @param string|Closure|null $handler |
||
84 | * @return RouteInterface |
||
85 | */ |
||
86 | public function post( $target, $handler = null ) { |
||
89 | |||
90 | /** |
||
91 | * Create and add a route for the PUT method |
||
92 | * |
||
93 | * @param mixed $target |
||
94 | * @param string|Closure|null $handler |
||
95 | * @return RouteInterface |
||
96 | */ |
||
97 | public function put( $target, $handler = null ) { |
||
100 | |||
101 | /** |
||
102 | * Create and add a route for the PATCH method |
||
103 | * |
||
104 | * @param mixed $target |
||
105 | * @param string|Closure|null $handler |
||
106 | * @return RouteInterface |
||
107 | */ |
||
108 | public function patch( $target, $handler = null ) { |
||
111 | |||
112 | /** |
||
113 | * Create and add a route for the DELETE method |
||
114 | * |
||
115 | * @param mixed $target |
||
116 | * @param string|Closure|null $handler |
||
117 | * @return RouteInterface |
||
118 | */ |
||
119 | public function delete( $target, $handler = null ) { |
||
122 | |||
123 | /** |
||
124 | * Create and add a route for the OPTIONS method |
||
125 | * |
||
126 | * @param mixed $target |
||
127 | * @param string|Closure|null $handler |
||
128 | * @return RouteInterface |
||
129 | */ |
||
130 | public function options( $target, $handler = null ) { |
||
133 | |||
134 | /** |
||
135 | * Create and add a route for all supported methods |
||
136 | * |
||
137 | * @param mixed $target |
||
138 | * @param string|Closure|null $handler |
||
139 | * @return RouteInterface |
||
140 | */ |
||
141 | public function any( $target, $handler = null ) { |
||
144 | } |
||
145 |