Browse Source

Fixed Configuration class, updated XSD schema and resolved some TODOs

Christophe Coevoet 14 years ago
parent
commit
df4dff002e

+ 21 - 6
src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php

@@ -34,27 +34,42 @@ class Configuration
         $treeBuilder = new TreeBuilder();
         $rootNode = $treeBuilder->root('monolog', 'array');
 
-        // TODO update XSD to match this
         $rootNode
+            ->fixXmlConfig('handler')
             ->arrayNode('handlers')
-                ->fixXmlConfig('handler')
                 ->canBeUnset()
                 ->performNoDeepMerging()
+                ->useAttributeAsKey('name')
                 ->prototype('array')
                     ->performNoDeepMerging()
-                    // TODO lowercase the type always
-                    ->scalarNode('type')->isRequired()->end()
+                    ->scalarNode('type')
+                        ->isRequired()
+                        ->beforeNormalization()
+                            ->always()
+                            ->then(function($v) { return strtolower($v); })
+                        ->end()
+                    ->end()
                     ->scalarNode('action_level')->end()
                     ->scalarNode('level')->defaultValue('INFO')->end()
                     ->scalarNode('path')->end()
-                    ->scalarNode('bubble')->end()
+                    ->booleanNode('bubble')->defaultFalse()->end()
                     ->scalarNode('buffer_size')->end()
                     ->arrayNode('handler')
                         ->performNoDeepMerging()
-                        ->scalarNode('type')->isRequired()->end()
+                        ->scalarNode('type')
+                            ->isRequired()
+                            ->beforeNormalization()
+                                ->always()
+                                ->then(function($v) { return strtolower($v); })
+                            ->end()
+                        ->end()
                         ->scalarNode('level')->defaultValue('DEBUG')->end()
                         ->scalarNode('path')->end()
                     ->end()
+                    ->validate()
+                        ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); })
+                        ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler')
+                    ->end()
                 ->end()
             ->end()
         ;

+ 2 - 6
src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php

@@ -82,15 +82,11 @@ class MonologExtension extends Extension
             $definition->setArguments(array(
                 $handler['path'],
                 $handler['level'],
-                isset($handler['bubble']) ? $handler['bubble'] : false,
+                $handler['bubble'],
             ));
             break;
 
         case 'fingerscrossed':
-            if (!isset($handler['handler'])) {
-                // TODO validate that in Config class?
-                throw new \InvalidArgumentException('Handler sub-node is missing.');
-            }
             if (!isset($handler['action_level'])) {
                 $handler['action_level'] = 'WARNING';
             }
@@ -100,7 +96,7 @@ class MonologExtension extends Extension
                 $this->buildHandler($container, $handler['handler']),
                 $handler['action_level'],
                 isset($handler['buffer_size']) ? $handler['buffer_size'] : 0,
-                isset($handler['bubble']) ? $handler['bubble'] : false,
+                $handler['bubble'],
             ));
             break;
         }

+ 21 - 5
src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd

@@ -8,14 +8,24 @@
     <xsd:element name="config" type="config" />
 
     <xsd:complexType name="config">
-        <xsd:all>
-            <xsd:element name="handler" type="handler" minOccurs="0" maxOccurs="unbounded" />
-        </xsd:all>
+        <xsd:choice minOccurs="0" maxOccurs="unbounded">
+            <xsd:element name="handler" type="handler" />
+        </xsd:choice>
     </xsd:complexType>
 
     <xsd:complexType name="handler">
-        <xsd:attribute name="level" type="level" />
-        <xsd:attribute name="path" type="xsd:string" />
+        <xsd:all>
+            <xsd:element name="handler" maxOccurs="1">
+                <xsd:complexType>
+                    <xsd:attributeGroup ref="handler_attribute" />
+                </xsd:complexType>
+            </xsd:element>
+        </xsd:all>
+        <xsd:attributeGroup ref="handler_attributes" />
+        <xsd:attribute name="name" type="xsd:string" use="required">
+        <xsd:attribute name="bubble" type="xsd:boolean" />
+        <xsd:attribute name="action-level" type="level" />
+        <xsd:attribute name="buffer-size" type="xsd:integer" />
     </xsd:complexType>
 
     <xsd:simpleType name="level">
@@ -31,4 +41,10 @@
             <xsd:enumeration value="400" />
         </xsd:restriction>
     </xsd:simpleType>
+
+    <xsd:attributeGroup name="handler_attributes">
+        <xsd:attribute name="type" type="xsd:string" use="required" />
+        <xsd:attribute name="level" type="level" />
+        <xsd:attribute name="path" type="xsd:string" />
+    </xsd:attributeGroup>
 </xsd:schema>