1 | <?php |
||
26 | trait ControllerCollectorTrait |
||
27 | { |
||
28 | |||
29 | abstract public function getWildcards(); |
||
31 | |||
32 | /** |
||
33 | * Define how controller actions names will be joined to form the route pattern. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | |||
38 | protected $controllerActionJoin = "/"; |
||
39 | |||
40 | /** |
||
41 | * Maps all the controller methods that begins with a HTTP method, and maps the rest of |
||
42 | * name as a path. The path will be the method name with slashes before every camelcased |
||
43 | * word and without the HTTP method prefix, and the controller name will be used to prefix |
||
44 | * the route pattern. e.g. ArticlesController::getCreate will generate a route to: GET articles/create |
||
45 | * |
||
46 | * @param string $controller The controller name |
||
47 | * @param string $prefix |
||
48 | * |
||
49 | * @throws \ReflectionException |
||
50 | * @return Group |
||
51 | */ |
||
52 | |||
53 | 5 | public function controller($controller, $prefix = null) |
|
60 | |||
61 | /** |
||
62 | * Maps several controllers at same time. |
||
63 | * |
||
64 | * @param string[] $controllers Controllers name. |
||
65 | * @throws \ReflectionException |
||
66 | * @return Group |
||
67 | */ |
||
68 | |||
69 | 1 | public function controllers(array $controllers) |
|
70 | { |
||
71 | 1 | $group = new Group; |
|
72 | 1 | foreach ($controllers as $controller) |
|
73 | 1 | $group->set($this->controller($controller)); |
|
74 | 1 | return $group; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Alias for Collector::controller but maps a controller without using the controller name as prefix. |
||
79 | * |
||
80 | * @param string $controller The controller name |
||
81 | * @throws \ReflectionException |
||
82 | * @return Group |
||
83 | */ |
||
84 | |||
85 | 2 | public function controllerWithoutPrefix($controller) |
|
91 | |||
92 | /** |
||
93 | * Alias for Collector::controllers but maps a controller without using the controller name as prefix. |
||
94 | * |
||
95 | * @param string[] $controllers |
||
96 | * @throws \ReflectionException |
||
97 | * @return Group |
||
98 | */ |
||
99 | |||
100 | 1 | public function controllersWithoutPrefix(array $controllers) |
|
107 | |||
108 | /** |
||
109 | * @param ReflectionClass $controller |
||
110 | * @param ReflectionMethod[] $methods |
||
111 | * @param string $prefix |
||
112 | * |
||
113 | * @return Group |
||
114 | */ |
||
115 | |||
116 | 7 | protected function collectControllerRoutes(ReflectionClass $controller, array $methods, $prefix) |
|
144 | |||
145 | /** |
||
146 | * @param ReflectionClass $controller |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | |||
151 | 4 | protected function getControllerPrefix(ReflectionClass $controller) |
|
156 | |||
157 | /** |
||
158 | * @param \ReflectionMethod |
||
159 | * @return string |
||
160 | */ |
||
161 | |||
162 | 7 | protected function getMethodConstraints(ReflectionMethod $method) |
|
182 | |||
183 | /** |
||
184 | * @param ReflectionParameter $parameter |
||
185 | * @param string[] $types |
||
186 | * @return string |
||
187 | */ |
||
188 | |||
189 | 7 | protected function getPathConstraint(ReflectionParameter $parameter, $types) |
|
195 | |||
196 | /** |
||
197 | * @param ReflectionMethod $method |
||
198 | * @return string[] |
||
199 | */ |
||
200 | |||
201 | 7 | protected function getParamsConstraint(ReflectionMethod $method) |
|
214 | |||
215 | /** |
||
216 | * @param ReflectionClass|ReflectionMethod $reflector |
||
217 | * @return string|null |
||
218 | */ |
||
219 | |||
220 | 7 | protected function getAnnotatedStrategy($reflector) |
|
225 | |||
226 | /** |
||
227 | * Define how controller actions names will be joined to form the route pattern. |
||
228 | * Defaults to "/" so actions like "getMyAction" will be "/my/action". If changed to |
||
229 | * "-" the new pattern will be "/my-action". |
||
230 | * |
||
231 | * @param string $join |
||
232 | */ |
||
233 | |||
234 | 1 | public function setControllerActionJoin($join) |
|
238 | |||
239 | /** |
||
240 | * @return string |
||
241 | */ |
||
242 | |||
243 | 1 | public function getControllerActionJoin() |
|
247 | |||
248 | } |
||
249 |