1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ZfDebugModule. Console commands and other utilities for debugging ZF2 apps. |
4
|
|
|
* |
5
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
6
|
|
|
* @copyright 2016 Vítor Brandão <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Noiselabs\ZfDebugModule\Util\Routing; |
10
|
|
|
|
11
|
|
|
use Zend\Mvc\Router\RouteInterface; |
12
|
|
|
|
13
|
|
|
class RouteCollectionBuilder |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var RouteInterface |
17
|
|
|
*/ |
18
|
|
|
private $routes; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* RoutesInspector constructor. |
22
|
|
|
* |
23
|
|
|
* @param array $routes |
24
|
|
|
*/ |
25
|
|
|
public function __construct(array $routes = []) |
26
|
|
|
{ |
27
|
|
|
$this->routes = $routes; |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return RouteCollection |
32
|
|
|
*/ |
33
|
|
|
public function build() |
34
|
|
|
{ |
35
|
|
|
$routeCollection = new FlatRouteCollection(); |
36
|
|
|
$this->processRoutes($routeCollection, $this->routes); |
|
|
|
|
37
|
|
|
|
38
|
|
|
return $routeCollection; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param FlatRouteCollection $routeCollection |
43
|
|
|
* @param array $routesConfig |
44
|
|
|
* @param array $parentRoutesConfig |
45
|
|
|
*/ |
46
|
|
|
private function processRoutes(FlatRouteCollection $routeCollection, array $routesConfig, array $parentRoutesConfig = null) |
47
|
|
|
{ |
48
|
|
|
foreach (array_keys($routesConfig) as $k) { |
49
|
|
|
$routeName = $k; |
50
|
|
|
$routeUrl = isset($routesConfig[$k]['options']['route']) ? $routesConfig[$k]['options']['route'] : ''; |
51
|
|
|
|
52
|
|
|
if (!empty($parentRoutesConfig)) { |
53
|
|
|
$pk = key($parentRoutesConfig); |
54
|
|
|
|
55
|
|
|
$routeName = $pk . '/' . $routeName; |
56
|
|
|
if (isset($parentRoutesConfig[$pk]['options']['route'])) { |
57
|
|
|
$routeUrl = $parentRoutesConfig[$pk]['options']['route'] . $routeUrl; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$controller = isset($routesConfig[$k]['options']['defaults']['controller']) |
62
|
|
|
? $routesConfig[$k]['options']['defaults']['controller'] : null; |
63
|
|
|
$action = isset($routesConfig[$k]['options']['defaults']['action']) |
64
|
|
|
? $routesConfig[$k]['options']['defaults']['action'] : null; |
65
|
|
|
$route = new Route($routeName, $routeUrl, $controller, $action); |
66
|
|
|
$routeCollection->addRoute($route); |
67
|
|
|
|
68
|
|
|
if (isset($routesConfig[$k]['child_routes']) && !empty($routesConfig[$k]['child_routes'])) { |
69
|
|
|
$childRoutes = $routesConfig[$k]['child_routes']; |
70
|
|
|
unset($routesConfig[$k]['child_routes']); |
71
|
|
|
$this->processRoutes($routeCollection, $childRoutes, [$k => $routesConfig[$k]]); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..