1 | <?php |
||
2 | |||
3 | namespace MinasRouter\Helpers; |
||
4 | |||
5 | use MinasRouter\Router\Route; |
||
6 | |||
7 | class Functions |
||
8 | { |
||
9 | /** |
||
10 | * Method responsible for returning the |
||
11 | * active RouteCollection instance. |
||
12 | * |
||
13 | * @return null|\MinasRouter\Router\RouteCollection |
||
14 | */ |
||
15 | protected function collection() |
||
16 | { |
||
17 | return Route::$collection; |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * Method responsible for returning a route. |
||
22 | * |
||
23 | * @param string $name |
||
24 | * |
||
25 | * @return null|\MinasRouter\Router\RouteManager |
||
26 | */ |
||
27 | public function get(String $routerName) |
||
28 | { |
||
29 | return $this->collection()->getByName($routerName); |
||
30 | } |
||
31 | |||
32 | public function getStructuredRoute(String $routerName, $params) |
||
0 ignored issues
–
show
|
|||
33 | { |
||
34 | $params = (array) func_get_arg(1); |
||
35 | |||
36 | if(!$router = $this->get($routerName)) { |
||
37 | return null; |
||
38 | } |
||
39 | |||
40 | $originalRoute = $router->getOriginalRoute(); |
||
41 | |||
42 | preg_match_all("/{\w+\??}/", $originalRoute, $matches); |
||
43 | |||
44 | if(empty($matches[0])) { |
||
45 | return $originalRoute; |
||
46 | } |
||
47 | |||
48 | if(count($matches[0]) != count($params)) { |
||
49 | return null; |
||
50 | } |
||
51 | |||
52 | foreach($matches[0] as $index => $match) { |
||
53 | $paramForReplace = isset($params[$index]) ? $params[$index] : 'undefined'; |
||
54 | |||
55 | $originalRoute = str_replace($match, $paramForReplace, $originalRoute); |
||
56 | } |
||
57 | |||
58 | return $originalRoute; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Method responsible for returning the |
||
63 | * current route. |
||
64 | * |
||
65 | * @return null|\MinasRouter\Router\RouteManager |
||
66 | */ |
||
67 | public function current() |
||
68 | { |
||
69 | return $this->collection()->getCurrentRoute(); |
||
70 | } |
||
71 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.