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

  • TracyExtension
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Tracy (https://tracy.nette.org)
 5:  * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Tracy\Bridges\Nette;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Tracy extension for Nette DI.
15:  */
16: class TracyExtension extends Nette\DI\CompilerExtension
17: {
18:     public $defaults = array(
19:         'email' => NULL,
20:         'fromEmail' => NULL,
21:         'logSeverity' => NULL,
22:         'editor' => NULL,
23:         'browser' => NULL,
24:         'errorTemplate' => NULL,
25:         'strictMode' => NULL,
26:         'maxLen' => NULL,
27:         'maxDepth' => NULL,
28:         'showLocation' => NULL,
29:         'scream' => NULL,
30:         'bar' => array(), // of class name
31:         'blueScreen' => array(), // of callback
32:     );
33: 
34:     /** @var bool */
35:     private $debugMode;
36: 
37: 
38:     public function __construct($debugMode = FALSE)
39:     {
40:         $this->debugMode = $debugMode;
41:     }
42: 
43: 
44:     public function loadConfiguration()
45:     {
46:         $this->validateConfig($this->defaults);
47:         $container = $this->getContainerBuilder();
48: 
49:         $container->addDefinition($this->prefix('logger'))
50:             ->setClass('Tracy\ILogger')
51:             ->setFactory('Tracy\Debugger::getLogger');
52: 
53:         $container->addDefinition($this->prefix('blueScreen'))
54:             ->setFactory('Tracy\Debugger::getBlueScreen');
55: 
56:         $container->addDefinition($this->prefix('bar'))
57:             ->setFactory('Tracy\Debugger::getBar');
58:     }
59: 
60: 
61:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
62:     {
63:         $initialize = $class->getMethod('initialize');
64:         $container = $this->getContainerBuilder();
65: 
66:         $options = $this->config;
67:         unset($options['bar'], $options['blueScreen']);
68:         foreach ($options as $key => $value) {
69:             if ($value !== NULL) {
70:                 $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
71:                 $initialize->addBody($container->formatPhp(
72:                     'Tracy\Debugger::' . $key . ' = ?;',
73:                     Nette\DI\Compiler::filterArguments(array($value))
74:                 ));
75:             }
76:         }
77: 
78:         if ($this->debugMode) {
79:             foreach ((array) $this->config['bar'] as $item) {
80:                 $initialize->addBody($container->formatPhp(
81:                     '$this->getService(?)->addPanel(?);',
82:                     Nette\DI\Compiler::filterArguments(array(
83:                         $this->prefix('bar'),
84:                         is_string($item) ? new Nette\DI\Statement($item) : $item,
85:                     ))
86:                 ));
87:             }
88:         }
89: 
90:         foreach ((array) $this->config['blueScreen'] as $item) {
91:             $initialize->addBody($container->formatPhp(
92:                 '$this->getService(?)->addPanel(?);',
93:                 Nette\DI\Compiler::filterArguments(array($this->prefix('blueScreen'), $item))
94:             ));
95:         }
96:     }
97: 
98: }
99: 
Nette 2.3.8 API API documentation generated by ApiGen 2.8.0