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
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • ConstantsExtension
  • DecoratorExtension
  • DIExtension
  • ExtensionsExtension
  • InjectExtension
  • PhpExtension
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\DI\Extensions;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * DI extension.
15:  *
16:  * @author     David Grudl
17:  */
18: class DIExtension extends Nette\DI\CompilerExtension
19: {
20:     public $defaults = array(
21:         'debugger' => FALSE,
22:         'accessors' => FALSE,
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:         if ($config['accessors']) {
43:             $this->getContainerBuilder()->parameters['container']['accessors'] = TRUE;
44:         }
45:     }
46: 
47: 
48:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
49:     {
50:         $initialize = $class->getMethod('initialize');
51:         $container = $this->getContainerBuilder();
52: 
53:         if ($this->debugMode && $this->config['debugger']) {
54:             Nette\Bridges\DITracy\ContainerPanel::$compilationTime = $this->time;
55:             $initialize->addBody($container->formatPhp('?;', array(
56:                 new Nette\DI\Statement('@Tracy\Bar::addPanel', array(new Nette\DI\Statement('Nette\Bridges\DITracy\ContainerPanel')))
57:             )));
58:         }
59: 
60:         foreach (array_filter($container->findByTag('run')) as $name => $on) {
61:             $initialize->addBody('$this->getService(?);', array($name));
62:         }
63: 
64:         if (!empty($this->config['accessors'])) {
65:             $definitions = $container->getDefinitions();
66:             ksort($definitions);
67:             foreach ($definitions as $name => $def) {
68:                 if (Nette\PhpGenerator\Helpers::isIdentifier($name)) {
69:                     $type = $def->getImplement() ?: $def->getClass();
70:                     $class->addDocument("@property $type \$$name");
71:                 }
72:             }
73:         }
74:     }
75: 
76: }
77: 
Nette 2.3.1 API API documentation generated by ApiGen 2.8.0