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