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: class ContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
25: {
26:
27: private $container;
28:
29:
30: public function __construct(Container $container)
31: {
32: if (PHP_VERSION_ID < 50300) {
33: throw new Nette\NotSupportedException(__CLASS__ . ' requires PHP 5.3 or newer.');
34: }
35: $this->container = $container;
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: public function getPanel()
56: {
57: $services = $this->getContainerProperty('factories');
58: $factories = array();
59: foreach (Nette\Reflection\ClassType::from($this->container)->getMethods() as $method) {
60: if (preg_match('#^create(Service)?_*(.+)\z#', $method->getName(), $m)) {
61: $name = str_replace('__', '.', strtolower(substr($m[2], 0, 1)) . substr($m[2], 1));
62: if ($m[1]) {
63: $services[$name] = $method->getAnnotation('return');
64: } elseif ($method->isPublic()) {
65: $a = strrpos(".$name", '.');
66: $factories[substr($name, 0, $a) . 'create' . ucfirst(substr($name, $a))] = $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: private function getContainerProperty($name)
82: {
83: $prop = Nette\Reflection\ClassType::from('Nette\DI\Container')->getProperty($name);
84: $prop->setAccessible(TRUE);
85: return $prop->getValue($this->container);
86: }
87:
88: }
89: