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