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

  • 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:         'showBar' => NULL,
 27:         'maxLen' => NULL,
 28:         'maxDepth' => NULL,
 29:         'showLocation' => NULL,
 30:         'scream' => NULL,
 31:         'bar' => array(), // of class name
 32:         'blueScreen' => array(), // of callback
 33:     );
 34: 
 35:     /** @var bool */
 36:     private $debugMode;
 37: 
 38: 
 39:     public function __construct($debugMode = FALSE)
 40:     {
 41:         $this->debugMode = $debugMode;
 42:     }
 43: 
 44: 
 45:     public function loadConfiguration()
 46:     {
 47:         $this->validateConfig($this->defaults);
 48:         $container = $this->getContainerBuilder();
 49: 
 50:         $container->addDefinition($this->prefix('logger'))
 51:             ->setClass('Tracy\ILogger')
 52:             ->setFactory('Tracy\Debugger::getLogger');
 53: 
 54:         $container->addDefinition($this->prefix('blueScreen'))
 55:             ->setFactory('Tracy\Debugger::getBlueScreen');
 56: 
 57:         $container->addDefinition($this->prefix('bar'))
 58:             ->setFactory('Tracy\Debugger::getBar');
 59:     }
 60: 
 61: 
 62:     public function afterCompile(Nette\PhpGenerator\ClassType $class)
 63:     {
 64:         $initialize = $class->getMethod('initialize');
 65:         $container = $this->getContainerBuilder();
 66: 
 67:         $options = $this->config;
 68:         unset($options['bar'], $options['blueScreen']);
 69:         foreach ($options as $key => $value) {
 70:             if ($value !== NULL) {
 71:                 $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
 72:                 $initialize->addBody($container->formatPhp(
 73:                     'Tracy\Debugger::' . $key . ' = ?;',
 74:                     Nette\DI\Compiler::filterArguments(array($value))
 75:                 ));
 76:             }
 77:         }
 78: 
 79:         if ($this->debugMode) {
 80:             foreach ((array) $this->config['bar'] as $item) {
 81:                 $initialize->addBody($container->formatPhp(
 82:                     '$this->getService(?)->addPanel(?);',
 83:                     Nette\DI\Compiler::filterArguments(array(
 84:                         $this->prefix('bar'),
 85:                         is_string($item) ? new Nette\DI\Statement($item) : $item,
 86:                     ))
 87:                 ));
 88:             }
 89:         }
 90: 
 91:         foreach ((array) $this->config['blueScreen'] as $item) {
 92:             $initialize->addBody($container->formatPhp(
 93:                 '$this->getService(?)->addPanel(?);',
 94:                 Nette\DI\Compiler::filterArguments(array($this->prefix('blueScreen'), $item))
 95:             ));
 96:         }
 97:     }
 98: 
 99: }
100: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0