Skip to content

Commit f5ae981

Browse files
committed
RoutingPanel: supports withPath(...)
1 parent b89b3d6 commit f5ae981

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/Bridges/ApplicationTracy/RoutingPanel.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(
5757
*/
5858
public function getTab(): string
5959
{
60-
$this->analyse($this->router);
60+
$this->analyse($this->router, $this->httpRequest);
6161
return Nette\Utils\Helpers::capture(function () {
6262
$matched = $this->matched;
6363
require __DIR__ . '/templates/RoutingPanel.tab.phtml';
@@ -87,21 +87,33 @@ public function getPanel(): string
8787
*/
8888
private function analyse(
8989
Routing\Router $router,
90+
Nette\Http\IRequest $httpRequest,
9091
string $module = '',
92+
string $path = null,
9193
bool $parentMatches = true,
9294
int $level = -1,
9395
int $flag = 0
9496
): void {
9597
if ($router instanceof Routing\RouteList) {
9698
try {
97-
$parentMatches = $parentMatches && $router->match($this->httpRequest) !== null;
99+
$parentMatches = $parentMatches && $router->match($httpRequest) !== null;
98100
} catch (\Throwable $e) {
99101
}
102+
103+
$prop = (new \ReflectionProperty(Routing\RouteList::class, 'path'));
104+
$prop->setAccessible(true);
105+
if ($pathPrefix = $prop->getValue($router)) {
106+
$path .= $pathPrefix;
107+
$url = $httpRequest->getUrl();
108+
$httpRequest = $httpRequest->withUrl($url->withPath($url->getPath(), $url->getBasePath() . $pathPrefix));
109+
}
110+
111+
$module .= ($router instanceof Nette\Application\Routers\RouteList ? $router->getModule() : '');
112+
100113
$next = count($this->routers);
101-
$parentModule = $module . ($router instanceof Nette\Application\Routers\RouteList ? $router->getModule() : '');
102114
$flags = $router->getFlags();
103115
foreach ($router->getRouters() as $i => $subRouter) {
104-
$this->analyse($subRouter, $parentModule, $parentMatches, $level + 1, $flags[$i]);
116+
$this->analyse($subRouter, $httpRequest, $module, $path, $parentMatches, $level + 1, $flags[$i]);
105117
}
106118

107119
if ($info = $this->routers[$next] ?? null) {
@@ -117,7 +129,7 @@ private function analyse(
117129
$params = $e = null;
118130
try {
119131
$params = $parentMatches
120-
? $router->match($this->httpRequest)
132+
? $router->match($httpRequest)
121133
: null;
122134
} catch (\Throwable $e) {
123135
$matched = 'error';
@@ -142,6 +154,7 @@ private function analyse(
142154
'mask' => $router instanceof Routing\Route ? $router->getMask() : null,
143155
'params' => $params,
144156
'module' => rtrim($module, ':'),
157+
'path' => $path,
145158
'error' => $e,
146159
];
147160
}

src/Bridges/ApplicationTracy/templates/RoutingPanel.panel.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ use Tracy\Helpers;
8484
<td class="symbol" title="<?= Helpers::escapeHtml(['yes' => 'matched as first', 'may' => 'suitable but not matched as first', 'no' => '', 'oneway' => 'one-way', 'error' => 'error'][$router->matched]) ?>"
8585
><?= ['yes' => '', 'may' => '', 'no' => '', 'oneway' => '', 'error' => ''][$router->matched] ?></td>
8686

87-
<td><code title="<?= Helpers::escapeHtml($router->class) ?>"><?= isset($router->mask) ? str_replace(['/', '-'], ['<wbr>/', '<wbr>-'], Helpers::escapeHtml($router->mask)) : str_replace('\\', '<wbr>\\', Helpers::escapeHtml($router->class)) ?></code></td>
87+
<td><code title="<?= Helpers::escapeHtml($router->class) ?>"><?=
88+
isset($router->path) ? '<small>' . Helpers::escapeHtml($router->path) . '</small>' : '',
89+
isset($router->mask) ? str_replace(['/', '-'], ['<wbr>/', '<wbr>-'], Helpers::escapeHtml($router->mask)) : str_replace('\\', '<wbr>\\', Helpers::escapeHtml($router->class))
90+
?></code></td>
8891

8992
<td><code>
9093
<?php foreach ($router->defaults as $key => $value): ?>

0 commit comments

Comments
 (0)