Skip to content

Instantly share code, notes, and snippets.

@enumag
Created July 31, 2013 20:30
Show Gist options
  • Select an option

  • Save enumag/6125849 to your computer and use it in GitHub Desktop.

Select an option

Save enumag/6125849 to your computer and use it in GitHub Desktop.
<?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