1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19: 20:
21: class ContainerPanel extends Object implements IBarPanel
22: {
23:
24: private $container;
25:
26:
27:
28: public function __construct(DIContainer $container)
29: {
30: if (PHP_VERSION_ID < 50300) {
31: throw new NotSupportedException(__CLASS__ . ' requires PHP 5.3 or newer.');
32: }
33: $this->container = $container;
34: }
35:
36:
37:
38: 39: 40: 41:
42: public function getTab()
43: {
44: ob_start();
45: require dirname(__FILE__) . '/templates/ContainerPanel.tab.phtml';
46: return ob_get_clean();
47: }
48:
49:
50:
51: 52: 53: 54:
55: public function getPanel()
56: {
57: $services = $this->getContainerProperty('factories');
58: $factories = array();
59: foreach (ClassReflection::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 dirname(__FILE__) . '/templates/ContainerPanel.panel.phtml';
77: return ob_get_clean();
78: }
79:
80:
81:
82: private function getContainerProperty($name)
83: {
84: $prop = ClassReflection::from('DIContainer')->getProperty($name);
85: $prop->setAccessible(TRUE);
86: return $prop->getValue($this->container);
87: }
88:
89: }
90: