|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Biurad opensource projects. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
|
7
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Flange\Debug\Tracy; |
|
14
|
|
|
|
|
15
|
|
|
use Biurad\Http\Uri; |
|
16
|
|
|
use Flight\Routing\Router; |
|
17
|
|
|
use Nette; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
20
|
|
|
use Tracy; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Routing debugger for Debug Bar. |
|
24
|
|
|
*/ |
|
25
|
|
|
final class RoutesPanel implements Tracy\IBarPanel |
|
26
|
|
|
{ |
|
27
|
|
|
use Nette\SmartObject; |
|
28
|
|
|
|
|
29
|
|
|
private int $routeCount = 0; |
|
30
|
|
|
private ?Request $request; |
|
31
|
|
|
|
|
32
|
|
|
/** @var array<int,mixed> */ |
|
33
|
|
|
private array $routes = []; |
|
34
|
|
|
|
|
35
|
|
|
/** @var \ReflectionClass|\ReflectionFunction|\ReflectionMethod|string */ |
|
36
|
|
|
private ?\Reflector $source = null; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function __construct(private Router $profiler, RequestStack $request) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->request = $request->getMainRequest(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Renders tab. |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getTab(): string |
|
47
|
|
|
{ |
|
48
|
|
|
foreach ($this->profiler->getCollection()->getRoutes() as $route) { |
|
49
|
|
|
$this->processData($route); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return Nette\Utils\Helpers::capture(function (): void { |
|
53
|
|
|
require __DIR__.'/templates/RoutingPanel.tab.phtml'; |
|
54
|
|
|
}); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Renders panel. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getPanel(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return Nette\Utils\Helpers::capture(function (): void { |
|
63
|
|
|
require __DIR__.'/templates/RoutingPanel.panel.phtml'; |
|
64
|
|
|
}); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function processData($profile): void |
|
68
|
|
|
{ |
|
69
|
|
|
++$this->routeCount; |
|
70
|
|
|
$data = ['matched' => false, 'route' => $profile, 'name' => \is_array($profile) ? $profile['name'] ?? 'unnamed' : $profile->getName() ?? 'unnamed']; |
|
71
|
|
|
|
|
72
|
|
|
if (null !== ($r = $this->request) && $profile === $this->profiler->match($r->getMethod(), new Uri($r->getUri()))) { |
|
73
|
|
|
$data['matched'] = true; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->routes[] = $data; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|