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

Classes

  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  * @package Nette\DI\Diagnostics
 7:  */
 8: 
 9: 
10: 
11:  // used in templates
12: 
13: 
14: /**
15:  * Dependency injection container panel for Debugger Bar.
16:  *
17:  * @author     Patrik Votoček
18:  * @package Nette\DI\Diagnostics
19:  */
20: class NContainerPanel extends NObject implements IBarPanel
21: {
22:     /** @var NDIContainer */
23:     private $container;
24: 
25: 
26:     public function __construct(NDIContainer $container)
27:     {
28:         if (PHP_VERSION_ID < 50300) {
29:             throw new NotSupportedException(__CLASS__ . ' requires PHP 5.3 or newer.');
30:         }
31:         $this->container = $container;
32:     }
33: 
34: 
35:     /**
36:      * Renders tab.
37:      * @return string
38:      */
39:     public function getTab()
40:     {
41:         ob_start();
42:         require dirname(__FILE__) . '/templates/ContainerPanel.tab.phtml';
43:         return ob_get_clean();
44:     }
45: 
46: 
47:     /**
48:      * Renders panel.
49:      * @return string
50:      */
51:     public function getPanel()
52:     {
53:         $services = $this->getContainerProperty('factories');
54:         $factories = array();
55:         foreach (NClassReflection::from($this->container)->getMethods() as $method) {
56:             if (preg_match('#^create(Service)?_*(.+)\z#', $method->getName(), $m)) {
57:                 $name = str_replace('__', '.', strtolower(substr($m[2], 0, 1)) . substr($m[2], 1));
58:                 if ($m[1]) {
59:                     $services[$name] = $method->getAnnotation('return');
60:                 } elseif ($method->isPublic()) {
61:                     $a = strrpos(".$name", '.');
62:                     $factories[substr($name, 0, $a) . 'create' . ucfirst(substr($name, $a))] = $method->getAnnotation('return');
63:                 }
64:             }
65:         }
66:         ksort($services);
67:         ksort($factories);
68:         $container = $this->container;
69:         $registry = $this->getContainerProperty('registry');
70: 
71:         ob_start();
72:         require dirname(__FILE__) . '/templates/ContainerPanel.panel.phtml';
73:         return ob_get_clean();
74:     }
75: 
76: 
77:     private function getContainerProperty($name)
78:     {
79:         $prop = NClassReflection::from('NDIContainer')->getProperty($name);
80:         $prop->setAccessible(TRUE);
81:         return $prop->getValue($this->container);
82:     }
83: 
84: }
85: 
Nette Framework 2.0.18 (for PHP 5.2, prefixed) API documentation generated by ApiGen 2.8.0