From 2cd99e80b6ae03b251c5236202c74113dc6cb39b Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Wed, 23 May 2012 19:34:41 +0200 Subject: [PATCH] [Form] Added FormBuilderInterface and FormViewInterface and cleaned up FormTypeInterface and FormTypeExtensionInterface --- UPGRADE-2.1.md | 71 +++--- .../Doctrine/Form/Type/DoctrineType.php | 6 +- .../Bridge/Propel1/Form/Type/ModelType.php | 6 +- .../Form/UserLoginFormType.php | 6 +- src/Symfony/Component/Form/AbstractType.php | 8 +- .../Component/Form/AbstractTypeExtension.php | 6 +- src/Symfony/Component/Form/CHANGELOG.md | 10 +- .../Form/Extension/Core/Type/BirthdayType.php | 2 +- .../Form/Extension/Core/Type/CheckboxType.php | 10 +- .../Form/Extension/Core/Type/ChoiceType.php | 20 +- .../Extension/Core/Type/CollectionType.php | 10 +- .../Form/Extension/Core/Type/CountryType.php | 2 +- .../Form/Extension/Core/Type/DateTimeType.php | 10 +- .../Form/Extension/Core/Type/DateType.php | 10 +- .../Form/Extension/Core/Type/EmailType.php | 2 +- .../Form/Extension/Core/Type/FileType.php | 8 +- .../Form/Extension/Core/Type/FormType.php | 11 +- .../Form/Extension/Core/Type/HiddenType.php | 2 +- .../Form/Extension/Core/Type/IntegerType.php | 6 +- .../Form/Extension/Core/Type/LanguageType.php | 2 +- .../Form/Extension/Core/Type/LocaleType.php | 2 +- .../Form/Extension/Core/Type/MoneyType.php | 10 +- .../Form/Extension/Core/Type/NumberType.php | 6 +- .../Form/Extension/Core/Type/PasswordType.php | 8 +- .../Form/Extension/Core/Type/PercentType.php | 6 +- .../Form/Extension/Core/Type/RadioType.php | 2 +- .../Form/Extension/Core/Type/RepeatedType.php | 4 +- .../Form/Extension/Core/Type/SearchType.php | 2 +- .../Form/Extension/Core/Type/TextType.php | 6 +- .../Form/Extension/Core/Type/TextareaType.php | 6 +- .../Form/Extension/Core/Type/TimeType.php | 10 +- .../Form/Extension/Core/Type/TimezoneType.php | 2 +- .../Form/Extension/Core/Type/UrlType.php | 6 +- .../Csrf/Type/FormTypeCsrfExtension.php | 8 +- .../Type/FormTypeValidatorExtension.php | 4 +- src/Symfony/Component/Form/Form.php | 4 +- src/Symfony/Component/Form/FormBuilder.php | 66 +---- .../Component/Form/FormBuilderInterface.php | 109 +++++++++ src/Symfony/Component/Form/FormConfig.php | 145 ++--------- .../Form/FormConfigEditorInterface.php | 225 ++++++++++++++++++ .../Form/FormTypeExtensionInterface.php | 32 +-- .../Component/Form/FormTypeInterface.php | 57 ++--- src/Symfony/Component/Form/FormView.php | 83 ++----- .../Component/Form/FormViewInterface.php | 148 ++++++++++++ .../Csrf/Type/FormTypeCsrfExtensionTest.php | 4 +- .../Form/Tests/Fixtures/AuthorType.php | 4 +- .../Component/Form/Tests/Fixtures/FooType.php | 5 +- .../Tests/Fixtures/FooTypeBarExtension.php | 4 +- .../Tests/Fixtures/FooTypeBazExtension.php | 4 +- src/Symfony/Component/Form/Tests/FormTest.php | 24 +- 50 files changed, 765 insertions(+), 439 deletions(-) create mode 100644 src/Symfony/Component/Form/FormBuilderInterface.php create mode 100644 src/Symfony/Component/Form/FormConfigEditorInterface.php create mode 100644 src/Symfony/Component/Form/FormViewInterface.php diff --git a/UPGRADE-2.1.md b/UPGRADE-2.1.md index 38183feec3..d48129b0fa 100644 --- a/UPGRADE-2.1.md +++ b/UPGRADE-2.1.md @@ -290,29 +290,6 @@ * `FormUtil::toArrayKey()` and `FormUtil::toArrayKeys()` have been removed. They were merged into ChoiceList and have no public equivalent anymore. - * The options passed to the `getParent()` method of form types no longer - contain default options. They only contain the options passed by the user. - - You should check if options exist before attempting to read their value. - - Before: - - ``` - public function getParent(array $options) - { - return 'single_text' === $options['widget'] ? 'text' : 'choice'; - } - ``` - - After: - - ``` - public function getParent(array $options) - { - return isset($options['widget']) && 'single_text' === $options['widget'] ? 'text' : 'choice'; - } - ``` - * The `add()`, `remove()`, `setParent()`, `bind()` and `setData()` methods in the Form class now throw an exception if the form is already bound. @@ -611,13 +588,50 @@ The second argument `$value` contains the current default value and does not have to be specified if not needed. - * A third argument $options was added to the methods `buildView()` and - `buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`. - You should adapt your implementing classes. + * No options are passed to `getParent()` of `FormTypeInterface` anymore. If + you previously dynamically inherited from FormType or FieldType, you can now + dynamically set the "single_control" option instead. Before: ``` + public function getParent(array $options) + { + return $options['expanded'] ? 'form' : 'field'; + } + ``` + + After: + + ``` + public function setDefaultOptions(OptionsResolver $resolver) + { + $singleControl = function (Options $options) { + return !$options['expanded']; + }; + + $resolver->setDefaults(array( + 'single_control' => $singleControl, + )); + } + + public function getParent() + { + return 'form'; + } + ``` + + * A third argument $options was added to the methods `buildView()` and + `buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`. + Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last, + all methods in these types now receive instances of `FormBuilderInterface` + and `FormViewInterface` where they received instances of `FormBuilder` and + `FormView` before. You need to adapt your implementing classes. + + Before: + + ``` + public function buildForm(FormBuilder $builder, array $options) public function buildView(FormView $view, FormInterface $form) public function buildViewBottomUp(FormView $view, FormInterface $form) ``` @@ -625,8 +639,9 @@ After: ``` - public function buildView(FormView $view, FormInterface $form, array $options) - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) + public function buildViewBottomUp(FormViewInterface $view, FormInterface $form, array $options) ``` ### Validator diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index a4c393303c..c9d218f948 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -13,7 +13,7 @@ namespace Symfony\Bridge\Doctrine\Form\Type; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ObjectManager; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface; use Symfony\Bridge\Doctrine\Form\EventListener\MergeDoctrineCollectionListener; @@ -34,7 +34,7 @@ abstract class DoctrineType extends AbstractType $this->registry = $registry; } - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['multiple']) { $builder @@ -94,7 +94,7 @@ abstract class DoctrineType extends AbstractType */ abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class); - public function getParent(array $options) + public function getParent() { return 'choice'; } diff --git a/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php b/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php index 9fe1def8a2..713eaf5aea 100644 --- a/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php +++ b/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php @@ -14,7 +14,7 @@ namespace Symfony\Bridge\Propel1\Form\Type; use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList; use Symfony\Bridge\Propel1\Form\DataTransformer\CollectionToArrayTransformer; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -25,7 +25,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ class ModelType extends AbstractType { - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['multiple']) { $builder->prependClientTransformer(new CollectionToArrayTransformer()); @@ -58,7 +58,7 @@ class ModelType extends AbstractType )); } - public function getParent(array $options) + public function getParent() { return 'choice'; } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php index b1b0bd2e46..f130b3ce19 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Form; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\Event\FilterDataEvent; @@ -29,7 +29,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ class UserLoginFormType extends AbstractType { - private $reqeust; + private $request; /** * @param Request $request A request instance @@ -42,7 +42,7 @@ class UserLoginFormType extends AbstractType /** * @see Symfony\Component\Form\AbstractType::buildForm() */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('username', 'text') diff --git a/src/Symfony/Component/Form/AbstractType.php b/src/Symfony/Component/Form/AbstractType.php index 823350c8d9..c5bcb38a06 100644 --- a/src/Symfony/Component/Form/AbstractType.php +++ b/src/Symfony/Component/Form/AbstractType.php @@ -28,21 +28,21 @@ abstract class AbstractType implements FormTypeInterface /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { } /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { } /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { } @@ -92,7 +92,7 @@ abstract class AbstractType implements FormTypeInterface /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'form'; } diff --git a/src/Symfony/Component/Form/AbstractTypeExtension.php b/src/Symfony/Component/Form/AbstractTypeExtension.php index c1c0423361..431abfc53e 100644 --- a/src/Symfony/Component/Form/AbstractTypeExtension.php +++ b/src/Symfony/Component/Form/AbstractTypeExtension.php @@ -21,21 +21,21 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { } /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { } /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { } diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 24ccd19bc6..b765236e81 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -43,7 +43,6 @@ CHANGELOG * forms now don't create an empty object anymore if they are completely empty and not required. The empty value for such forms is null. * added constant Guess::VERY_HIGH_CONFIDENCE - * [BC BREAK] FormType::getParent() does not see default options anymore * [BC BREAK] The methods `add`, `remove`, `setParent`, `bind` and `setData` in class Form now throw an exception if the form is already bound * fields of constrained classes without a NotBlank or NotNull constraint are @@ -95,8 +94,15 @@ CHANGELOG * deprecated the methods `getDefaultOptions` and `getAllowedOptionValues` in FormTypeInterface and FormTypeExtensionInterface * options passed during construction can now be accessed from FormConfigInterface + * added FormBuilderInterface, FormViewInterface and FormConfigEditorInterface + * [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now + receive FormBuilderInterface and FormViewInterface instead of FormBuilder and + FormView + * [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in + FormTypeInterface and FormTypeExtensionInterface * [BC BREAK] the options array is now passed as last argument of the methods * `buildView` - * `buildViewBottomUp` + * `finishView` in FormTypeInterface and FormTypeExtensionInterface + * [BC BREAK] no options are passed to `getParent` of FormTypeInterface anymore diff --git a/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php b/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php index a2772ae527..c27b78535a 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php @@ -29,7 +29,7 @@ class BirthdayType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'date'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php b/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php index 114054a34e..75d492b9e7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php @@ -12,10 +12,10 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class CheckboxType extends AbstractType @@ -23,7 +23,7 @@ class CheckboxType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->appendClientTransformer(new BooleanToStringTransformer($options['value'])) @@ -33,7 +33,7 @@ class CheckboxType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view ->set('value', $options['value']) @@ -60,7 +60,7 @@ class CheckboxType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 90a87af9c4..c1d0bca732 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -12,9 +12,9 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList; use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; @@ -34,7 +34,7 @@ class ChoiceType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) { throw new FormException('Either the option "choices" or "choice_list" must be set.'); @@ -73,7 +73,7 @@ class ChoiceType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view ->set('multiple', $options['multiple']) @@ -95,7 +95,7 @@ class ChoiceType extends AbstractType /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { if ($options['expanded']) { // Radio buttons should have the same name as the parent @@ -178,7 +178,7 @@ class ChoiceType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } @@ -194,11 +194,11 @@ class ChoiceType extends AbstractType /** * Adds the sub fields for an expanded choice field. * - * @param FormBuilder $builder The form builder. - * @param array $choiceViews The choice view objects. - * @param array $options The build options. + * @param FormBuilderInterface $builder The form builder. + * @param array $choiceViews The choice view objects. + * @param array $options The build options. */ - private function addSubForms(FormBuilder $builder, array $choiceViews, array $options) + private function addSubForms(FormBuilderInterface $builder, array $choiceViews, array $options) { foreach ($choiceViews as $i => $choiceView) { if (is_array($choiceView)) { diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index b31c1d4e94..bfe4c4b482 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -12,8 +12,8 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -23,7 +23,7 @@ class CollectionType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array( @@ -46,7 +46,7 @@ class CollectionType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view ->set('allow_add', $options['allow_add']) @@ -61,7 +61,7 @@ class CollectionType extends AbstractType /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { if ($form->getConfig()->hasAttribute('prototype') && $view->get('prototype')->get('multipart')) { $view->set('multipart', true); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php index 3316db119d..11838fdd5a 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CountryType.php @@ -30,7 +30,7 @@ class CountryType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'choice'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index 6926c51727..8732b0ed79 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -13,8 +13,8 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormBuilder; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\ReversedTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; @@ -29,7 +29,7 @@ class DateTimeType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $parts = array('year', 'month', 'day', 'hour', 'minute'); $timeParts = array('hour', 'minute'); @@ -116,7 +116,7 @@ class DateTimeType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view->set('widget', $options['widget']); @@ -197,7 +197,7 @@ class DateTimeType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index d0c6a3e0d0..8a3a8fcbdb 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -13,9 +13,9 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Exception\CreationException; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; @@ -31,7 +31,7 @@ class DateType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $format = $options['format']; $pattern = null; @@ -136,7 +136,7 @@ class DateType extends AbstractType /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { $view->set('widget', $options['widget']); @@ -209,7 +209,7 @@ class DateType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php b/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php index 0afad854d1..26652ef660 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/EmailType.php @@ -18,7 +18,7 @@ class EmailType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'text'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index 8d76c4f3aa..1df97569b7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class FileType extends AbstractType @@ -21,7 +21,7 @@ class FileType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view ->set('type', 'file') @@ -32,7 +32,7 @@ class FileType extends AbstractType /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { $view ->set('multipart', true) @@ -52,7 +52,7 @@ class FileType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 4a75c688be..4cf34c96f8 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -14,9 +14,10 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Util\PropertyPath; use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormFactoryInterface; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -29,7 +30,7 @@ class FormType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->setRequired($options['required']) @@ -53,7 +54,7 @@ class FormType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $name = $form->getName(); $readOnly = $options['read_only']; @@ -115,7 +116,7 @@ class FormType extends AbstractType /** * {@inheritdoc} */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { $multipart = false; @@ -216,7 +217,7 @@ class FormType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return null; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/HiddenType.php b/src/Symfony/Component/Form/Extension/Core/Type/HiddenType.php index 51b4c0e71c..c06e9dc83c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/HiddenType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/HiddenType.php @@ -33,7 +33,7 @@ class HiddenType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php b/src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php index 17b6f2b85b..e3f445195c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,7 +21,7 @@ class IntegerType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->appendClientTransformer( new IntegerToLocalizedStringTransformer( @@ -61,7 +61,7 @@ class IntegerType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php index bdcf6f82df..3bfed8ba1f 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php @@ -30,7 +30,7 @@ class LanguageType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'choice'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php index ffdf7ab4cd..ef1c073db4 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php @@ -30,7 +30,7 @@ class LocaleType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'choice'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php index faa864eec5..8d2e2b115b 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php @@ -13,9 +13,9 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class MoneyType extends AbstractType @@ -25,7 +25,7 @@ class MoneyType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->appendClientTransformer(new MoneyToLocalizedStringTransformer( @@ -40,7 +40,7 @@ class MoneyType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view->set('money_pattern', self::getPattern($options['currency'])); } @@ -62,7 +62,7 @@ class MoneyType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/NumberType.php b/src/Symfony/Component/Form/Extension/Core/Type/NumberType.php index a5bb48fb45..d939d2d217 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/NumberType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/NumberType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,7 +21,7 @@ class NumberType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->appendClientTransformer(new NumberToLocalizedStringTransformer( $options['precision'], @@ -59,7 +59,7 @@ class NumberType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php b/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php index ffa94dab31..ba327487f3 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php @@ -13,8 +13,8 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormBuilder; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class PasswordType extends AbstractType @@ -22,7 +22,7 @@ class PasswordType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { if ($options['always_empty'] || !$form->isBound()) { $view->set('value', ''); @@ -42,7 +42,7 @@ class PasswordType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'text'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/PercentType.php b/src/Symfony/Component/Form/Extension/Core/Type/PercentType.php index 644e8adfb7..7a924be61b 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/PercentType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/PercentType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,7 +21,7 @@ class PercentType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->appendClientTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type'])); } @@ -48,7 +48,7 @@ class PercentType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php b/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php index db22b41a70..dfa7c7d53b 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/RadioType.php @@ -18,7 +18,7 @@ class RadioType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'checkbox'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php b/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php index cc53e3b859..e9e64b9a5c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -22,7 +22,7 @@ class RepeatedType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { // Overwrite required option for child fields $options['first_options']['required'] = $options['required']; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php b/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php index 2f5c417a65..bf82972d56 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/SearchType.php @@ -18,7 +18,7 @@ class SearchType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'text'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TextType.php b/src/Symfony/Component/Form/Extension/Core/Type/TextType.php index e984902f8c..01aa044b5a 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TextType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TextType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToStringTransformer; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,7 +21,7 @@ class TextType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->appendClientTransformer(new ValueToStringTransformer()) @@ -41,7 +41,7 @@ class TextType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php b/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php index d9b0e5c7b6..bebfce89da 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormInterface; class TextareaType extends AbstractType @@ -20,7 +20,7 @@ class TextareaType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view->set('pattern', null); } @@ -28,7 +28,7 @@ class TextareaType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'text'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php index 8c40a791a0..b840745b44 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php @@ -13,12 +13,12 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\ReversedTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -27,7 +27,7 @@ class TimeType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $parts = array('hour', 'minute'); $format = 'H:i'; @@ -113,7 +113,7 @@ class TimeType extends AbstractType /** * {@inheritdoc} */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormViewInterface $view, FormInterface $form, array $options) { $view ->set('widget', $options['widget']) @@ -193,7 +193,7 @@ class TimeType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'field'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php index c974581afe..d7c3cb0943 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimezoneType.php @@ -35,7 +35,7 @@ class TimezoneType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'choice'; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php index 9ffb20d76a..8bcc5bf852 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -21,7 +21,7 @@ class UrlType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventSubscriber(new FixUrlProtocolListener($options['default_protocol'])); } @@ -39,7 +39,7 @@ class UrlType extends AbstractType /** * {@inheritdoc} */ - public function getParent(array $options) + public function getParent() { return 'text'; } diff --git a/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php b/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php index b37b1f353b..3638f9e1d4 100644 --- a/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php +++ b/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php @@ -14,8 +14,8 @@ namespace Symfony\Component\Form\Extension\Csrf\Type; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener; -use Symfony\Component\Form\FormBuilder; -use Symfony\Component\Form\FormView; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -41,7 +41,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension * @param FormBuilder $builder The form builder * @param array $options The options */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { if (!$options['csrf_protection']) { return; @@ -59,7 +59,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension * @param FormView $view The form view * @param FormInterface $form The form */ - public function buildViewBottomUp(FormView $view, FormInterface $form, array $options) + public function finishView(FormViewInterface $view, FormInterface $form, array $options) { if ($options['csrf_protection'] && !$view->hasParent() && !$options['single_control']) { $factory = $form->getConfig()->getAttribute('csrf_factory'); diff --git a/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php b/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php index aed5ee6f87..4455c48fa0 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php +++ b/src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Validator\Type; use Symfony\Component\Form\AbstractTypeExtension; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper; use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener; use Symfony\Component\Validator\ValidatorInterface; @@ -43,7 +43,7 @@ class FormTypeValidatorExtension extends AbstractTypeExtension /** * {@inheritdoc} */ - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventSubscriber(new ValidationListener($this->validator, $this->violationMapper)); } diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index cda238e720..841bb882e5 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -957,10 +957,10 @@ class Form implements \IteratorAggregate, FormInterface } foreach ($types as $type) { - $type->buildViewBottomUp($view, $this, $options); + $type->finishView($view, $this, $options); foreach ($type->getExtensions() as $typeExtension) { - $typeExtension->buildViewBottomUp($view, $this, $options); + $typeExtension->finishView($view, $this, $options); } } diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index 2929a58c54..2dac8bab04 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -22,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; * * @author Bernhard Schussek */ -class FormBuilder extends FormConfig +class FormBuilder extends FormConfig implements FormBuilderInterface { /** * The form factory. @@ -69,9 +69,7 @@ class FormBuilder extends FormConfig } /** - * Returns the associated form factory. - * - * @return FormFactoryInterface The factory + * {@inheritdoc} */ public function getFormFactory() { @@ -79,17 +77,7 @@ class FormBuilder extends FormConfig } /** - * Adds a new field to this group. A field must have a unique name within - * the group. Otherwise the existing field is overwritten. - * - * If you add a nested group, this group should also be represented in the - * object hierarchy. - * - * @param string|FormBuilder $child - * @param string|FormTypeInterface $type - * @param array $options - * - * @return FormBuilder The builder object. + * {@inheritdoc} */ public function add($child, $type = null, array $options = array()) { @@ -124,13 +112,7 @@ class FormBuilder extends FormConfig } /** - * Creates a form builder. - * - * @param string $name The name of the form or the name of the property - * @param string|FormTypeInterface $type The type of the form or null if name is a property - * @param array $options The options - * - * @return FormBuilder The created builder. + * {@inheritdoc} */ public function create($name, $type = null, array $options = array()) { @@ -146,13 +128,7 @@ class FormBuilder extends FormConfig } /** - * Returns a child by name. - * - * @param string $name The name of the child - * - * @return FormBuilder The builder for the child - * - * @throws FormException if the given child does not exist + * {@inheritdoc} */ public function get($name) { @@ -168,11 +144,7 @@ class FormBuilder extends FormConfig } /** - * Removes the field with the given name. - * - * @param string $name - * - * @return FormBuilder The builder object. + * {@inheritdoc} */ public function remove($name) { @@ -189,11 +161,7 @@ class FormBuilder extends FormConfig } /** - * Returns whether a field with the given name exists. - * - * @param string $name - * - * @return Boolean + * {@inheritdoc} */ public function has($name) { @@ -209,9 +177,7 @@ class FormBuilder extends FormConfig } /** - * Returns the children. - * - * @return array + * {@inheritdoc} */ public function all() { @@ -221,9 +187,7 @@ class FormBuilder extends FormConfig } /** - * Creates the form. - * - * @return Form The form + * {@inheritdoc} */ public function getForm() { @@ -244,9 +208,7 @@ class FormBuilder extends FormConfig } /** - * Returns the parent builder. - * - * @return FormBuilder The parent builder + * {@inheritdoc} */ public function getParent() { @@ -254,13 +216,9 @@ class FormBuilder extends FormConfig } /** - * Sets the parent builder. - * - * @param FormBuilder $parent The parent builder - * - * @return FormBuilder The builder object. + * {@inheritdoc} */ - public function setParent(FormBuilder $parent = null) + public function setParent(FormBuilderInterface $parent = null) { $this->parent = $parent; diff --git a/src/Symfony/Component/Form/FormBuilderInterface.php b/src/Symfony/Component/Form/FormBuilderInterface.php new file mode 100644 index 0000000000..2bd182de84 --- /dev/null +++ b/src/Symfony/Component/Form/FormBuilderInterface.php @@ -0,0 +1,109 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form; + +/** + * @author Bernhard Schussek + */ +interface FormBuilderInterface extends FormConfigEditorInterface +{ + /** + * Adds a new field to this group. A field must have a unique name within + * the group. Otherwise the existing field is overwritten. + * + * If you add a nested group, this group should also be represented in the + * object hierarchy. + * + * @param string|FormBuilderInterface $child + * @param string|FormTypeInterface $type + * @param array $options + * + * @return FormBuilderInterface The builder object. + */ + function add($child, $type = null, array $options = array()); + + /** + * Creates a form builder. + * + * @param string $name The name of the form or the name of the property + * @param string|FormTypeInterface $type The type of the form or null if name is a property + * @param array $options The options + * + * @return FormBuilderInterface The created builder. + */ + function create($name, $type = null, array $options = array()); + + /** + * Returns a child by name. + * + * @param string $name The name of the child + * + * @return FormBuilderInterface The builder for the child + * + * @throws Exception\FormException if the given child does not exist + */ + function get($name); + /** + * Removes the field with the given name. + * + * @param string $name + * + * @return FormBuilderInterface The builder object. + */ + function remove($name); + + /** + * Returns whether a field with the given name exists. + * + * @param string $name + * + * @return Boolean + */ + function has($name); + + /** + * Returns the children. + * + * @return array + */ + function all(); + + /** + * Returns the associated form factory. + * + * @return FormFactoryInterface The factory + */ + function getFormFactory(); + + /** + * Creates the form. + * + * @return Form The form + */ + function getForm(); + + /** + * Returns the parent builder. + * + * @return FormBuilderInterface The parent builder + */ + function getParent(); + + /** + * Sets the parent builder. + * + * @param FormBuilderInterface $parent The parent builder + * + * @return FormBuilderInterface The builder object. + */ + function setParent(FormBuilderInterface $parent = null); +} diff --git a/src/Symfony/Component/Form/FormConfig.php b/src/Symfony/Component/Form/FormConfig.php index f12111b9c4..204ae6698f 100644 --- a/src/Symfony/Component/Form/FormConfig.php +++ b/src/Symfony/Component/Form/FormConfig.php @@ -21,7 +21,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; * * @author Bernhard Schussek */ -class FormConfig implements FormConfigInterface +class FormConfig implements FormConfigEditorInterface { /** * @var EventDispatcherInterface @@ -146,15 +146,7 @@ class FormConfig implements FormConfigInterface } /** - * Adds an event listener to an event on this form. - * - * @param string $eventName The name of the event to listen to. - * @param callable $listener The listener to execute. - * @param integer $priority The priority of the listener. Listeners - * with a higher priority are called before - * listeners with a lower priority. - * - * @return self The configuration object. + * {@inheritdoc} */ public function addEventListener($eventName, $listener, $priority = 0) { @@ -164,11 +156,7 @@ class FormConfig implements FormConfigInterface } /** - * Adds an event subscriber for events on this form. - * - * @param EventSubscriberInterface $subscriber The subscriber to attach. - * - * @return self The configuration object. + * {@inheritdoc} */ public function addEventSubscriber(EventSubscriberInterface $subscriber) { @@ -178,13 +166,7 @@ class FormConfig implements FormConfigInterface } /** - * Adds a validator to the form. - * - * @param FormValidatorInterface $validator The validator. - * - * @return self The configuration object. - * - * @deprecated Deprecated since version 2.1, to be removed in 2.3. + * {@inheritdoc} */ public function addValidator(FormValidatorInterface $validator) { @@ -194,11 +176,7 @@ class FormConfig implements FormConfigInterface } /** - * Appends a transformer to the client transformer chain - * - * @param DataTransformerInterface $clientTransformer - * - * @return self The configuration object. + * {@inheritdoc} */ public function appendClientTransformer(DataTransformerInterface $clientTransformer) { @@ -208,11 +186,7 @@ class FormConfig implements FormConfigInterface } /** - * Prepends a transformer to the client transformer chain. - * - * @param DataTransformerInterface $clientTransformer - * - * @return self The configuration object. + * {@inheritdoc} */ public function prependClientTransformer(DataTransformerInterface $clientTransformer) { @@ -222,9 +196,7 @@ class FormConfig implements FormConfigInterface } /** - * Clears the client transformers. - * - * @return self The configuration object. + * {@inheritdoc} */ public function resetClientTransformers() { @@ -234,11 +206,7 @@ class FormConfig implements FormConfigInterface } /** - * Appends a transformer to the normalization transformer chain - * - * @param DataTransformerInterface $normTransformer - * - * @return self The configuration object. + * {@inheritdoc} */ public function appendNormTransformer(DataTransformerInterface $normTransformer) { @@ -248,11 +216,7 @@ class FormConfig implements FormConfigInterface } /** - * Prepends a transformer to the normalization transformer chain - * - * @param DataTransformerInterface $normTransformer - * - * @return self The configuration object. + * {@inheritdoc} */ public function prependNormTransformer(DataTransformerInterface $normTransformer) { @@ -262,9 +226,7 @@ class FormConfig implements FormConfigInterface } /** - * Clears the normalization transformers. - * - * @return self The configuration object. + * {@inheritdoc} */ public function resetNormTransformers() { @@ -346,9 +308,7 @@ class FormConfig implements FormConfigInterface } /** - * Returns the data mapper of the form. - * - * @return DataMapperInterface The data mapper. + * {@inheritdoc} */ public function getDataMapper() { @@ -460,12 +420,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets the value for an attribute. - * - * @param string $name The name of the attribute - * @param string $value The value of the attribute - * - * @return self The configuration object. + * {@inheritdoc} */ public function setAttribute($name, $value) { @@ -475,11 +430,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets the attributes. - * - * @param array $attributes The attributes. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setAttributes(array $attributes) { @@ -489,11 +440,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets the data mapper used by the form. - * - * @param DataMapperInterface $dataMapper - * - * @return self The configuration object. + * {@inheritdoc} */ public function setDataMapper(DataMapperInterface $dataMapper = null) { @@ -503,11 +450,7 @@ class FormConfig implements FormConfigInterface } /** - * Set whether the form is disabled. - * - * @param Boolean $disabled Whether the form is disabled - * - * @return self The configuration object. + * {@inheritdoc} */ public function setDisabled($disabled) { @@ -517,11 +460,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets the data used for the client data when no value is bound. - * - * @param mixed $emptyData The empty data. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setEmptyData($emptyData) { @@ -531,11 +470,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets whether errors bubble up to the parent. - * - * @param Boolean $errorBubbling - * - * @return self The configuration object. + * {@inheritdoc} */ public function setErrorBubbling($errorBubbling) { @@ -545,11 +480,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets whether this field is required to be filled out when bound. - * - * @param Boolean $required - * - * @return self The configuration object. + * {@inheritdoc} */ public function setRequired($required) { @@ -559,13 +490,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets the property path that the form should be mapped to. - * - * @param string|PropertyPath $propertyPath The property path or null if the path - * should be set automatically based on - * the form's name. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setPropertyPath($propertyPath) { @@ -579,12 +504,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets whether the form should be mapped to an element of its - * parent's data. - * - * @param Boolean $mapped Whether the form should be mapped. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setMapped($mapped) { @@ -594,12 +514,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets whether the form's data should be modified by reference. - * - * @param Boolean $byReference Whether the data should be - modified by reference. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setByReference($byReference) { @@ -609,11 +524,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets whether the form should be virtual. - * - * @param Boolean $virtual Whether the form should be virtual. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setVirtual($virtual) { @@ -623,11 +534,7 @@ class FormConfig implements FormConfigInterface } /** - * Set the types. - * - * @param array $types An array FormTypeInterface - * - * @return self The configuration object. + * {@inheritdoc} */ public function setTypes(array $types) { @@ -637,11 +544,7 @@ class FormConfig implements FormConfigInterface } /** - * Sets the initial data of the form. - * - * @param array $data The data of the form in application format. - * - * @return self The configuration object. + * {@inheritdoc} */ public function setData($data) { diff --git a/src/Symfony/Component/Form/FormConfigEditorInterface.php b/src/Symfony/Component/Form/FormConfigEditorInterface.php new file mode 100644 index 0000000000..87b92b0793 --- /dev/null +++ b/src/Symfony/Component/Form/FormConfigEditorInterface.php @@ -0,0 +1,225 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * @author Bernhard Schussek + */ +interface FormConfigEditorInterface extends FormConfigInterface +{ + /** + * Adds an event listener to an event on this form. + * + * @param string $eventName The name of the event to listen to. + * @param callable $listener The listener to execute. + * @param integer $priority The priority of the listener. Listeners + * with a higher priority are called before + * listeners with a lower priority. + * + * @return self The configuration object. + */ + function addEventListener($eventName, $listener, $priority = 0); + + /** + * Adds an event subscriber for events on this form. + * + * @param EventSubscriberInterface $subscriber The subscriber to attach. + * + * @return self The configuration object. + */ + function addEventSubscriber(EventSubscriberInterface $subscriber); + + /** + * Adds a validator to the form. + * + * @param FormValidatorInterface $validator The validator. + * + * @return self The configuration object. + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. + */ + function addValidator(FormValidatorInterface $validator); + + /** + * Appends a transformer to the client transformer chain + * + * @param DataTransformerInterface $clientTransformer + * + * @return self The configuration object. + */ + function appendClientTransformer(DataTransformerInterface $clientTransformer); + + /** + * Prepends a transformer to the client transformer chain. + * + * @param DataTransformerInterface $clientTransformer + * + * @return self The configuration object. + */ + function prependClientTransformer(DataTransformerInterface $clientTransformer); + + /** + * Clears the client transformers. + * + * @return self The configuration object. + */ + function resetClientTransformers(); + + /** + * Appends a transformer to the normalization transformer chain + * + * @param DataTransformerInterface $normTransformer + * + * @return self The configuration object. + */ + function appendNormTransformer(DataTransformerInterface $normTransformer); + + /** + * Prepends a transformer to the normalization transformer chain + * + * @param DataTransformerInterface $normTransformer + * + * @return self The configuration object. + */ + function prependNormTransformer(DataTransformerInterface $normTransformer); + + /** + * Clears the normalization transformers. + * + * @return self The configuration object. + */ + function resetNormTransformers(); + + /** + * Sets the value for an attribute. + * + * @param string $name The name of the attribute + * @param string $value The value of the attribute + * + * @return self The configuration object. + */ + function setAttribute($name, $value); + + /** + * Sets the attributes. + * + * @param array $attributes The attributes. + * + * @return self The configuration object. + */ + function setAttributes(array $attributes); + + /** + * Sets the data mapper used by the form. + * + * @param DataMapperInterface $dataMapper + * + * @return self The configuration object. + */ + function setDataMapper(DataMapperInterface $dataMapper = null); + + /** + * Set whether the form is disabled. + * + * @param Boolean $disabled Whether the form is disabled + * + * @return self The configuration object. + */ + function setDisabled($disabled); + + /** + * Sets the data used for the client data when no value is bound. + * + * @param mixed $emptyData The empty data. + * + * @return self The configuration object. + */ + function setEmptyData($emptyData); + + /** + * Sets whether errors bubble up to the parent. + * + * @param Boolean $errorBubbling + * + * @return self The configuration object. + */ + function setErrorBubbling($errorBubbling); + + /** + * Sets whether this field is required to be filled out when bound. + * + * @param Boolean $required + * + * @return self The configuration object. + */ + function setRequired($required); + + /** + * Sets the property path that the form should be mapped to. + * + * @param string|PropertyPath $propertyPath The property path or null if the path + * should be set automatically based on + * the form's name. + * + * @return self The configuration object. + */ + function setPropertyPath($propertyPath); + + /** + * Sets whether the form should be mapped to an element of its + * parent's data. + * + * @param Boolean $mapped Whether the form should be mapped. + * + * @return self The configuration object. + */ + function setMapped($mapped); + + /** + * Sets whether the form's data should be modified by reference. + * + * @param Boolean $byReference Whether the data should be + modified by reference. + * + * @return self The configuration object. + */ + function setByReference($byReference); + + /** + * Sets whether the form should be virtual. + * + * @param Boolean $virtual Whether the form should be virtual. + * + * @return self The configuration object. + */ + function setVirtual($virtual); + + /** + * Set the types. + * + * @param array $types An array FormTypeInterface + * + * @return self The configuration object. + */ + function setTypes(array $types); + + /** + * Sets the initial data of the form. + * + * @param array $data The data of the form in application format. + * + * @return self The configuration object. + */ + function setData($data); +} diff --git a/src/Symfony/Component/Form/FormTypeExtensionInterface.php b/src/Symfony/Component/Form/FormTypeExtensionInterface.php index 686adddba2..9e88b37f8e 100644 --- a/src/Symfony/Component/Form/FormTypeExtensionInterface.php +++ b/src/Symfony/Component/Form/FormTypeExtensionInterface.php @@ -21,43 +21,43 @@ interface FormTypeExtensionInterface /** * Builds the form. * - * This method gets called after the extended type has built the form to + * This method is called after the extended type has built the form to * further modify it. * * @see FormTypeInterface::buildForm() * - * @param FormBuilder $builder The form builder - * @param array $options The options + * @param FormBuilderInterface $builder The form builder + * @param array $options The options */ - function buildForm(FormBuilder $builder, array $options); + function buildForm(FormBuilderInterface $builder, array $options); /** * Builds the view. * - * This method gets called after the extended type has built the view to + * This method is called after the extended type has built the view to * further modify it. * * @see FormTypeInterface::buildView() * - * @param FormView $view The view - * @param FormInterface $form The form - * @param array $options The options + * @param FormViewInterface $view The view + * @param FormInterface $form The form + * @param array $options The options */ - function buildView(FormView $view, FormInterface $form, array $options); + function buildView(FormViewInterface $view, FormInterface $form, array $options); /** - * Builds the view. + * Finishes the view. * - * This method gets called after the extended type has built the view to + * This method is called after the extended type has finished the view to * further modify it. * - * @see FormTypeInterface::buildViewBottomUp() + * @see FormTypeInterface::finishView() * - * @param FormView $view The view - * @param FormInterface $form The form - * @param array $options The options + * @param FormViewInterface $view The view + * @param FormInterface $form The form + * @param array $options The options */ - function buildViewBottomUp(FormView $view, FormInterface $form, array $options); + function finishView(FormViewInterface $view, FormInterface $form, array $options); /** * Overrides the default options from the extended type. diff --git a/src/Symfony/Component/Form/FormTypeInterface.php b/src/Symfony/Component/Form/FormTypeInterface.php index 062fadd55f..66de14d0e8 100644 --- a/src/Symfony/Component/Form/FormTypeInterface.php +++ b/src/Symfony/Component/Form/FormTypeInterface.php @@ -21,49 +21,52 @@ interface FormTypeInterface /** * Builds the form. * - * This method gets called for each type in the hierarchy starting form the - * top most type. - * Type extensions can further modify the form. + * This method is called for each type in the hierarchy starting form the + * top most type. Type extensions can further modify the form. * * @see FormTypeExtensionInterface::buildForm() * - * @param FormBuilder $builder The form builder - * @param array $options The options + * @param FormBuilderInterface $builder The form builder + * @param array $options The options */ - function buildForm(FormBuilder $builder, array $options); + function buildForm(FormBuilderInterface $builder, array $options); /** * Builds the form view. * - * This method gets called for each type in the hierarchy starting form the - * top most type. - * Type extensions can further modify the view. + * This method is called for each type in the hierarchy starting form the + * top most type. Type extensions can further modify the view. + * + * A view of a form is built before the views of the child forms are built. + * This means that you cannot access child views in this method. If you need + * to do so, move your logic to {@link finishView()} instead. * * @see FormTypeExtensionInterface::buildView() * - * @param FormView $view The view - * @param FormInterface $form The form - * @param array $options The options + * @param FormViewInterface $view The view + * @param FormInterface $form The form + * @param array $options The options */ - function buildView(FormView $view, FormInterface $form, array $options); + function buildView(FormViewInterface $view, FormInterface $form, array $options); /** - * Builds the form view. + * Finishes the form view. * * This method gets called for each type in the hierarchy starting form the - * top most type. - * Type extensions can further modify the view. + * top most type. Type extensions can further modify the view. * - * Children views have been built when this method gets called so you get - * a chance to modify them. + * When this method is called, views of the form's children have already + * been built and finished and can be accessed. You should only implement + * such logic in this method that actually accesses child views. For everything + * else you are recommended to implement {@link buildView()} instead. * - * @see FormTypeExtensionInterface::buildViewBottomUp() + * @see FormTypeExtensionInterface::finishView() * - * @param FormView $view The view - * @param FormInterface $form The form - * @param array $options The options + * @param FormViewInterface $view The view + * @param FormInterface $form The form + * @param array $options The options */ - function buildViewBottomUp(FormView $view, FormInterface $form, array $options); + function finishView(FormViewInterface $view, FormInterface $form, array $options); /** * Returns a builder for the current type. @@ -75,7 +78,7 @@ interface FormTypeInterface * @param FormFactoryInterface $factory The form factory * @param array $options The options * - * @return FormBuilder|null A form builder or null when the type does not have a builder + * @return FormBuilderInterface|null A form builder or null when the type does not have a builder */ function createBuilder($name, FormFactoryInterface $factory, array $options); @@ -89,11 +92,9 @@ interface FormTypeInterface /** * Returns the name of the parent type. * - * @param array $options - * - * @return string|null The name of the parent type if any otherwise null + * @return string|null The name of the parent type if any, null otherwise. */ - function getParent(array $options); + function getParent(); /** * Returns the name of this type. diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index 2e5b6c7a61..bdd01718db 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -11,14 +11,10 @@ namespace Symfony\Component\Form; -use ArrayAccess; -use IteratorAggregate; -use Countable; - /** * @author Bernhard Schussek */ -class FormView implements ArrayAccess, IteratorAggregate, Countable +class FormView implements \IteratorAggregate, FormViewInterface { private $name; @@ -47,16 +43,16 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable $this->name = $name; } + /** + * {@inheritdoc} + */ public function getName() { return $this->name; } /** - * @param string $name - * @param mixed $value - * - * @return FormView The current view + * {@inheritdoc} */ public function set($name, $value) { @@ -66,9 +62,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * @param $name - * - * @return Boolean + * {@inheritdoc} */ public function has($name) { @@ -76,10 +70,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * @param $name - * @param $default - * - * @return mixed + * {@inheritdoc} */ public function get($name, $default = null) { @@ -91,7 +82,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * @return array + * {@inheritdoc} */ public function all() { @@ -124,9 +115,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns whether the attached form is rendered. - * - * @return Boolean Whether the form is rendered + * {@inheritdoc} */ public function isRendered() { @@ -150,9 +139,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Marks the attached form as rendered - * - * @return FormView The current view + * {@inheritdoc} */ public function setRendered() { @@ -162,13 +149,9 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Sets the parent view. - * - * @param FormView $parent The parent view - * - * @return FormView The current view + * {@inheritdoc} */ - public function setParent(FormView $parent = null) + public function setParent(FormViewInterface $parent = null) { $this->parent = $parent; @@ -176,9 +159,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns the parent view. - * - * @return FormView The parent view + * {@inheritdoc} */ public function getParent() { @@ -186,9 +167,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns whether this view has a parent. - * - * @return Boolean Whether this view has a parent + * {@inheritdoc} */ public function hasParent() { @@ -196,13 +175,9 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Adds a child view. - * - * @param FormView $child The child view to add. - * - * @return FormView The current view + * {@inheritdoc} */ - public function addChild(FormView $child) + public function addChild(FormViewInterface $child) { $this->children[$child->getName()] = $child; @@ -210,11 +185,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Removes a child view. - * - * @param string $name The name of the removed child view. - * - * @return FormView The current view + * {@inheritdoc} */ public function removeChild($name) { @@ -224,9 +195,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns the children. - * - * @return array The children as instances of FormView + * {@inheritdoc} */ public function getChildren() { @@ -234,11 +203,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns a given child. - * - * @param string $name The name of the child - * - * @return FormView The child view + * {@inheritdoc} */ public function getChild($name) { @@ -246,9 +211,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns whether this view has children. - * - * @return Boolean Whether this view has children + * {@inheritdoc} */ public function hasChildren() { @@ -256,11 +219,7 @@ class FormView implements ArrayAccess, IteratorAggregate, Countable } /** - * Returns whether this view has a given child. - * - * @param string $name The name of the child - * - * @return Boolean Whether the child with the given name exists + * {@inheritdoc} */ public function hasChild($name) { diff --git a/src/Symfony/Component/Form/FormViewInterface.php b/src/Symfony/Component/Form/FormViewInterface.php new file mode 100644 index 0000000000..94bdca546a --- /dev/null +++ b/src/Symfony/Component/Form/FormViewInterface.php @@ -0,0 +1,148 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form; + +/** + * @author Bernhard Schussek + */ +interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable +{ + /** + * Returns the name of the form. + * + * @return string The form name. + */ + function getName(); + + /** + * Sets a view variable. + * + * @param string $name The variable name. + * @param string $value The variable value. + * + * @return FormViewInterface The view object. + */ + function set($name, $value); + + /** + * Returns whether a view variable exists. + * + * @param string $name The variable name. + * + * @return Boolean Whether the variable exists. + */ + function has($name); + + /** + * Returns the value of a view variable. + * + * @param string $name The variable name. + * @param mixed $default The value to return if the variable is not set. + * + * @return mixed The variable value. + */ + function get($name, $default = null); + + /** + * Returns the values of all view variables. + * + * @return array The values of all variables. + */ + function all(); + + /** + * Returns whether the view was already rendered. + * + * @return Boolean Whether this view's widget is rendered. + */ + function isRendered(); + + /** + * Marks the view as rendered. + * + * @return FormViewInterface The view object. + */ + function setRendered(); + + /** + * Sets the parent view. + * + * @param FormViewInterface $parent The parent view. + * + * @return FormViewInterface The view object. + */ + function setParent(FormViewInterface $parent = null); + + /** + * Returns the parent view. + * + * @return FormViewInterface The parent view. + */ + function getParent(); + + /** + * Returns whether this view has a parent. + * + * @return Boolean Whether this view has a parent + */ + function hasParent(); + + /** + * Adds a child view. + * + * @param FormViewInterface $child The child view to add. + * + * @return FormViewInterface The view object. + */ + function addChild(FormViewInterface $child); + + /** + * Removes a child view. + * + * @param string $name The name of the removed child view. + * + * @return FormViewInterface The view object. + */ + function removeChild($name); + + /** + * Returns the children. + * + * @return array The children as instances of FormView + */ + function getChildren(); + + /** + * Returns a given child. + * + * @param string $name The name of the child + * + * @return FormViewInterface The child view + */ + function getChild($name); + + /** + * Returns whether this view has children. + * + * @return Boolean Whether this view has children + */ + function hasChildren(); + + /** + * Returns whether this view has a given child. + * + * @param string $name The name of the child + * + * @return Boolean Whether the child with the given name exists + */ + function hasChild($name); +} diff --git a/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php index 0fdea7d438..aae90101f1 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php @@ -12,13 +12,13 @@ namespace Symfony\Component\Form\Tests\Extension\Csrf\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Csrf\CsrfExtension; use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase; class FormTypeCsrfExtensionTest_ChildType extends AbstractType { - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { // The form needs a child in order to trigger CSRF protection by // default diff --git a/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php index a04046ae90..c5a27af573 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php @@ -3,12 +3,12 @@ namespace Symfony\Component\Form\Tests\Fixtures; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class AuthorType extends AbstractType { - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('firstName') diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooType.php b/src/Symfony/Component/Form/Tests/Fixtures/FooType.php index 7c8b0dd964..feae68900f 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FooType.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooType.php @@ -13,12 +13,13 @@ namespace Symfony\Component\Form\Tests\Fixtures; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\EventDispatcher\EventDispatcher; class FooType extends AbstractType { - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setAttribute('foo', 'x'); $builder->setAttribute('data_option', $options['data']); @@ -51,7 +52,7 @@ class FooType extends AbstractType ); } - public function getParent(array $options) + public function getParent() { return null; } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php index 31f9293634..c5f92e1191 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBarExtension.php @@ -12,11 +12,11 @@ namespace Symfony\Component\Form\Tests\Fixtures; use Symfony\Component\Form\AbstractTypeExtension; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; class FooTypeBarExtension extends AbstractTypeExtension { - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setAttribute('bar', 'x'); } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php index 33d328639e..2e36475449 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FooTypeBazExtension.php @@ -12,11 +12,11 @@ namespace Symfony\Component\Form\Tests\Fixtures; use Symfony\Component\Form\AbstractTypeExtension; -use Symfony\Component\Form\FormBuilder; +use Symfony\Component\Form\FormBuilderInterface; class FooTypeBazExtension extends AbstractTypeExtension { - public function buildForm(FormBuilder $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options) { $builder->setAttribute('baz', 'x'); } diff --git a/src/Symfony/Component/Form/Tests/FormTest.php b/src/Symfony/Component/Form/Tests/FormTest.php index e0188d9085..e7cce5f6e3 100644 --- a/src/Symfony/Component/Form/Tests/FormTest.php +++ b/src/Symfony/Component/Form/Tests/FormTest.php @@ -1132,30 +1132,30 @@ class FormTest extends \PHPUnit_Framework_TestCase })); $type1->expects($this->once()) - ->method('buildViewBottomUp') + ->method('finishView') ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { - $calls[] = 'type1::buildViewBottomUp'; + $calls[] = 'type1::finishView'; $test->assertTrue($view->hasChildren()); })); $type1Extension->expects($this->once()) - ->method('buildViewBottomUp') + ->method('finishView') ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { - $calls[] = 'type1ext::buildViewBottomUp'; + $calls[] = 'type1ext::finishView'; $test->assertTrue($view->hasChildren()); })); $type2->expects($this->once()) - ->method('buildViewBottomUp') + ->method('finishView') ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { - $calls[] = 'type2::buildViewBottomUp'; + $calls[] = 'type2::finishView'; $test->assertTrue($view->hasChildren()); })); $type2Extension->expects($this->once()) - ->method('buildViewBottomUp') + ->method('finishView') ->will($this->returnCallback(function (FormView $view, Form $form) use ($test, &$calls) { - $calls[] = 'type2ext::buildViewBottomUp'; + $calls[] = 'type2ext::finishView'; $test->assertTrue($view->hasChildren()); })); @@ -1170,10 +1170,10 @@ class FormTest extends \PHPUnit_Framework_TestCase 1 => 'type1ext::buildView', 2 => 'type2::buildView', 3 => 'type2ext::buildView', - 4 => 'type1::buildViewBottomUp', - 5 => 'type1ext::buildViewBottomUp', - 6 => 'type2::buildViewBottomUp', - 7 => 'type2ext::buildViewBottomUp', + 4 => 'type1::finishView', + 5 => 'type1ext::finishView', + 6 => 'type2::finishView', + 7 => 'type2ext::finishView', ), $calls); }