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\Controller\Http; |
10
|
|
|
|
11
|
|
|
use Noiselabs\ZfDebugModule\Module; |
12
|
|
|
use Noiselabs\ZfDebugModule\Package; |
13
|
|
|
use Noiselabs\ZfDebugModule\Util\Routing\RouteCollection; |
14
|
|
|
use Noiselabs\ZfDebugModule\Util\Routing\RouteMatcher; |
15
|
|
|
use Zend\Http\Request; |
16
|
|
|
use Zend\Http\Response; |
17
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
18
|
|
|
use Zend\View\Model\JsonModel; |
19
|
|
|
use Zend\View\Model\ViewModel; |
20
|
|
|
|
21
|
|
|
class RoutesController extends AbstractActionController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var RouteCollection |
25
|
|
|
*/ |
26
|
|
|
private $routeCollection; |
27
|
|
|
/** |
28
|
|
|
* @var RouteMatcher |
29
|
|
|
*/ |
30
|
|
|
private $routeMatcher; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* RoutesController constructor. |
34
|
|
|
* |
35
|
|
|
* @param RouteCollection $routeCollection |
36
|
|
|
* @param RouteMatcher $routeMatcher |
37
|
|
|
*/ |
38
|
5 |
|
public function __construct(RouteCollection $routeCollection, RouteMatcher $routeMatcher) |
39
|
|
|
{ |
40
|
5 |
|
$this->routeCollection = $routeCollection; |
41
|
5 |
|
$this->routeMatcher = $routeMatcher; |
42
|
5 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return Response |
46
|
|
|
*/ |
47
|
1 |
|
public function indexAction() |
48
|
|
|
{ |
49
|
1 |
|
return $this->redirect()->toRoute(Package::NAME . '/routes/list'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return ViewModel |
54
|
|
|
*/ |
55
|
1 |
|
public function listAllAction() |
56
|
|
|
{ |
57
|
1 |
|
$this->layout(Module::DEFAULT_LAYOUT); |
58
|
1 |
|
$view = new ViewModel([ |
59
|
1 |
|
'routeCollection' => $this->routeCollection, |
60
|
1 |
|
]); |
61
|
1 |
|
$view->setTemplate(Package::FQPN . '/routes/list-all'); |
62
|
|
|
|
63
|
1 |
|
return $view; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return ViewModel |
68
|
|
|
*/ |
69
|
1 |
|
public function renderMatchRouteViewAction() |
70
|
|
|
{ |
71
|
1 |
|
$this->layout(Module::DEFAULT_LAYOUT); |
72
|
1 |
|
$view = new ViewModel(); |
73
|
1 |
|
$view->setTemplate(Package::FQPN . '/routes/match'); |
74
|
|
|
|
75
|
1 |
|
return $view; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return JsonModel |
80
|
|
|
*/ |
81
|
1 |
|
public function matchRouteAction() |
82
|
|
|
{ |
83
|
1 |
|
$data = $this->params()->fromQuery(); |
84
|
1 |
|
$route = null; |
85
|
1 |
|
if (isset($data['method']) && !empty($data['method']) && isset($data['url']) && !empty($data['url'])) { |
86
|
1 |
|
if (null !== ($routeName = $this->routeMatcher->match($data['method'], $data['url']))) { |
87
|
1 |
|
$route = $this->routeCollection->getRoute($routeName); |
88
|
|
|
$route = [ |
89
|
1 |
|
'name' => $route->getName(), |
90
|
1 |
|
'url' => $route->getUrl(), |
91
|
1 |
|
'controller' => $route->getController(), |
92
|
1 |
|
'action' => $route->getAction(), |
93
|
1 |
|
]; |
94
|
1 |
|
} |
95
|
1 |
|
} |
96
|
|
|
|
97
|
1 |
|
return new JsonModel(['requestedRouteData' => $data, 'routeMatch' => $route]); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|