[WebProfilerBundle] converted the configuration to the new system

This commit is contained in:
Fabien Potencier 2011-03-30 19:31:32 +02:00
parent c8fe15bfcf
commit bdc07ad13e
3 changed files with 56 additions and 25 deletions

View File

@ -0,0 +1,45 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
/**
* This class contains the configuration information for the bundle
*
* This information is solely responsible for how the different configuration
* sections are normalized, and merged.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Configuration
{
/**
* Generates the configuration tree.
*
* @return \Symfony\Component\Config\Definition\ArrayNode The config tree
*/
public function getConfigTree()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('swiftmailer');
$rootNode
->children()
->booleanNode('toolbar')->defaultFalse()->end()
->scalarNode('intercept_redirects')->defaultFalse()->end()
->end()
;
return $treeBuilder->buildTree();
}
}

View File

@ -13,9 +13,9 @@ namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;
/**
* WebProfilerExtension.
@ -31,36 +31,23 @@ use Symfony\Component\Config\FileLocator;
*/
class WebProfilerExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
foreach ($configs as $config) {
$this->doConfigLoad($config, $container);
}
}
/**
* Loads the web profiler configuration.
*
* @param array $config An array of configuration settings
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function doConfigLoad(array $config, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container)
{
if (isset($config['toolbar'])) {
if ($config['toolbar']) {
if (!$container->hasDefinition('debug.toolbar')) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('toolbar.xml');
}
} elseif ($container->hasDefinition('debug.toolbar')) {
$container->getDefinition('debug.toolbar')->clearTags();
}
}
$configuration = new Configuration();
$processor = new Processor();
$config = $processor->process($configuration->getConfigTree(), $configs);
foreach (array('intercept-redirects', 'intercept_redirects') as $key) {
if (isset($config[$key])) {
$container->setParameter('debug.toolbar.intercept_redirects', (Boolean) $config[$key]);
}
if ($config['toolbar']) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('toolbar.xml');
$container->getDefinition('debug.toolbar')->setArgument(1, $config['intercept_redirects']);
}
}

View File

@ -6,14 +6,13 @@
<parameters>
<parameter key="debug.toolbar.class">Symfony\Bundle\WebProfilerBundle\WebDebugToolbarListener</parameter>
<parameter key="debug.toolbar.intercept_redirects">false</parameter>
</parameters>
<services>
<service id="debug.toolbar" class="%debug.toolbar.class%">
<tag name="kernel.listener" event="onCoreResponse" priority="-128" />
<argument type="service" id="templating.engine.twig" />
<argument>%debug.toolbar.intercept_redirects%</argument>
<argument /> <!-- intercept_redirects -->
</service>
</services>
</container>