Total Complexity | 8 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
7 | trait PrioritizeTrait |
||
8 | { |
||
9 | use Helper; |
||
10 | |||
11 | protected function sortRoutes(): void |
||
12 | { |
||
13 | $staticRoutes = []; |
||
14 | $paramRoutes = []; |
||
15 | |||
16 | foreach($this->getRoutes() as $r => $route){ |
||
17 | |||
18 | $path = urldecode($route['uri']->getPath()); |
||
19 | |||
20 | if(strstr($path,'{')){ |
||
21 | $paramRoutes[$this->getKeyArray(substr_count($path,'/') + substr_count($path,'{'),$paramRoutes)] = $route; |
||
22 | continue; |
||
23 | } |
||
24 | |||
25 | $staticRoutes[$this->getKeyArray(substr_count($path,'/'),$staticRoutes)] = $route; |
||
26 | } |
||
27 | |||
28 | rsort($paramRoutes); |
||
29 | rsort($staticRoutes); |
||
30 | |||
31 | $this->orderRoutes(array_merge($staticRoutes,$paramRoutes)); |
||
32 | } |
||
33 | |||
34 | private function getKeyArray(int $index, array $array): int |
||
35 | { |
||
36 | while(array_key_exists($index,$array)){ |
||
37 | $index++; |
||
38 | } |
||
39 | return $index; |
||
40 | } |
||
41 | |||
42 | private function orderRoutes(array $routes):void |
||
53 | } |
||
54 | } |
||
55 |