/
ContainerPanel.php
90 lines (72 loc) 路 2.02 KB
/
ContainerPanel.php
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
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Bridges\DITracy;
use Nette;
use Nette\DI\Container;
use Tracy;
/**
* Dependency injection container panel for Debugger Bar.
*/
class ContainerPanel implements Tracy\IBarPanel
{
use Nette\SmartObject;
/** @var float|null */
public static $compilationTime;
/** @var Nette\DI\Container */
private $container;
/** @var float|null */
private $elapsedTime;
public function __construct(Container $container)
{
$this->container = $container;
$this->elapsedTime = self::$compilationTime ? microtime(true) - self::$compilationTime : null;
}
/**
* Renders tab.
*/
public function getTab(): string
{
ob_start(function () {});
$elapsedTime = $this->elapsedTime;
require __DIR__ . '/templates/ContainerPanel.tab.phtml';
return ob_get_clean();
}
/**
* Renders panel.
*/
public function getPanel(): string
{
$container = $this->container;
$rc = new \ReflectionClass($container);
$file = $rc->getFileName();
$tags = [];
$instances = $this->getContainerProperty('instances');
$wiring = $this->getContainerProperty('wiring');
$types = [];
foreach ($rc->getMethods() as $method) {
if (preg_match('#^createService(.+)#', $method->getName(), $m) && $method->getReturnType()) {
$types[lcfirst(str_replace('__', '.', $m[1]))] = $method->getReturnType()->getName();
}
}
$types = $this->getContainerProperty('types') + $types;
ksort($types);
foreach ($this->getContainerProperty('tags') as $tag => $tmp) {
foreach ($tmp as $service => $val) {
$tags[$service][$tag] = $val;
}
}
ob_start(function () {});
require __DIR__ . '/templates/ContainerPanel.panel.phtml';
return ob_get_clean();
}
private function getContainerProperty(string $name)
{
$prop = (new \ReflectionClass(Nette\DI\Container::class))->getProperty($name);
$prop->setAccessible(true);
return $prop->getValue($this->container);
}
}