1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ZfDebugModule. WebUI and Console commands 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; |
10
|
|
|
|
11
|
|
|
use Zend\Console\Adapter\AdapterInterface as Console; |
12
|
|
|
use Zend\EventManager\EventInterface; |
13
|
|
|
use Zend\ModuleManager\Feature\BootstrapListenerInterface; |
14
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
15
|
|
|
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface; |
16
|
|
|
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface; |
17
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
18
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
19
|
|
|
use Zend\Mvc\MvcEvent; |
20
|
|
|
use Zend\Mvc\Router\RouteInterface; |
21
|
|
|
use Zend\Mvc\Router\RouteMatch; |
22
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
23
|
|
|
use Zend\Stdlib\RequestInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* ZfDebug Module. |
27
|
|
|
* |
28
|
|
|
* @author Vítor Brandão <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class Module implements BootstrapListenerInterface, ConfigProviderInterface, ConsoleBannerProviderInterface, |
|
|
|
|
31
|
|
|
ConsoleUsageProviderInterface, InitProviderInterface |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
const DEFAULT_LAYOUT = 'noiselabs/zf-debug-utils/layout'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
10 |
|
public function init(ModuleManagerInterface $manager) |
39
|
|
|
{ |
40
|
10 |
|
$manager->loadModule('AssetManager'); |
41
|
10 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
11 |
|
public function getConfig() |
47
|
|
|
{ |
48
|
11 |
|
return require __DIR__ . '/Resources/config/module.config.php'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Listen to the bootstrap event. |
53
|
|
|
* |
54
|
|
|
* @param EventInterface|MvcEvent $e |
55
|
|
|
* |
56
|
|
|
* @return array|void |
57
|
|
|
*/ |
58
|
11 |
|
public function onBootstrap(EventInterface $e) |
59
|
|
|
{ |
60
|
11 |
|
if (!$e instanceof MvcEvent) { |
61
|
1 |
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
10 |
|
$currentRouteName = $this->getCurrentRouteName($e->getApplication()->getServiceManager()); |
65
|
10 |
|
$e->getViewModel()->setVariables(['__currentRouteName' => $currentRouteName]); |
66
|
10 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
* |
71
|
|
|
* @param Console $console |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
1 |
|
public function getConsoleBanner(Console $console) |
76
|
|
|
{ |
77
|
1 |
|
return sprintf('%s v%s', Package::NAME, Package::VERSION); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param Console $console |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
1 |
|
public function getConsoleUsage(Console $console) |
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
1 |
|
'[ Routing ]', |
89
|
1 |
|
'', |
90
|
1 |
|
'zfdebug routes export' => 'Exports all routes in CSV format', |
91
|
1 |
|
'zfdebug routes list' => 'Lists all routes', |
92
|
1 |
|
'zfdebug routes match [METHOD] [URL]' => 'Matches a URL to a Route', |
93
|
1 |
|
['Examples:'], |
94
|
1 |
|
['$ zfdebug routes export', ''], |
95
|
1 |
|
['$ zfdebug routes list', ''], |
96
|
1 |
|
['$ zfdebug routes match GET /users/123', ''], |
97
|
1 |
|
['$ zfdebug routes match POST /login', ''], |
98
|
1 |
|
]; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
103
|
|
|
* |
104
|
|
|
* @return null|string |
105
|
|
|
*/ |
106
|
10 |
|
private function getCurrentRouteName(ServiceLocatorInterface $serviceLocator) |
107
|
|
|
{ |
108
|
|
|
/** @var RouteInterface $router */ |
109
|
10 |
|
$router = $serviceLocator->get('router'); |
110
|
|
|
/** @var RequestInterface $request */ |
111
|
10 |
|
$request = $serviceLocator->get('request'); |
112
|
|
|
/** @var RouteMatch|null $matchedRoute */ |
113
|
10 |
|
$matchedRoute = $router->match($request); |
114
|
|
|
|
115
|
10 |
|
return ($matchedRoute instanceof RouteMatch) ? $matchedRoute->getMatchedRouteName() : null; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|