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
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Tracy (http://tracy.nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  */
 7: 
 8: namespace Tracy\Bridges\Nette;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Tracy extension for Nette DI.
15:  *
16:  * @author     David Grudl
17:  */
18: class TracyExtension extends Nette\DI\CompilerExtension
19: {
20:     public $defaults = array(
21:         'email' => NULL,
22:         'logSeverity' => NULL,
23:         'editor' => NULL,
24:         'browser' => NULL,
25:         'errorTemplate' => NULL,
26:         'strictMode' => 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:                 $initialize->addBody($container->formatPhp(
72:                     'Tracy\Debugger::$? = ?;',
73:                     Nette\DI\Compiler::filterArguments(array($key, $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.1 API API documentation generated by ApiGen 2.8.0