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 extends Nette\Object implements Tracy\IBarPanel
19: {
20: /** @var int */
21: public static $compilationTime;
22:
23: /** @var Nette\DI\Container */
24: private $container;
25:
26: /** @var int|NULL */
27: private $elapsedTime;
28:
29:
30: public function __construct(Container $container)
31: {
32: $this->container = $container;
33: $this->elapsedTime = self::$compilationTime ? microtime(TRUE) - self::$compilationTime : NULL;
34: }
35:
36:
37: /**
38: * Renders tab.
39: * @return string
40: */
41: public function getTab()
42: {
43: ob_start(function () {});
44: $elapsedTime = $this->elapsedTime;
45: require __DIR__ . '/templates/ContainerPanel.tab.phtml';
46: return ob_get_clean();
47: }
48:
49:
50: /**
51: * Renders panel.
52: * @return string
53: */
54: public function getPanel()
55: {
56: $container = $this->container;
57: $registry = $this->getContainerProperty('registry');
58: $rc = new \ReflectionClass($container);
59: $file = $rc->getFileName();
60: $tags = array();
61: $meta = $this->getContainerProperty('meta');
62: $services = $meta[Container::SERVICES];
63: ksort($services);
64: if (isset($meta[Container::TAGS])) {
65: foreach ($meta[Container::TAGS] as $tag => $tmp) {
66: foreach ($tmp as $service => $val) {
67: $tags[$service][$tag] = $val;
68: }
69: }
70: }
71:
72: ob_start(function () {});
73: require __DIR__ . '/templates/ContainerPanel.panel.phtml';
74: return ob_get_clean();
75: }
76:
77:
78: private function getContainerProperty($name)
79: {
80: $rc = new \ReflectionClass('Nette\DI\Container');
81: $prop = $rc->getProperty($name);
82: $prop->setAccessible(TRUE);
83: return $prop->getValue($this->container);
84: }
85:
86: }
87: