Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • ConstantsExtension
  • DecoratorExtension
  • DIExtension
  • ExtensionsExtension
  • InjectExtension
  • PhpExtension
  • 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 (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\DI\Extensions;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * DI extension.
15:  */
16: class DIExtension extends Nette\DI\CompilerExtension
17: {
18:     public $defaults = array(
19:         'debugger' => FALSE,
20:         'accessors' => FALSE,
21:     );
22: 
23:     /** @var bool */
24:     private $debugMode;
25: 
26:     /** @var int */
27:     private $time;
28: 
29: 
30:     public function __construct($debugMode = FALSE)
31:     {
32:         $this->debugMode = $debugMode;
33:         $this->time = microtime(TRUE);
34:     }
35: 
36: 
37:     public function loadConfiguration()
38:     {
39:         $config = $this->validateConfig($this->defaults);
40:         if ($config['accessors']) {
41:             $this->getContainerBuilder()->parameters['container']['accessors'] = TRUE;
42:         }
43:     }
44: 
45: 
46:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
47:     {
48:         $initialize = $class->getMethod('initialize');
49:         $container = $this->getContainerBuilder();
50: 
51:         if ($this->debugMode && $this->config['debugger']) {
52:             Nette\Bridges\DITracy\ContainerPanel::$compilationTime = $this->time;
53:             $initialize->addBody($container->formatPhp('?;', array(
54:                 new Nette\DI\Statement('@Tracy\Bar::addPanel', array(new Nette\DI\Statement('Nette\Bridges\DITracy\ContainerPanel'))),
55:             )));
56:         }
57: 
58:         foreach (array_filter($container->findByTag('run')) as $name => $on) {
59:             $initialize->addBody('$this->getService(?);', array($name));
60:         }
61: 
62:         if (!empty($this->config['accessors'])) {
63:             $definitions = $container->getDefinitions();
64:             ksort($definitions);
65:             foreach ($definitions as $name => $def) {
66:                 if (Nette\PhpGenerator\Helpers::isIdentifier($name)) {
67:                     $type = $def->getImplement() ?: $def->getClass();
68:                     $class->addComment("@property $type \$$name");
69:                 }
70:             }
71:         }
72:     }
73: 
74: }
75: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0