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