diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000000..3ee6ccdbde --- /dev/null +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php @@ -0,0 +1,45 @@ + + * + * 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 + */ +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(); + } +} diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 3e16b1a856..cc70d6972a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -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']); } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml index a65a331129..59dce00896 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml @@ -6,14 +6,13 @@ Symfony\Bundle\WebProfilerBundle\WebDebugToolbarListener - false - %debug.toolbar.intercept_redirects% +