Created
July 31, 2013 20:30
-
-
Save enumag/6125849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Nette; | |
| /** | |
| * @author Jáchym Toušek <enumag@gmail.com> | |
| */ | |
| class SessionPanelExtension extends Nette\Config\CompilerExtension | |
| { | |
| /** @var array */ | |
| public $defaults = array( | |
| 'hiddenSections' => array(), | |
| ); | |
| public function loadConfiguration() | |
| { | |
| $builder = $this->getContainerBuilder(); | |
| $config = $this->getConfig($this->defaults); | |
| if ($builder->parameters['debugMode']) { | |
| $builder->addDefinition($this->prefix('panel')) | |
| ->setClass('Kdyby\SessionPanel\Diagnostics\SessionPanel'); | |
| Nette\Utils\Validators::assertField($config, 'hiddenSections', 'array'); | |
| foreach ($config['hiddenSections'] as $section) { | |
| $builder->getDefinition($this->prefix('panel')) | |
| ->addSetup('hideSection', array($section)); | |
| } | |
| } | |
| } | |
| public function afterCompile(Nette\Utils\PhpGenerator\ClassType $class) | |
| { | |
| $builder = $this->getContainerBuilder(); | |
| if ($builder->parameters['debugMode']) { | |
| $class->methods['initialize']->addBody($builder->formatPhp( | |
| 'Nette\Diagnostics\Debugger::' . (method_exists('Nette\Diagnostics\Debugger', 'getBar') ? 'getBar()' : '$bar') . '->addPanel(?);', | |
| Nette\DI\Compiler::filterArguments(array(new Nette\DI\Statement($this->prefix('@panel')))) | |
| )); | |
| } | |
| } | |
| public static function register(Nette\Config\Configurator $configurator) | |
| { | |
| $configurator->onCompile[] = function ($config, Nette\DI\Compiler $compiler) { | |
| $compiler->addExtension('debugger.session', new static()); | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment