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
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • TracyExtension
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  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 = [
 19:         'email' => NULL,
 20:         'fromEmail' => NULL,
 21:         'logSeverity' => NULL,
 22:         'editor' => NULL,
 23:         'browser' => NULL,
 24:         'errorTemplate' => NULL,
 25:         'strictMode' => NULL,
 26:         'showBar' => NULL,
 27:         'maxLen' => NULL,
 28:         'maxDepth' => NULL,
 29:         'showLocation' => NULL,
 30:         'scream' => NULL,
 31:         'bar' => [], // of class name
 32:         'blueScreen' => [], // of callback
 33:         'editorMapping' => [],
 34:     ];
 35: 
 36:     /** @var bool */
 37:     private $debugMode;
 38: 
 39:     /** @var bool */
 40:     private $cliMode;
 41: 
 42: 
 43:     public function __construct($debugMode = FALSE, $cliMode = FALSE)
 44:     {
 45:         $this->debugMode = $debugMode;
 46:         $this->cliMode = $cliMode;
 47:     }
 48: 
 49: 
 50:     public function loadConfiguration()
 51:     {
 52:         $this->validateConfig($this->defaults);
 53:         $builder = $this->getContainerBuilder();
 54: 
 55:         $builder->addDefinition($this->prefix('logger'))
 56:             ->setClass('Tracy\ILogger')
 57:             ->setFactory('Tracy\Debugger::getLogger');
 58: 
 59:         $builder->addDefinition($this->prefix('blueScreen'))
 60:             ->setFactory('Tracy\Debugger::getBlueScreen');
 61: 
 62:         $builder->addDefinition($this->prefix('bar'))
 63:             ->setFactory('Tracy\Debugger::getBar');
 64:     }
 65: 
 66: 
 67:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
 68:     {
 69:         $initialize = $class->getMethod('initialize');
 70:         $builder = $this->getContainerBuilder();
 71:         $class = method_exists('Nette\DI\Helpers', 'filterArguments') ? 'Nette\DI\Helpers' : 'Nette\DI\Compiler';
 72: 
 73:         $options = $this->config;
 74:         unset($options['bar'], $options['blueScreen']);
 75:         if (isset($options['logSeverity'])) {
 76:             $res = 0;
 77:             foreach ((array) $options['logSeverity'] as $level) {
 78:                 $res |= is_int($level) ? $level : constant($level);
 79:             }
 80:             $options['logSeverity'] = $res;
 81:         }
 82:         foreach ($options as $key => $value) {
 83:             if ($value !== NULL) {
 84:                 $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
 85:                 $initialize->addBody($builder->formatPhp(
 86:                     'Tracy\Debugger::' . $key . ' = ?;',
 87:                     $class::filterArguments([$value])
 88:                 ));
 89:             }
 90:         }
 91: 
 92:         $logger = $builder->getDefinition($this->prefix('logger'));
 93:         if ($logger->getFactory()->getEntity() !== 'Tracy\Debugger::getLogger') {
 94:             $initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger]));
 95:         }
 96: 
 97:         if ($this->debugMode) {
 98:             foreach ((array) $this->config['bar'] as $item) {
 99:                 $initialize->addBody($builder->formatPhp(
100:                     '$this->getService(?)->addPanel(?);',
101:                     $class::filterArguments([
102:                         $this->prefix('bar'),
103:                         is_string($item) ? new Nette\DI\Statement($item) : $item,
104:                     ])
105:                 ));
106:             }
107: 
108:             if (!$this->cliMode) {
109:                 $initialize->addBody('if ($tmp = $this->getByType("Nette\Http\Session", FALSE)) { $tmp->start(); Tracy\Debugger::dispatch(); };');
110:             }
111:         }
112: 
113:         foreach ((array) $this->config['blueScreen'] as $item) {
114:             $initialize->addBody($builder->formatPhp(
115:                 '$this->getService(?)->addPanel(?);',
116:                 $class::filterArguments([$this->prefix('blueScreen'), $item])
117:             ));
118:         }
119:     }
120: 
121: }
122: 
Nette 2.4-20170221 API API documentation generated by ApiGen 2.8.0