Pārlūkot izejas kodu

Merge remote branch 'vicb/form-fixes'

* vicb/form-fixes:
  [Form] Make the PropertyPathMapper class use the UnexpectedTypeException
  [Form] Fix adding transformers in the FormBuilder
  [Form] Fix the ReversedTransform class
Fabien Potencier 14 gadi atpakaļ
vecāks
revīzija
b62cd109f0

+ 11 - 3
src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php

@@ -15,6 +15,7 @@ use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\DataMapperInterface;
 use Symfony\Component\Form\Util\VirtualFormAwareIterator;
 use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\UnexpectedTypeException;
 
 class PropertyPathMapper implements DataMapperInterface
 {
@@ -29,15 +30,22 @@ class PropertyPathMapper implements DataMapperInterface
         $this->dataClass = $dataClass;
     }
 
+    /**
+     *
+     * @param dataClass $data
+     * @param array $forms
+     *
+     * @throws UnexpectedTypeException if the type of the data parameter is not supported
+     */
     public function mapDataToForms($data, array $forms)
     {
         if (!empty($data) && !is_array($data) && !is_object($data)) {
-            throw new \InvalidArgumentException(sprintf('Expected argument of type object or array, %s given', gettype($data)));
+            throw new UnexpectedTypeException($data, 'Object, array or empty');
         }
 
         if (!empty($data)) {
-            if ($this->dataClass && !$data instanceof $this->dataClass) {
-                throw new FormException(sprintf('Form data should be instance of %s', $this->dataClass));
+            if (null !== $this->dataClass && !$data instanceof $this->dataClass) {
+                throw new UnexpectedTypeException($data, $this->dataClass);
             }
 
             $iterator = new VirtualFormAwareIterator($forms);

+ 3 - 3
src/Symfony/Component/Form/FormBuilder.php

@@ -162,7 +162,7 @@ class FormBuilder
      *
      * @param DataTransformerInterface $clientTransformer
      */
-    public function appendNormTransformer(DataTransformerInterface $normTransformer = null)
+    public function appendNormTransformer(DataTransformerInterface $normTransformer)
     {
         $this->normTransformers[] = $normTransformer;
 
@@ -198,7 +198,7 @@ class FormBuilder
      *
      * @param DataTransformerInterface $clientTransformer
      */
-    public function appendClientTransformer(DataTransformerInterface $clientTransformer = null)
+    public function appendClientTransformer(DataTransformerInterface $clientTransformer)
     {
         $this->clientTransformers[] = $clientTransformer;
 
@@ -210,7 +210,7 @@ class FormBuilder
      *
      * @param DataTransformerInterface $clientTransformer
      */
-    public function prependClientTransformer(DataTransformerInterface $clientTransformer = null)
+    public function prependClientTransformer(DataTransformerInterface $clientTransformer)
     {
         array_unshift($this->clientTransformers, $clientTransformer);
 

+ 1 - 1
src/Symfony/Component/Form/ReversedTransformer.php

@@ -42,7 +42,7 @@ class ReversedTransformer implements DataTransformerInterface
      */
     public function transform($value)
     {
-        return $this->reversedTransformer->reverseTransform($value, null);
+        return $this->reversedTransformer->reverseTransform($value);
     }
 
     /**