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

Classes

  • ContainerPanel
  • Overview
  • Namespace
  • 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:  */
 7: 
 8: namespace Nette\DI\Diagnostics;
 9: 
10: use Nette,
11:     Nette\DI\Container,
12:     Nette\Diagnostics\Helpers; // used in templates
13: 
14: 
15: /**
16:  * Dependency injection container panel for Debugger Bar.
17:  *
18:  * @author     Patrik Votoček
19:  */
20: class ContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
21: {
22:     /** @var Nette\DI\Container */
23:     private $container;
24: 
25: 
26:     public function __construct(Container $container)
27:     {
28:         if (PHP_VERSION_ID < 50300) {
29:             throw new Nette\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 __DIR__ . '/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 (Nette\Reflection\ClassType::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 __DIR__ . '/templates/ContainerPanel.panel.phtml';
73:         return ob_get_clean();
74:     }
75: 
76: 
77:     private function getContainerProperty($name)
78:     {
79:         $prop = Nette\Reflection\ClassType::from('Nette\DI\Container')->getProperty($name);
80:         $prop->setAccessible(TRUE);
81:         return $prop->getValue($this->container);
82:     }
83: 
84: }
85: 
Nette 2.0 API documentation generated by ApiGen 2.8.0