1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Bridges\DITracy;
9:
10: use Nette;
11: use Nette\DI\Container;
12: use Tracy;
13:
14:
15: 16: 17: 18: 19:
20: class ContainerPanel extends Nette\Object implements Tracy\IBarPanel
21: {
22:
23: private $container;
24:
25:
26: public function __construct(Container $container)
27: {
28: $this->container = $container;
29: }
30:
31:
32: 33: 34: 35:
36: public function getTab()
37: {
38: ob_start();
39: require __DIR__ . '/templates/ContainerPanel.tab.phtml';
40: return ob_get_clean();
41: }
42:
43:
44: 45: 46: 47:
48: public function getPanel()
49: {
50: $services = array();
51: foreach (Nette\Reflection\ClassType::from($this->container)->getMethods() as $method) {
52: if (preg_match('#^createService_*(.+)\z#', $method->getName(), $m)) {
53: $services[str_replace('__', '.', strtolower(substr($m[1], 0, 1)) . substr($m[1], 1))] = $method->getAnnotation('return');
54: }
55: }
56: ksort($services);
57: $container = $this->container;
58: $registry = $this->getContainerProperty('registry');
59: $tags = array();
60: $meta = $this->getContainerProperty('meta');
61: if (isset($meta[Container::TAGS])) {
62: foreach ($meta[Container::TAGS] as $tag => $tmp) {
63: foreach ($tmp as $service => $val) {
64: $tags[$service][$tag] = $val;
65: }
66: }
67: }
68:
69: ob_start();
70: require __DIR__ . '/templates/ContainerPanel.panel.phtml';
71: return ob_get_clean();
72: }
73:
74:
75: private function getContainerProperty($name)
76: {
77: $prop = Nette\Reflection\ClassType::from('Nette\DI\Container')->getProperty($name);
78: $prop->setAccessible(TRUE);
79: return $prop->getValue($this->container);
80: }
81:
82: }
83: