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

  • NContainerPanel
  • Overview
  • Package
  • Class
  • Tree
 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 NContainerPanel extends NObject implements IBarPanel
22: {
23:     /** @var NDIContainer */
24:     private $container;
25: 
26: 
27: 
28:     public function __construct(NDIContainer $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:      * Renders tab.
40:      * @return string
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:      * Renders panel.
53:      * @return string
54:      */
55:     public function getPanel()
56:     {
57:         $services = $this->getContainerProperty('factories');
58:         $factories = array();
59:         foreach (NClassReflection::from($this->container)->getMethods() as $method) {
60:             if (preg_match('#^create(Service)?(.+)$#', $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 = NClassReflection::from('NDIContainer')->getProperty($name);
85:         $prop->setAccessible(TRUE);
86:         return $prop->getValue($this->container);
87:     }
88: 
89: }
90: 
Nette Framework 2.0.4 (for PHP 5.2, prefixed) API API documentation generated by ApiGen 2.7.0