Sfoglia il codice sorgente

Merge remote branch 'vicb/form-doc-method-order'

* vicb/form-doc-method-order:
  [Form] Order method according to their visibility to respect the CS
  [Form] Add phpDoc for form builder and fix method declaration order to conform to the CS
Fabien Potencier 14 anni fa
parent
commit
c6b598fa52

+ 51 - 51
src/Symfony/Component/Form/AbstractExtension.php

@@ -39,6 +39,57 @@ abstract class AbstractExtension implements FormExtensionInterface
      */
     private $typeGuesserLoaded = false;
 
+    public function getType($name)
+    {
+        if (null === $this->types) {
+            $this->initTypes();
+        }
+
+        if (!isset($this->types[$name])) {
+            throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
+        }
+
+        return $this->types[$name];
+    }
+
+    public function hasType($name)
+    {
+        if (null === $this->types) {
+            $this->initTypes();
+        }
+
+        return isset($this->types[$name]);
+    }
+
+    public function getTypeExtensions($name)
+    {
+        if (null === $this->typeExtensions) {
+            $this->initTypeExtensions();
+        }
+
+        return isset($this->typeExtensions[$name])
+            ? $this->typeExtensions[$name]
+            : array();
+    }
+
+    public function hasTypeExtensions($name)
+    {
+        if (null === $this->typeExtensions) {
+            $this->initTypeExtensions();
+        }
+
+        return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
+    }
+
+    public function getTypeGuesser()
+    {
+        if (!$this->typeGuesserLoaded) {
+            $this->initTypeGuesser();
+        }
+
+        return $this->typeGuesser;
+    }
+
     protected function loadTypes()
     {
         return array();
@@ -104,55 +155,4 @@ abstract class AbstractExtension implements FormExtensionInterface
 
         $this->guesser = $guesser;
     }
-
-    public function getType($name)
-    {
-        if (null === $this->types) {
-            $this->initTypes();
-        }
-
-        if (!isset($this->types[$name])) {
-            throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
-        }
-
-        return $this->types[$name];
-    }
-
-    public function hasType($name)
-    {
-        if (null === $this->types) {
-            $this->initTypes();
-        }
-
-        return isset($this->types[$name]);
-    }
-
-    function getTypeExtensions($name)
-    {
-        if (null === $this->typeExtensions) {
-            $this->initTypeExtensions();
-        }
-
-        return isset($this->typeExtensions[$name])
-            ? $this->typeExtensions[$name]
-            : array();
-    }
-
-    function hasTypeExtensions($name)
-    {
-        if (null === $this->typeExtensions) {
-            $this->initTypeExtensions();
-        }
-
-        return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
-    }
-
-    public function getTypeGuesser()
-    {
-        if (!$this->typeGuesserLoaded) {
-            $this->initTypeGuesser();
-        }
-
-        return $this->typeGuesser;
-    }
 }

+ 16 - 16
src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php

@@ -40,22 +40,6 @@ class DefaultCsrfProvider implements CsrfProviderInterface
         $this->secret = $secret;
     }
 
-    /**
-     * Returns the ID of the user session
-     *
-     * Automatically starts the session if necessary.
-     *
-     * @return string  The session ID
-     */
-    protected function getSessionId()
-    {
-        if (!session_id()) {
-            session_start();
-        }
-
-        return session_id();
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -71,4 +55,20 @@ class DefaultCsrfProvider implements CsrfProviderInterface
     {
         return $token === $this->generateCsrfToken($pageId);
     }
+
+    /**
+     * Returns the ID of the user session
+     *
+     * Automatically starts the session if necessary.
+     *
+     * @return string  The session ID
+     */
+    protected function getSessionId()
+    {
+        if (!session_id()) {
+            session_start();
+        }
+
+        return session_id();
+    }
 }

+ 55 - 55
src/Symfony/Component/Form/Extension/Validator/Validator/DelegatingValidator.php

@@ -77,6 +77,61 @@ class DelegatingValidator implements FormValidatorInterface
         }
     }
 
+    /**
+     * Validates the data of a form
+     *
+     * This method is called automatically during the validation process.
+     *
+     * @param FormInterface    $form    The validated form
+     * @param ExecutionContext $context The current validation context
+     */
+    public static function validateFormData(FormInterface $form, ExecutionContext $context)
+    {
+        if (is_object($form->getData()) || is_array($form->getData())) {
+            $propertyPath = $context->getPropertyPath();
+            $graphWalker = $context->getGraphWalker();
+
+            // The Execute constraint is called on class level, so we need to
+            // set the property manually
+            $context->setCurrentProperty('data');
+
+            // Adjust the property path accordingly
+            if (!empty($propertyPath)) {
+                $propertyPath .= '.';
+            }
+
+            $propertyPath .= 'data';
+
+            foreach (self::getFormValidationGroups($form) as $group) {
+                $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
+            }
+        }
+    }
+
+    static protected function getFormValidationGroups(FormInterface $form)
+    {
+        $groups = null;
+
+        if ($form->hasAttribute('validation_groups')) {
+            $groups = $form->getAttribute('validation_groups');
+        }
+
+        $currentForm = $form;
+        while (!$groups && $currentForm->hasParent()) {
+            $currentForm = $currentForm->getParent();
+
+            if ($currentForm->hasAttribute('validation_groups')) {
+                $groups = $currentForm->getAttribute('validation_groups');
+            }
+        }
+
+        if (null === $groups) {
+            $groups = array('Default');
+        }
+
+        return (array) $groups;
+    }
+
     private function buildFormPathMapping(FormInterface $form, array &$mapping, $formPath = '', $namePath = '')
     {
         if ($formPath) {
@@ -178,59 +233,4 @@ class DelegatingValidator implements FormValidatorInterface
             }
         }
     }
-
-    /**
-     * Validates the data of a form
-     *
-     * This method is called automatically during the validation process.
-     *
-     * @param FormInterface    $form    The validated form
-     * @param ExecutionContext $context The current validation context
-     */
-    public static function validateFormData(FormInterface $form, ExecutionContext $context)
-    {
-        if (is_object($form->getData()) || is_array($form->getData())) {
-            $propertyPath = $context->getPropertyPath();
-            $graphWalker = $context->getGraphWalker();
-
-            // The Execute constraint is called on class level, so we need to
-            // set the property manually
-            $context->setCurrentProperty('data');
-
-            // Adjust the property path accordingly
-            if (!empty($propertyPath)) {
-                $propertyPath .= '.';
-            }
-
-            $propertyPath .= 'data';
-
-            foreach (self::getFormValidationGroups($form) as $group) {
-                $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
-            }
-        }
-    }
-
-    static protected function getFormValidationGroups(FormInterface $form)
-    {
-        $groups = null;
-
-        if ($form->hasAttribute('validation_groups')) {
-            $groups = $form->getAttribute('validation_groups');
-        }
-
-        $currentForm = $form;
-        while (!$groups && $currentForm->hasParent()) {
-            $currentForm = $currentForm->getParent();
-
-            if ($currentForm->hasAttribute('validation_groups')) {
-                $groups = $currentForm->getAttribute('validation_groups');
-            }
-        }
-
-        if (null === $groups) {
-            $groups = array('Default');
-        }
-
-        return (array) $groups;
-    }
 }

+ 5 - 5
src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php

@@ -24,15 +24,15 @@ class ValidatorExtension extends AbstractExtension
         $this->validator = $validator;
     }
 
+    public function loadTypeGuesser()
+    {
+        return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
+    }
+
     protected function loadTypeExtensions()
     {
         return array(
             new Type\FieldTypeValidatorExtension($this->validator),
         );
     }
-
-    public function loadTypeGuesser()
-    {
-        return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
-    }
 }

+ 32 - 32
src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php

@@ -63,38 +63,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
         });
     }
 
-    /**
-     * Iterates over the constraints of a property, executes a constraints on
-     * them and returns the best guess
-     *
-     * @param string $class       The class to read the constraints from
-     * @param string $property    The property for which to find constraints
-     * @param \Closure $guessForConstraint   The closure that returns a guess
-     *                            for a given constraint
-     * @return Guess  The guessed value with the highest confidence
-     */
-    protected function guess($class, $property, \Closure $guessForConstraint)
-    {
-        $guesses = array();
-        $classMetadata = $this->metadataFactory->getClassMetadata($class);
-
-        if ($classMetadata->hasMemberMetadatas($property)) {
-            $memberMetadatas = $classMetadata->getMemberMetadatas($property);
-
-            foreach ($memberMetadatas as $memberMetadata) {
-                $constraints = $memberMetadata->getConstraints();
-
-                foreach ($constraints as $constraint) {
-                    if ($guess = $guessForConstraint($constraint)) {
-                        $guesses[] = $guess;
-                    }
-                }
-            }
-        }
-
-        return Guess::getBestGuess($guesses);
-    }
-
     /**
      * Guesses a field class name for a given constraint
      *
@@ -297,4 +265,36 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
                 );
         }
     }
+
+    /**
+     * Iterates over the constraints of a property, executes a constraints on
+     * them and returns the best guess
+     *
+     * @param string $class       The class to read the constraints from
+     * @param string $property    The property for which to find constraints
+     * @param \Closure $guessForConstraint   The closure that returns a guess
+     *                            for a given constraint
+     * @return Guess  The guessed value with the highest confidence
+     */
+    protected function guess($class, $property, \Closure $guessForConstraint)
+    {
+        $guesses = array();
+        $classMetadata = $this->metadataFactory->getClassMetadata($class);
+
+        if ($classMetadata->hasMemberMetadatas($property)) {
+            $memberMetadatas = $classMetadata->getMemberMetadatas($property);
+
+            foreach ($memberMetadatas as $memberMetadata) {
+                $constraints = $memberMetadata->getConstraints();
+
+                foreach ($constraints as $constraint) {
+                    if ($guess = $guessForConstraint($constraint)) {
+                        $guesses[] = $guess;
+                    }
+                }
+            }
+        }
+
+        return Guess::getBestGuess($guesses);
+    }
 }

+ 45 - 45
src/Symfony/Component/Form/Form.php

@@ -876,6 +876,51 @@ class Form implements \IteratorAggregate, FormInterface
         return count($this->children);
     }
 
+    /**
+     * Creates a view.
+     *
+     * @param FormView $parent The parent view
+     *
+     * @return FormView The view
+     */
+    public function createView(FormView $parent = null)
+    {
+        if (null === $parent && $this->parent) {
+            $parent = $this->parent->createView();
+        }
+
+        $view = new FormView();
+
+        $view->setParent($parent);
+
+        $types = (array) $this->types;
+        $childViews = array();
+
+        foreach ($types as $type) {
+            $type->buildView($view, $this);
+
+            foreach ($type->getExtensions() as $typeExtension) {
+                $typeExtension->buildView($view, $this);
+            }
+        }
+
+        foreach ($this->children as $key => $child) {
+            $childViews[$key] = $child->createView($view);
+        }
+
+        $view->setChildren($childViews);
+
+        foreach ($types as $type) {
+            $type->buildViewBottomUp($view, $this);
+
+            foreach ($type->getExtensions() as $typeExtension) {
+                $typeExtension->buildViewBottomUp($view, $this);
+            }
+        }
+
+        return $view;
+    }
+
     /**
      * Normalizes the value if a normalization transformer is set.
      *
@@ -949,49 +994,4 @@ class Form implements \IteratorAggregate, FormInterface
 
         return $value;
     }
-
-    /**
-     * Creates a view.
-     *
-     * @param FormView $parent The parent view
-     *
-     * @return FormView The view
-     */
-    public function createView(FormView $parent = null)
-    {
-        if (null === $parent && $this->parent) {
-            $parent = $this->parent->createView();
-        }
-
-        $view = new FormView();
-
-        $view->setParent($parent);
-
-        $types = (array) $this->types;
-        $childViews = array();
-
-        foreach ($types as $type) {
-            $type->buildView($view, $this);
-
-            foreach ($type->getExtensions() as $typeExtension) {
-                $typeExtension->buildView($view, $this);
-            }
-        }
-
-        foreach ($this->children as $key => $child) {
-            $childViews[$key] = $child->createView($view);
-        }
-
-        $view->setChildren($childViews);
-
-        foreach ($types as $type) {
-            $type->buildViewBottomUp($view, $this);
-
-            foreach ($type->getExtensions() as $typeExtension) {
-                $typeExtension->buildViewBottomUp($view, $this);
-            }
-        }
-
-        return $view;
-    }
 }

+ 270 - 34
src/Symfony/Component/Form/FormBuilder.php

@@ -18,38 +18,106 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
 class FormBuilder
 {
+    /**
+     * @var string
+     */
     private $name;
 
-    private $data;
+    /**
+     * The form data in application format
+     * @var mixed
+     */
+    private $appData;
 
+    /**
+     * The event dispatcher
+     *
+     * @var EventDispatcherInterface
+     */
     private $dispatcher;
 
+    /**
+     * The form factory
+     * @var FormFactoryInterface
+     */
     private $factory;
 
+    /**
+     * @var Boolean
+     */
     private $readOnly;
 
+    /**
+     * @var Boolean
+     */
     private $required;
 
+    /**
+     * The transformers for transforming from normalized to client format and
+     * back
+     * @var array An array of DataTransformerInterface
+     */
     private $clientTransformers = array();
 
+    /**
+     * The transformers for transforming from application to normalized format
+     * and back
+     * @var array An array of DataTransformerInterface
+     */
     private $normTransformers = array();
 
+    /**
+     * @var array An array of FormValidatorInterface
+     */
     private $validators = array();
 
+    /**
+     * Key-value store for arbitrary attributes attached to the form
+     * @var array
+     */
     private $attributes = array();
 
+    /**
+     * @var array An array of FormTypeInterface
+     */
     private $types = array();
 
+    /**
+     * @var string
+     */
     private $dataClass;
 
+    /**
+     * The children of the form
+     * @var array
+     */
     private $children = array();
 
+    /**
+     * @var DataMapperInterface
+     */
     private $dataMapper;
 
+    /**
+     * Whether added errors should bubble up to the parent
+     * @var Boolean
+     */
     private $errorBubbling = false;
 
+    /**
+     * Data used for the client data when no value is bound
+     * @var mixed
+     */
     private $emptyData = '';
 
+    /**
+     * Constructor.
+     *
+     * @param string                    $name
+     * @param FormFactoryInterface      $factory
+     * @param EventDispatcherInterface  $dispatcher
+     * @param string                    $dataClass
+     */
     public function __construct($name, FormFactoryInterface $factory, EventDispatcherInterface $dispatcher, $dataClass = null)
     {
         $this->name = $name;
@@ -58,35 +126,69 @@ class FormBuilder
         $this->dataClass = $dataClass;
     }
 
+    /**
+     * Returns the associated form factory.
+     *
+     * @return FormFactoryInterface The factory
+     */
     public function getFormFactory()
     {
         return $this->factory;
     }
 
+    /**
+     * Returns the name of the form.
+     *
+     * @return string The form name
+     */
     public function getName()
     {
         return $this->name;
     }
 
-    public function setData($data)
+    /**
+     * Updates the field with default data.
+     *
+     * @param array $appData The data formatted as expected for the underlying object
+     *
+     * @return FormBuilder The current builder
+     */
+    public function setData($appData)
     {
-        $this->data = $data;
+        $this->appData = $appData;
 
         return $this;
     }
 
+    /**
+     * Returns the data in the format needed for the underlying object.
+     *
+     * @return mixed
+     */
     public function getData()
     {
-        return $this->data;
+        return $this->appData;
     }
 
+    /**
+     * Set whether the form is read only
+     *
+     * @param Boolean $readOnly Whether the form is read only
+     *
+     * @return FormBuilder The current builder
+     */
     public function setReadOnly($readOnly)
     {
-        $this->readOnly = $readOnly;
+        $this->readOnly = (Boolean) $readOnly;
 
         return $this;
     }
 
+    /**
+     * Returns whether the form is read only.
+     *
+     * @return Boolean Whether the form is read only
+     */
     public function getReadOnly()
     {
         return $this->readOnly;
@@ -96,31 +198,57 @@ class FormBuilder
      * Sets whether this field is required to be filled out when bound.
      *
      * @param Boolean $required
+     *
+     * @return FormBuilder The current builder
      */
     public function setRequired($required)
     {
-        $this->required = $required;
+        $this->required = (Boolean) $required;
 
         return $this;
     }
 
+    /**
+     * Returns whether this field is required to be filled out when bound.
+     *
+     * @return Boolean Whether this field is required
+     */
     public function getRequired()
     {
         return $this->required;
     }
 
+    /**
+     * Sets whether errors bubble up to the parent.
+     *
+     * @param type $errorBubbling
+     *
+     * @return FormBuilder The current builder
+     */
     public function setErrorBubbling($errorBubbling)
     {
-        $this->errorBubbling = $errorBubbling;
+        $this->errorBubbling = (Boolean) $errorBubbling;
 
         return $this;
     }
 
+    /**
+     * Returns whether errors bubble up to the parent.
+     *
+     * @return Boolean
+     */
     public function getErrorBubbling()
     {
         return $this->errorBubbling;
     }
 
+    /**
+     * Adds a validator to the form.
+     *
+     * @param FormValidatorInterface $validator The validator
+     *
+     * @return FormBuilder The current builder
+     */
     public function addValidator(FormValidatorInterface $validator)
     {
         $this->validators[] = $validator;
@@ -128,6 +256,11 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Returns the validators used by the form.
+     *
+     * @return array An array of FormValidatorInterface
+     */
     public function getValidators()
     {
         return $this->validators;
@@ -137,6 +270,8 @@ class FormBuilder
      * Adds an event listener for events on this field
      *
      * @see Symfony\Component\EventDispatcher\EventDispatcherInterface::addEventListener
+     *
+     * @return FormBuilder The current builder
      */
     public function addEventListener($eventNames, $listener, $priority = 0)
     {
@@ -149,6 +284,8 @@ class FormBuilder
      * Adds an event subscriber for events on this field
      *
      * @see Symfony\Component\EventDispatcher\EventDispatcherInterface::addEventSubscriber
+     *
+     * @return FormBuilder The current builder
      */
     public function addEventSubscriber(EventSubscriberInterface $subscriber, $priority = 0)
     {
@@ -161,6 +298,8 @@ class FormBuilder
      * Appends a transformer to the normalization transformer chain
      *
      * @param DataTransformerInterface $clientTransformer
+     *
+     * @return FormBuilder The current builder
      */
     public function appendNormTransformer(DataTransformerInterface $normTransformer)
     {
@@ -173,14 +312,21 @@ class FormBuilder
      * Prepends a transformer to the client transformer chain
      *
      * @param DataTransformerInterface $normTransformer
+     *
+     * @return FormBuilder The current builder
      */
-    public function prependNormTransformer(DataTransformerInterface $normTransformer = null)
+    public function prependNormTransformer(DataTransformerInterface $normTransformer)
     {
         array_unshift($this->normTransformers, $normTransformer);
 
         return $this;
     }
 
+    /**
+     * Clears the normalization transformers.
+     *
+     * @return FormBuilder The current builder
+     */
     public function resetNormTransformers()
     {
         $this->normTransformers = array();
@@ -188,6 +334,11 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Returns all the normalization transformers.
+     *
+     * @return array An array of DataTransformerInterface
+     */
     public function getNormTransformers()
     {
         return $this->normTransformers;
@@ -197,6 +348,8 @@ class FormBuilder
      * Appends a transformer to the client transformer chain
      *
      * @param DataTransformerInterface $clientTransformer
+     *
+     * @return FormBuilder The current builder
      */
     public function appendClientTransformer(DataTransformerInterface $clientTransformer)
     {
@@ -209,6 +362,8 @@ class FormBuilder
      * Prepends a transformer to the client transformer chain
      *
      * @param DataTransformerInterface $clientTransformer
+     *
+     * @return FormBuilder The current builder
      */
     public function prependClientTransformer(DataTransformerInterface $clientTransformer)
     {
@@ -222,11 +377,24 @@ class FormBuilder
         $this->clientTransformers = array();
     }
 
+    /**
+     * Returns all the client transformers.
+     *
+     * @return array An array of DataTransformerInterface
+     */
     public function getClientTransformers()
     {
         return $this->clientTransformers;
     }
 
+    /**
+     * Sets the value for an attribute.
+     *
+     * @param string $name  The name of the attribute
+     * @param string $value The value of the attribute
+     *
+     * @return FormBuilder The current builder
+     */
     public function setAttribute($name, $value)
     {
         $this->attributes[$name] = $value;
@@ -234,21 +402,43 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Returns the value of the attributes with the given name.
+     *
+     * @param string $name The name of the attribute
+     */
     public function getAttribute($name)
     {
         return $this->attributes[$name];
     }
 
+    /**
+     * Returns whether the form has an attribute with the given name.
+     *
+     * @param string $name The name of the attribute
+     */
     public function hasAttribute($name)
     {
         return isset($this->attributes[$name]);
     }
 
+    /**
+     * Returns all the attributes.
+     *
+     * @return array An array of attributes
+     */
     public function getAttributes()
     {
         return $this->attributes;
     }
 
+    /**
+     * Sets the data mapper used by the form.
+     *
+     * @param DataMapperInterface $dataMapper
+     *
+     * @return FormBuilder The current builder
+     */
     public function setDataMapper(DataMapperInterface $dataMapper)
     {
         $this->dataMapper = $dataMapper;
@@ -256,11 +446,23 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Returns the data mapper used by the form.
+     *
+     * @return array An array of DataMapperInterface
+     */
     public function getDataMapper()
     {
         return $this->dataMapper;
     }
 
+    /**
+     * Set the types.
+     *
+     * @param array $types An array FormTypeInterface
+     *
+     * @return FormBuilder The current builder
+     */
     public function setTypes(array $types)
     {
         $this->types = $types;
@@ -268,11 +470,21 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Return the types.
+     *
+     * @return array An array of FormTypeInterface
+     */
     public function getTypes()
     {
         return $this->types;
     }
 
+    /**
+     * Sets the data used for the client data when no value is bound.
+     *
+     * @param mixed $emptyData
+     */
     public function setEmptyData($emptyData)
     {
         $this->emptyData = $emptyData;
@@ -280,6 +492,11 @@ class FormBuilder
         return $this;
     }
 
+    /**
+     * Returns the data used for the client data when no value is bound.
+     *
+     * @return mixed
+     */
     public function getEmptyData()
     {
         return $this->emptyData;
@@ -317,10 +534,11 @@ class FormBuilder
      * $form->add($locationGroup);
      * </code>
      *
-     * @param string                   $name
+     * @param string|FormBuilder       $child
      * @param string|FormTypeInterface $type
      * @param array                    $options
-     * @return FormInterface
+     *
+     * @return FormBuilder The current builder
      */
     public function add($child, $type = null, array $options = array())
     {
@@ -339,8 +557,8 @@ class FormBuilder
         }
 
         $this->children[$child] = array(
-            'type' => $type,
-            'options' => $options,
+            'type'      => $type,
+            'options'   => $options,
         );
 
         return $this;
@@ -378,9 +596,11 @@ class FormBuilder
         }
 
         if (!$this->children[$name] instanceof FormBuilder) {
-            $this->children[$name] = $this->create($name,
+            $this->children[$name] = $this->create(
+                $name,
                 $this->children[$name]['type'],
-                $this->children[$name]['options']);
+                $this->children[$name]['options']
+            );
         }
 
         return $this->children[$name];
@@ -402,6 +622,7 @@ class FormBuilder
      * Returns whether a field with the given name exists.
      *
      * @param  string $name
+     *
      * @return Boolean
      */
     public function has($name)
@@ -409,26 +630,11 @@ class FormBuilder
         return isset($this->children[$name]);
     }
 
-    protected function buildDispatcher()
-    {
-        return $this->dispatcher;
-    }
-
-    protected function buildChildren()
-    {
-        $children = array();
-
-        foreach ($this->children as $name => $builder) {
-            if (!$builder instanceof FormBuilder) {
-                $builder = $this->create($name, $builder['type'], $builder['options']);
-            }
-
-            $children[$builder->getName()] = $builder->getForm();
-        }
-
-        return $children;
-    }
-
+    /**
+     * Creates the form.
+     *
+     * @return Form The form
+     */
     public function getForm()
     {
         $instance = new Form(
@@ -456,4 +662,34 @@ class FormBuilder
 
         return $instance;
     }
+
+    /**
+     * Returns the event dispatcher.
+     *
+     * @return type
+     */
+    protected function buildDispatcher()
+    {
+        return $this->dispatcher;
+    }
+
+    /**
+     * Creates the children.
+     *
+     * @return array An array of Form
+     */
+    protected function buildChildren()
+    {
+        $children = array();
+
+        foreach ($this->children as $name => $builder) {
+            if (!$builder instanceof FormBuilder) {
+                $builder = $this->create($name, $builder['type'], $builder['options']);
+            }
+
+            $children[$builder->getName()] = $builder->getForm();
+        }
+
+        return $children;
+    }
 }

+ 15 - 15
src/Symfony/Component/Form/FormFactory.php

@@ -40,21 +40,6 @@ class FormFactory implements FormFactoryInterface
         $this->extensions = $extensions;
     }
 
-    private function loadGuesser()
-    {
-        $guessers = array();
-
-        foreach ($this->extensions as $extension) {
-            $guesser = $extension->getTypeGuesser();
-
-            if ($guesser) {
-                $guessers[] = $guesser;
-            }
-        }
-
-        $this->guesser = new FormTypeGuesserChain($guessers);
-    }
-
     public function getType($name)
     {
         $type = null;
@@ -198,4 +183,19 @@ class FormFactory implements FormFactoryInterface
 
         return $this->createNamedBuilder($type, $property, $data, $options);
     }
+
+    private function loadGuesser()
+    {
+        $guessers = array();
+
+        foreach ($this->extensions as $extension) {
+            $guesser = $extension->getTypeGuesser();
+
+            if ($guesser) {
+                $guessers[] = $guesser;
+            }
+        }
+
+        $this->guesser = new FormTypeGuesserChain($guessers);
+    }
 }

+ 7 - 0
src/Symfony/Component/Form/FormTypeGuesserChain.php

@@ -18,6 +18,13 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
 {
     private $guessers = array();
 
+    /**
+     * Constructor.
+     *
+     * @param array $guessers Guessers as instances of FormTypeGuesserInterface
+     *
+     * @throws UnexpectedTypeException if any guesser does not implement FormTypeGuesserInterface
+     */
     public function __construct(array $guessers)
     {
         foreach ($guessers as $guesser) {