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
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

  • ConstantsExtension
  • DecoratorExtension
  • DIExtension
  • ExtensionsExtension
  • InjectExtension
  • PhpExtension
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
 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 = [
19:         'debugger' => true,
20:         'accessors' => false,
21:         'excluded' => [],
22:         'parentClass' => null,
23:     ];
24: 
25:     /** @var bool */
26:     private $debugMode;
27: 
28:     /** @var int */
29:     private $time;
30: 
31: 
32:     public function __construct($debugMode = false)
33:     {
34:         $this->debugMode = $debugMode;
35:         $this->time = microtime(true);
36:     }
37: 
38: 
39:     public function loadConfiguration()
40:     {
41:         $config = $this->validateConfig($this->defaults);
42:         $builder = $this->getContainerBuilder();
43:         $builder->addExcludedClasses($config['excluded']);
44:     }
45: 
46: 
47:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
48:     {
49:         if ($this->config['parentClass']) {
50:             $class->setExtends($this->config['parentClass']);
51:         }
52: 
53:         $initialize = $class->getMethod('initialize');
54:         $builder = $this->getContainerBuilder();
55: 
56:         if ($this->debugMode && $this->config['debugger']) {
57:             Nette\Bridges\DITracy\ContainerPanel::$compilationTime = $this->time;
58:             $initialize->addBody($builder->formatPhp('?;', [
59:                 new Nette\DI\Statement('@Tracy\Bar::addPanel', [new Nette\DI\Statement(Nette\Bridges\DITracy\ContainerPanel::class)]),
60:             ]));
61:         }
62: 
63:         foreach (array_filter($builder->findByTag('run')) as $name => $on) {
64:             $initialize->addBody('$this->getService(?);', [$name]);
65:         }
66:     }
67: }
68: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0