Packages

  • 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
  • Package
  • 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:  * @package Nette\DI\Diagnostics
11:  */
12: 
13: 
14: 
15: /**
16:  * Dependency injection container panel for Debugger Bar.
17:  *
18:  * @author     Patrik Votoček
19:  * @package Nette\DI\Diagnostics
20:  */
21: class ContainerPanel extends Object implements IBarPanel
22: {
23:     /** @var DIContainer */
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:      * Renders tab.
38:      * @return string
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:      * Renders panel.
50:      * @return string
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: 
Nette Framework 2.0.11 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0