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:  * Dependency injection container panel for Debugger Bar.
21:  *
22:  * @author     Patrik Votoček
23:  */
24: class ContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
25: {
26:     /** @var Nette\DI\Container */
27:     private $container;
28: 
29: 
30:     public function __construct(Container $container)
31:     {
32:         if (PHP_VERSION_ID < 50300) {
33:             throw new Nette\NotSupportedException(__CLASS__ . ' requires PHP 5.3 or newer.');
34:         }
35:         $this->container = $container;
36:     }
37: 
38: 
39:     /**
40:      * Renders tab.
41:      * @return string
42:      */
43:     public function getTab()
44:     {
45:         ob_start();
46:         require __DIR__ . '/templates/ContainerPanel.tab.phtml';
47:         return ob_get_clean();
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 (Nette\Reflection\ClassType::from($this->container)->getMethods() as $method) {
60:             if (preg_match('#^create(Service)?_*(.+)\z#', $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 __DIR__ . '/templates/ContainerPanel.panel.phtml';
77:         return ob_get_clean();
78:     }
79: 
80: 
81:     private function getContainerProperty($name)
82:     {
83:         $prop = Nette\Reflection\ClassType::from('Nette\DI\Container')->getProperty($name);
84:         $prop->setAccessible(TRUE);
85:         return $prop->getValue($this->container);
86:     }
87: 
88: }
89: 
Nette Framework 2.0.12 API API documentation generated by ApiGen 2.8.0