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: if (PHP_VERSION_ID < 50300) {
35: throw new Nette\NotSupportedException(__CLASS__ . ' requires PHP 5.3 or newer.');
36: }
37: $this->container = $container;
38: }
39:
40:
41:
42: 43: 44: 45:
46: public function getTab()
47: {
48: ob_start();
49: require __DIR__ . '/templates/ContainerPanel.tab.phtml';
50: return ob_get_clean();
51: }
52:
53:
54:
55: 56: 57: 58:
59: public function getPanel()
60: {
61: $services = $this->getContainerProperty('factories');
62: $factories = array();
63: foreach (Nette\Reflection\ClassType::from($this->container)->getMethods() as $method) {
64: if (preg_match('#^create(Service)?(.+)$#', $method->getName(), $m)) {
65: $name = str_replace('__', '.', strtolower(substr($m[2], 0, 1)) . substr($m[2], 1));
66: if ($m[1]) {
67: $services[$name] = $method->getAnnotation('return');
68: } elseif ($method->isPublic()) {
69: $a = strrpos(".$name", '.');
70: $factories[substr($name, 0, $a) . 'create' . ucfirst(substr($name, $a))] = $method->getAnnotation('return');
71: }
72: }
73: }
74: ksort($services);
75: ksort($factories);
76: $container = $this->container;
77: $registry = $this->getContainerProperty('registry');
78:
79: ob_start();
80: require __DIR__ . '/templates/ContainerPanel.panel.phtml';
81: return ob_get_clean();
82: }
83:
84:
85:
86: private function getContainerProperty($name)
87: {
88: $prop = Nette\Reflection\ClassType::from('Nette\DI\Container')->getProperty($name);
89: $prop->setAccessible(TRUE);
90: return $prop->getValue($this->container);
91: }
92:
93: }
94: