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