-
Notifications
You must be signed in to change notification settings - Fork 565
Expand file tree
/
Copy pathroutes_panel.php
More file actions
96 lines (86 loc) · 3.3 KB
/
Copy pathroutes_panel.php
File metadata and controls
96 lines (86 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @var \Cake\Routing\Route\Route[] $routes
* @var string $matchedRoute
*/
use Cake\Core\Plugin as CorePlugin;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use function Cake\Core\h;
$routes = Cake\Routing\Router::routes();
$amountOfRoutesPerGroup = $duplicateRoutes = [];
foreach ($routes as $route) {
// Count the amount
$group = $route->defaults['plugin'] ?? 'app';
if (!array_key_exists($group, $amountOfRoutesPerGroup)) {
$amountOfRoutesPerGroup[$group] = 0;
}
$amountOfRoutesPerGroup[$group]++;
if (!array_key_exists($route->template, $duplicateRoutes)) {
$duplicateRoutes[$route->template] = 0;
}
$duplicateRoutes[$route->template]++;
}
$pluginNames = [];
foreach (CorePlugin::loaded() as $pluginName) {
if (!empty($amountOfRoutesPerGroup[$pluginName])) {
$name = sprintf('%s (%s)', $pluginName, $amountOfRoutesPerGroup[$pluginName]);
$pluginNames[$name] = Text::slug($pluginName);
}
}
?>
<div class="c-routes-panel">
<div class="c-routes-panel__button-wrapper">
<button type="button" class="o-button js-toggle-plugin-route" data-plugin=".c-routes-panel__route-entry--app">
App
<?= !empty($amountOfRoutesPerGroup['app']) ? ' (' . $amountOfRoutesPerGroup['app'] . ')' : '' ?>
</button>
<?php foreach ($pluginNames as $pluginName => $parsedName) : ?>
<button type="button" class="o-button js-toggle-plugin-route <?=
strpos($pluginName, 'DebugKit') === 0 ? ' is-active' : '' ?>"
data-plugin=".c-routes-panel__route-entry--plugin-<?= $parsedName ?>">
<?= $pluginName ?>
</button>
<?php endforeach; ?>
</div>
<table class="c-debug-table">
<thead>
<tr>
<th>Route name</th>
<th class="u-text-left">URI template</th>
<th class="u-text-left">Defaults</th>
</tr>
</thead>
<tbody>
<?php foreach ($routes as $route) : ?>
<?php
$class = '';
if (empty($route->defaults['plugin'])) :
$class = 'c-routes-panel__route-entry c-routes-panel__route-entry--app';
else :
$class = 'c-routes-panel__route-entry ' .
'c-routes-panel__route-entry--plugin c-routes-panel__route-entry--plugin-' .
Text::slug($route->defaults['plugin']);
// Hide DebugKit internal routes by default
if ($route->defaults['plugin'] === 'DebugKit') {
$class .= ' is-hidden';
}
endif;
// Highlight current route
if ($matchedRoute === $route->template) {
$class .= ' highlighted';
}
// Mark duplicate routes
if ($duplicateRoutes[$route->template] > 1) {
$class .= ' duplicate-route';
}
?>
<tr class="<?= $class ?>">
<td><?= h(Hash::get($route->options, '_name', $route->getName())) ?></td>
<td class="u-text-left"><?= h($route->template) ?></td>
<td class="u-text-left"><pre><?= json_encode($route->defaults, JSON_PRETTY_PRINT) ?></pre></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>