Selaa lähdekoodia

Moved the exception to setDefaultValue

Christophe Coevoet 14 vuotta sitten
vanhempi
commit
ccd630981f

+ 5 - 4
src/Symfony/Component/DependencyInjection/Configuration/ArrayNode.php

@@ -126,6 +126,11 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
         if (!is_array($value)) {
             throw new \InvalidArgumentException($this->getPath().': the default value of an array node has to be an array.');
         }
+
+        if (null === $this->prototype) {
+            throw new \RuntimeException($this->getPath().': An ARRAY node can have a specified default value only when using a prototype');
+        }
+
         $this->defaultValue = $value;
     }
 
@@ -148,10 +153,6 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
             return $this->defaultValue ?: array();
         }
 
-        if (null !== $this->defaultValue) {
-            throw new \RuntimeException($this->getPath().': An ARRAY node can have a specified default value only when using a prototype');
-        }
-
         $defaults = array();
         foreach ($this->children as $name => $child) {
             if (!$child->hasDefaultValue()) {

+ 4 - 4
src/Symfony/Component/DependencyInjection/Configuration/Builder/TreeBuilder.php

@@ -147,10 +147,6 @@ class TreeBuilder
         $configNode->addEquivalentValue(false, $node->falseEquivalent);
         $configNode->setPerformDeepMerging($node->performDeepMerging);
 
-        if (null !== $node->defaultValue) {
-            $configNode->setDefaultValue($node->defaultValue);
-        }
-
         if (null !== $node->key) {
             $configNode->setKeyAttribute($node->key);
         }
@@ -183,6 +179,10 @@ class TreeBuilder
             $configNode->setPrototype($this->createConfigNode($node->prototype));
         }
 
+        if (null !== $node->defaultValue) {
+            $configNode->setDefaultValue($node->defaultValue);
+        }
+
         return $configNode;
     }