Browse Source

[FrameworkBundle] Small fixes to FrameworkExtension and its configuration

 * Remove redundant null/true equivalent array() values for array nodes
 * Profiler matcher should not be deep merged; subsequent configs can simply overwrite its array
 * Per lsmith's suggestion, change "isset(x) && x" to "!empty(x)"
 * Templating engines node should be required, which is necessary to ensure requiresAtLeastOneElement() applies to its prototype children
Jeremy Mikola 14 years ago
parent
commit
fc3f56d17c

+ 2 - 4
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

@@ -76,11 +76,10 @@ class Configuration
         $rootNode
             ->arrayNode('profiler')
                 ->canBeUnset()
-                ->treatNullLike(array())
-                ->treatTrueLike(array())
                 ->booleanNode('only_exceptions')->end()
                 ->arrayNode('matcher')
                     ->canBeUnset()
+                    ->performNoDeepMerging()
                     ->scalarNode('ip')->end()
                     ->scalarNode('path')->end()
                     ->scalarNode('service')->end()
@@ -106,8 +105,6 @@ class Configuration
         $rootNode
             ->arrayNode('session')
                 ->canBeUnset()
-                ->treatNullLike(array())
-                ->treatTrueLike(array())
                 // Strip "pdo." prefix from option keys, since dots cannot appear in node names
                 ->beforeNormalization()
                     ->ifArray()
@@ -152,6 +149,7 @@ class Configuration
                 ->scalarNode('cache_warmer')->end()
                 ->fixXmlConfig('engine')
                 ->arrayNode('engines')
+                    ->isRequired()
                     ->requiresAtLeastOneElement()
                     ->beforeNormalization()
                         ->ifTrue(function($v){ return !is_array($v); })

+ 6 - 16
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

@@ -92,7 +92,7 @@ class FrameworkExtension extends Extension
             $container->setParameter('debug.file_link_format', $pattern);
         }
 
-        if (isset($config['test']) && $config['test']) {
+        if (!empty($config['test'])) {
             $loader->load('test.xml');
             $config['session']['storage_id'] = 'array';
         }
@@ -177,7 +177,7 @@ class FrameworkExtension extends Extension
      */
     private function registerEsiConfiguration(array $config, XmlFileLoader $loader)
     {
-        if (isset($config['enabled']) && $config['enabled']) {
+        if (!empty($config['enabled'])) {
             $loader->load('esi.xml');
         }
     }
@@ -222,23 +222,18 @@ class FrameworkExtension extends Extension
      * @param array            $config    A router configuration array
      * @param ContainerBuilder $container A ContainerBuilder instance
      * @param XmlFileLoader    $loader    An XmlFileLoader instance
-     * @throws \InvalidArgumentException if resource option is not set
      */
     private function registerRouterConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
     {
         $loader->load('routing.xml');
 
-        if (!isset($config['resource'])) {
-            throw new \InvalidArgumentException('Router configuration requires a resource option.');
-        }
-
         $container->setParameter('routing.resource', $config['resource']);
 
         if (isset($config['type'])) {
             $container->setParameter('router.options.resource_type', $config['type']);
         }
 
-        if (isset($config['cache_warmer']) && $config['cache_warmer']) {
+        if (!empty($config['cache_warmer'])) {
             $container->getDefinition('router.cache_warmer')->addTag('kernel.cache_warmer');
             $container->setAlias('router', 'router.cached');
         }
@@ -264,7 +259,7 @@ class FrameworkExtension extends Extension
     {
         $loader->load('session.xml');
 
-        if (isset($config['auto_start']) && $config['auto_start']) {
+        if (!empty($config['auto_start'])) {
             $container->getDefinition('session')->addMethodCall('start');
         }
 
@@ -299,7 +294,6 @@ class FrameworkExtension extends Extension
      * @param array            $config    A templating configuration array
      * @param ContainerBuilder $container A ContainerBuilder instance
      * @param XmlFileLoader    $loader    An XmlFileLoader instance
-     * @throws \LogicException if no engines are defined
      */
     private function registerTemplatingConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
     {
@@ -318,7 +312,7 @@ class FrameworkExtension extends Extension
             $container->setParameter('templating.assets.base_urls', $config['assets_base_urls']);
         }
 
-        if (isset($config['loaders']) && $config['loaders']) {
+        if (!empty($config['loaders'])) {
             $loaders = array_map(function($loader) { return new Reference($loader); }, $config['loaders']);
 
             // Use a delegation unless only a single loader was registered
@@ -344,10 +338,6 @@ class FrameworkExtension extends Extension
             $container->setAlias('templating.locator', 'templating.locator.cached');
         }
 
-        if (empty($config['engines'])) {
-            throw new \LogicException('You must register at least one templating engine.');
-        }
-
         $this->addClassesToCompile(array(
             'Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface',
             'Symfony\\Component\\Templating\\EngineInterface',
@@ -388,7 +378,7 @@ class FrameworkExtension extends Extension
      */
     private function registerTranslatorConfiguration(array $config, ContainerBuilder $container)
     {
-        if (isset($config['enabled']) && $config['enabled']) {
+        if (!empty($config['enabled'])) {
             // Use the "real" translator instead of the identity default
             $container->setDefinition('translator', $container->findDefinition('translator.real'));
 

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

@@ -57,7 +57,7 @@ abstract class FrameworkExtensionTest extends TestCase
     }
 
     /**
-     * @expectedException InvalidArgumentException
+     * @expectedException Symfony\Component\DependencyInjection\Configuration\Exception\InvalidConfigurationException
      */
     public function testRouterRequiresResourceOption()
     {
@@ -130,7 +130,7 @@ abstract class FrameworkExtensionTest extends TestCase
     }
 
     /**
-     * @expectedException LogicException
+     * @expectedException Symfony\Component\DependencyInjection\Configuration\Exception\InvalidConfigurationException
      */
     public function testTemplatingRequiresAtLeastOneEngine()
     {