1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Bridges\DITracy;
9:
10: use Nette;
11: use Nette\DI\Container;
12: use Tracy;
13:
14:
15: /**
16: * Dependency injection container panel for Debugger Bar.
17: */
18: class ContainerPanel implements Tracy\IBarPanel
19: {
20: use Nette\SmartObject;
21:
22: /** @var int */
23: public static $compilationTime;
24:
25: /** @var Nette\DI\Container */
26: private $container;
27:
28: /** @var int|null */
29: private $elapsedTime;
30:
31:
32: public function __construct(Container $container)
33: {
34: $this->container = $container;
35: $this->elapsedTime = self::$compilationTime ? microtime(true) - self::$compilationTime : null;
36: }
37:
38:
39: /**
40: * Renders tab.
41: * @return string
42: */
43: public function getTab()
44: {
45: ob_start(function () {});
46: $elapsedTime = $this->elapsedTime;
47: require __DIR__ . '/templates/ContainerPanel.tab.phtml';
48: return ob_get_clean();
49: }
50:
51:
52: /**
53: * Renders panel.
54: * @return string
55: */
56: public function getPanel()
57: {
58: $container = $this->container;
59: $registry = $this->getContainerProperty('registry');
60: $file = (new \ReflectionClass($container))->getFileName();
61: $tags = [];
62: $meta = $this->getContainerProperty('meta');
63: $services = $meta[Container::SERVICES];
64: ksort($services);
65: if (isset($meta[Container::TAGS])) {
66: foreach ($meta[Container::TAGS] as $tag => $tmp) {
67: foreach ($tmp as $service => $val) {
68: $tags[$service][$tag] = $val;
69: }
70: }
71: }
72:
73: ob_start(function () {});
74: require __DIR__ . '/templates/ContainerPanel.panel.phtml';
75: return ob_get_clean();
76: }
77:
78:
79: private function getContainerProperty($name)
80: {
81: $prop = (new \ReflectionClass(Nette\DI\Container::class))->getProperty($name);
82: $prop->setAccessible(true);
83: return $prop->getValue($this->container);
84: }
85: }
86: