Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • ContainerPanel
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  *
 6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  */
11: 
12: namespace Nette\DI\Diagnostics;
13: 
14: use Nette,
15:     Nette\DI\Container,
16:     Nette\Diagnostics\Helpers;
17: 
18: 
19: 
20: /**
21:  * Dependency injection container panel for Debugger Bar.
22:  *
23:  * @author     Patrik Votoček
24:  */
25: class ContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
26: {
27:     /** @var Nette\DI\Container */
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:      * Renders tab.
44:      * @return string
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:      * Renders panel.
57:      * @return string
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)?(.+)\z#', $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: 
Nette Framework 2.0.8 API API documentation generated by ApiGen 2.8.0