Skip to content

Commit

Permalink
RoutingPanel: withPath() fix II.
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 15, 2022
1 parent fa5da6a commit a8449f4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,24 @@ public function getPanel(): string
*/
private function analyse(
Routing\Router $router,
Nette\Http\IRequest $httpRequest,
?Nette\Http\IRequest $httpRequest,
string $module = '',
?string $path = null,
bool $parentMatches = true,
int $level = -1,
int $flag = 0
): void {
if ($router instanceof Routing\RouteList) {
try {
$parentMatches = $parentMatches && $router->match($httpRequest) !== null;
} catch (\Throwable $e) {
if ($httpRequest) {
try {
$httpRequest = $router->match($httpRequest) === null ? null : $httpRequest;
} catch (\Throwable $e) {
$httpRequest = null;
}
}

$prop = (new \ReflectionProperty(Routing\RouteList::class, 'path'));
$prop->setAccessible(true);
if ($pathPrefix = $prop->getValue($router)) {
if ($httpRequest && ($pathPrefix = $prop->getValue($router))) {
$path .= $pathPrefix;
$url = $httpRequest->getUrl();
$httpRequest = $httpRequest->withUrl($url->withPath($url->getPath(), $url->getBasePath() . $pathPrefix));
Expand All @@ -113,7 +115,7 @@ private function analyse(
$next = count($this->routers);
$flags = $router->getFlags();
foreach ($router->getRouters() as $i => $subRouter) {
$this->analyse($subRouter, $httpRequest, $module, $path, $parentMatches, $level + 1, $flags[$i]);
$this->analyse($subRouter, $httpRequest, $module, $path, $level + 1, $flags[$i]);
}

if ($info = $this->routers[$next] ?? null) {
Expand All @@ -130,7 +132,7 @@ private function analyse(
$matched = $flag & Routing\RouteList::ONE_WAY ? 'oneway' : 'no';
$params = $e = null;
try {
$params = $parentMatches
$params = $httpRequest
? $router->match($httpRequest)
: null;
} catch (\Throwable $e) {
Expand Down

0 comments on commit a8449f4

Please sign in to comment.