From d70d6c766ceeaae77ba28deb151e1e2fea788353 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Mon, 8 Dec 2014 08:03:20 +0100 Subject: [PATCH] Deprecated setDefaultOptions() in favor of configureOptions() --- AbstractType.php | 11 +++++++++++ AbstractTypeExtension.php | 11 +++++++++++ CHANGELOG.md | 6 ++++++ Extension/Core/Type/BaseType.php | 4 ++-- Extension/Core/Type/BirthdayType.php | 4 ++-- Extension/Core/Type/ButtonType.php | 6 +++--- Extension/Core/Type/CheckboxType.php | 4 ++-- Extension/Core/Type/ChoiceType.php | 4 ++-- Extension/Core/Type/CollectionType.php | 4 ++-- Extension/Core/Type/CountryType.php | 4 ++-- Extension/Core/Type/CurrencyType.php | 4 ++-- Extension/Core/Type/DateTimeType.php | 4 ++-- Extension/Core/Type/DateType.php | 4 ++-- Extension/Core/Type/FileType.php | 4 ++-- Extension/Core/Type/FormType.php | 6 +++--- Extension/Core/Type/HiddenType.php | 4 ++-- Extension/Core/Type/IntegerType.php | 4 ++-- Extension/Core/Type/LanguageType.php | 4 ++-- Extension/Core/Type/LocaleType.php | 4 ++-- Extension/Core/Type/MoneyType.php | 4 ++-- Extension/Core/Type/NumberType.php | 4 ++-- Extension/Core/Type/PasswordType.php | 4 ++-- Extension/Core/Type/PercentType.php | 4 ++-- Extension/Core/Type/RepeatedType.php | 4 ++-- Extension/Core/Type/TextType.php | 4 ++-- Extension/Core/Type/TimeType.php | 4 ++-- Extension/Core/Type/TimezoneType.php | 4 ++-- Extension/Core/Type/UrlType.php | 4 ++-- Extension/Csrf/Type/FormTypeCsrfExtension.php | 4 ++-- .../Validator/Type/BaseValidatorExtension.php | 4 ++-- .../Type/FormTypeValidatorExtension.php | 6 +++--- .../Type/RepeatedTypeValidatorExtension.php | 4 ++-- FormTypeExtensionInterface.php | 4 ++++ FormTypeInterface.php | 4 ++++ ResolvedFormType.php | 14 ++++++++++++++ Tests/Fixtures/AuthorType.php | 4 ++-- Tests/ResolvedFormTypeTest.php | 17 ++++++++--------- 37 files changed, 121 insertions(+), 72 deletions(-) diff --git a/AbstractType.php b/AbstractType.php index 6f7f5da653..08d6915344 100644 --- a/AbstractType.php +++ b/AbstractType.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** @@ -43,6 +44,16 @@ public function finishView(FormView $view, FormInterface $form, array $options) * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * Configures the options for this type. + * + * @param OptionsResolver $resolver The resolver for the options. + */ + public function configureOptions(OptionsResolver $resolver) { } diff --git a/AbstractTypeExtension.php b/AbstractTypeExtension.php index 351c80097f..140fe5fdd6 100644 --- a/AbstractTypeExtension.php +++ b/AbstractTypeExtension.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** @@ -43,6 +44,16 @@ public function finishView(FormView $view, FormInterface $form, array $options) * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) + { + $this->configureOptions($resolver); + } + + /** + * Configures the options for this type. + * + * @param OptionsResolver $resolver The resolver for the options. + */ + public function configureOptions(OptionsResolver $resolver) { } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 4611542054..07c96077c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +2.7.0 +----- + + * deprecated the overwriting of AbstractType::setDefaultOptions() in favor of overwriting AbstractType::configureOptions(). + * deprecated the overwriting of AbstractTypeExtension::setDefaultOptions() in favor of overwriting AbstractTypeExtension::configureOptions(). + 2.6.2 ----- diff --git a/Extension/Core/Type/BaseType.php b/Extension/Core/Type/BaseType.php index c03b7e88a7..c8610ee9d3 100644 --- a/Extension/Core/Type/BaseType.php +++ b/Extension/Core/Type/BaseType.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Encapsulates common logic of {@link FormType} and {@link ButtonType}. @@ -111,7 +111,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'block_name' => null, diff --git a/Extension/Core/Type/BirthdayType.php b/Extension/Core/Type/BirthdayType.php index f90f57d4b6..bc2711d586 100644 --- a/Extension/Core/Type/BirthdayType.php +++ b/Extension/Core/Type/BirthdayType.php @@ -12,14 +12,14 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class BirthdayType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'years' => range(date('Y') - 120, date('Y')), diff --git a/Extension/Core/Type/ButtonType.php b/Extension/Core/Type/ButtonType.php index c4b97652cd..7456adc93d 100644 --- a/Extension/Core/Type/ButtonType.php +++ b/Extension/Core/Type/ButtonType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\ButtonTypeInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * A form button. @@ -39,9 +39,9 @@ public function getName() /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - parent::setDefaultOptions($resolver); + parent::configureOptions($resolver); $resolver->setDefaults(array( 'auto_initialize' => false, diff --git a/Extension/Core/Type/CheckboxType.php b/Extension/Core/Type/CheckboxType.php index 13c78041d0..53a5e05275 100644 --- a/Extension/Core/Type/CheckboxType.php +++ b/Extension/Core/Type/CheckboxType.php @@ -16,7 +16,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer; use Symfony\Component\Form\FormView; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class CheckboxType extends AbstractType { @@ -49,7 +49,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $emptyData = function (FormInterface $form, $viewData) { return $viewData; diff --git a/Extension/Core/Type/ChoiceType.php b/Extension/Core/Type/ChoiceType.php index b705659e97..81b171fe5b 100644 --- a/Extension/Core/Type/ChoiceType.php +++ b/Extension/Core/Type/ChoiceType.php @@ -26,7 +26,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToValuesTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\ChoicesToBooleanArrayTransformer; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class ChoiceType extends AbstractType { @@ -161,7 +161,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $choiceListCache = & $this->choiceListCache; diff --git a/Extension/Core/Type/CollectionType.php b/Extension/Core/Type/CollectionType.php index 2fed7cea88..ccfec39682 100644 --- a/Extension/Core/Type/CollectionType.php +++ b/Extension/Core/Type/CollectionType.php @@ -17,7 +17,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class CollectionType extends AbstractType { @@ -72,7 +72,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $optionsNormalizer = function (Options $options, $value) { $value['block_name'] = 'entry'; diff --git a/Extension/Core/Type/CountryType.php b/Extension/Core/Type/CountryType.php index 3482ba6634..e6231c596b 100644 --- a/Extension/Core/Type/CountryType.php +++ b/Extension/Core/Type/CountryType.php @@ -13,14 +13,14 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Intl\Intl; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class CountryType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getRegionBundle()->getCountryNames(), diff --git a/Extension/Core/Type/CurrencyType.php b/Extension/Core/Type/CurrencyType.php index 3a925e3a3d..9d77b76381 100644 --- a/Extension/Core/Type/CurrencyType.php +++ b/Extension/Core/Type/CurrencyType.php @@ -13,14 +13,14 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Intl\Intl; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class CurrencyType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getCurrencyBundle()->getCurrencyNames(), diff --git a/Extension/Core/Type/DateTimeType.php b/Extension/Core/Type/DateTimeType.php index 252d370080..72e735787b 100644 --- a/Extension/Core/Type/DateTimeType.php +++ b/Extension/Core/Type/DateTimeType.php @@ -25,7 +25,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToRfc3339Transformer; use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class DateTimeType extends AbstractType { @@ -200,7 +200,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $compound = function (Options $options) { return $options['widget'] !== 'single_text'; diff --git a/Extension/Core/Type/DateType.php b/Extension/Core/Type/DateType.php index dc553ad8dd..48984b61f3 100644 --- a/Extension/Core/Type/DateType.php +++ b/Extension/Core/Type/DateType.php @@ -21,7 +21,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; use Symfony\Component\Form\ReversedTransformer; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; class DateType extends AbstractType @@ -165,7 +165,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $compound = function (Options $options) { return $options['widget'] !== 'single_text'; diff --git a/Extension/Core/Type/FileType.php b/Extension/Core/Type/FileType.php index 0f7bb3c7cd..bc24899de5 100644 --- a/Extension/Core/Type/FileType.php +++ b/Extension/Core/Type/FileType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class FileType extends AbstractType { @@ -47,7 +47,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'compound' => false, diff --git a/Extension/Core/Type/FormType.php b/Extension/Core/Type/FormType.php index a30de1df84..3fcacd50e9 100644 --- a/Extension/Core/Type/FormType.php +++ b/Extension/Core/Type/FormType.php @@ -18,7 +18,7 @@ use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; @@ -122,9 +122,9 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - parent::setDefaultOptions($resolver); + parent::configureOptions($resolver); // Derive "data_class" option from passed "data" object $dataClass = function (Options $options) { diff --git a/Extension/Core/Type/HiddenType.php b/Extension/Core/Type/HiddenType.php index 352b34620c..37b25435e1 100644 --- a/Extension/Core/Type/HiddenType.php +++ b/Extension/Core/Type/HiddenType.php @@ -12,14 +12,14 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class HiddenType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( // hidden fields cannot have a required attribute diff --git a/Extension/Core/Type/IntegerType.php b/Extension/Core/Type/IntegerType.php index 575dcb1fbd..b36637ad67 100644 --- a/Extension/Core/Type/IntegerType.php +++ b/Extension/Core/Type/IntegerType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class IntegerType extends AbstractType { @@ -34,7 +34,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( // default precision is locale specific (usually around 3) diff --git a/Extension/Core/Type/LanguageType.php b/Extension/Core/Type/LanguageType.php index 37b2bf3300..4bd09d26e9 100644 --- a/Extension/Core/Type/LanguageType.php +++ b/Extension/Core/Type/LanguageType.php @@ -13,14 +13,14 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Intl\Intl; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class LanguageType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getLanguageBundle()->getLanguageNames(), diff --git a/Extension/Core/Type/LocaleType.php b/Extension/Core/Type/LocaleType.php index 4610c1b459..92a41080e4 100644 --- a/Extension/Core/Type/LocaleType.php +++ b/Extension/Core/Type/LocaleType.php @@ -13,14 +13,14 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Intl\Intl; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class LocaleType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => Intl::getLocaleBundle()->getLocaleNames(), diff --git a/Extension/Core/Type/MoneyType.php b/Extension/Core/Type/MoneyType.php index 9653d6f8ab..781fe7ac65 100644 --- a/Extension/Core/Type/MoneyType.php +++ b/Extension/Core/Type/MoneyType.php @@ -16,7 +16,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer; use Symfony\Component\Form\FormView; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class MoneyType extends AbstractType { @@ -48,7 +48,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'precision' => 2, diff --git a/Extension/Core/Type/NumberType.php b/Extension/Core/Type/NumberType.php index 5b06e88bbe..946c9d44e4 100644 --- a/Extension/Core/Type/NumberType.php +++ b/Extension/Core/Type/NumberType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class NumberType extends AbstractType { @@ -33,7 +33,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( // default precision is locale specific (usually around 3) diff --git a/Extension/Core/Type/PasswordType.php b/Extension/Core/Type/PasswordType.php index 8f5633c6d1..611eb4d4a3 100644 --- a/Extension/Core/Type/PasswordType.php +++ b/Extension/Core/Type/PasswordType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class PasswordType extends AbstractType { @@ -31,7 +31,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'always_empty' => true, diff --git a/Extension/Core/Type/PercentType.php b/Extension/Core/Type/PercentType.php index 079eca0497..51632f031e 100644 --- a/Extension/Core/Type/PercentType.php +++ b/Extension/Core/Type/PercentType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class PercentType extends AbstractType { @@ -29,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'precision' => 0, diff --git a/Extension/Core/Type/RepeatedType.php b/Extension/Core/Type/RepeatedType.php index 47a3299359..a0d13f7faa 100644 --- a/Extension/Core/Type/RepeatedType.php +++ b/Extension/Core/Type/RepeatedType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\ValueToDuplicatesTransformer; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class RepeatedType extends AbstractType { @@ -44,7 +44,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'type' => 'text', diff --git a/Extension/Core/Type/TextType.php b/Extension/Core/Type/TextType.php index 11503261c5..4aef1cd6e6 100644 --- a/Extension/Core/Type/TextType.php +++ b/Extension/Core/Type/TextType.php @@ -12,14 +12,14 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class TextType extends AbstractType { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'compound' => false, diff --git a/Extension/Core/Type/TimeType.php b/Extension/Core/Type/TimeType.php index 4fd2cba56c..851d483f30 100644 --- a/Extension/Core/Type/TimeType.php +++ b/Extension/Core/Type/TimeType.php @@ -21,7 +21,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class TimeType extends AbstractType { @@ -157,7 +157,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $compound = function (Options $options) { return $options['widget'] !== 'single_text'; diff --git a/Extension/Core/Type/TimezoneType.php b/Extension/Core/Type/TimezoneType.php index 96b1407768..d19fb52fdc 100644 --- a/Extension/Core/Type/TimezoneType.php +++ b/Extension/Core/Type/TimezoneType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class TimezoneType extends AbstractType { @@ -26,7 +26,7 @@ class TimezoneType extends AbstractType /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'choices' => self::getTimezones(), diff --git a/Extension/Core/Type/UrlType.php b/Extension/Core/Type/UrlType.php index 5c414afc93..0deba91086 100644 --- a/Extension/Core/Type/UrlType.php +++ b/Extension/Core/Type/UrlType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class UrlType extends AbstractType { @@ -31,7 +31,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'default_protocol' => 'http', diff --git a/Extension/Csrf/Type/FormTypeCsrfExtension.php b/Extension/Csrf/Type/FormTypeCsrfExtension.php index b693894159..35d8648215 100644 --- a/Extension/Csrf/Type/FormTypeCsrfExtension.php +++ b/Extension/Csrf/Type/FormTypeCsrfExtension.php @@ -21,7 +21,7 @@ use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Component\Translation\TranslatorInterface; @@ -119,7 +119,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { // BC clause for the "intention" option $csrfTokenId = function (Options $options) { diff --git a/Extension/Validator/Type/BaseValidatorExtension.php b/Extension/Validator/Type/BaseValidatorExtension.php index f5bc00daa6..ada55dce27 100644 --- a/Extension/Validator/Type/BaseValidatorExtension.php +++ b/Extension/Validator/Type/BaseValidatorExtension.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Encapsulates common logic of {@link FormTypeValidatorExtension} and @@ -26,7 +26,7 @@ abstract class BaseValidatorExtension extends AbstractTypeExtension /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { // Make sure that validation groups end up as null, closure or array $validationGroupsNormalizer = function (Options $options, $groups) { diff --git a/Extension/Validator/Type/FormTypeValidatorExtension.php b/Extension/Validator/Type/FormTypeValidatorExtension.php index 89238be707..e5d57df166 100644 --- a/Extension/Validator/Type/FormTypeValidatorExtension.php +++ b/Extension/Validator/Type/FormTypeValidatorExtension.php @@ -17,7 +17,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * @author Bernhard Schussek @@ -58,9 +58,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - parent::setDefaultOptions($resolver); + parent::configureOptions($resolver); // Constraint should always be converted to an array $constraintsNormalizer = function (Options $options, $constraints) { diff --git a/Extension/Validator/Type/RepeatedTypeValidatorExtension.php b/Extension/Validator/Type/RepeatedTypeValidatorExtension.php index 858ff0fae1..3eacceae63 100644 --- a/Extension/Validator/Type/RepeatedTypeValidatorExtension.php +++ b/Extension/Validator/Type/RepeatedTypeValidatorExtension.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\OptionsResolver\Options; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * @author Bernhard Schussek @@ -23,7 +23,7 @@ class RepeatedTypeValidatorExtension extends AbstractTypeExtension /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { // Map errors to the first field $errorMapping = function (Options $options) { diff --git a/FormTypeExtensionInterface.php b/FormTypeExtensionInterface.php index 946c7a74b3..220eb6f4b0 100644 --- a/FormTypeExtensionInterface.php +++ b/FormTypeExtensionInterface.php @@ -63,6 +63,10 @@ public function finishView(FormView $view, FormInterface $form, array $options); * Overrides the default options from the extended type. * * @param OptionsResolverInterface $resolver The resolver for the options. + * + * @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0. + * Use the method configureOptions instead. This method will be + * added to the FormTypeExtensionInterface with Symfony 3.0 */ public function setDefaultOptions(OptionsResolverInterface $resolver); diff --git a/FormTypeInterface.php b/FormTypeInterface.php index 78f8bd0083..fc0bb046cb 100644 --- a/FormTypeInterface.php +++ b/FormTypeInterface.php @@ -72,6 +72,10 @@ public function finishView(FormView $view, FormInterface $form, array $options); * Sets the default options for this type. * * @param OptionsResolverInterface $resolver The resolver for the options. + * + * @deprecated Deprecated since Symfony 2.7, to be renamed in Symfony 3.0. + * Use the method configureOptions instead. This method will be + * added to the FormTypeInterface with Symfony 3.0. */ public function setDefaultOptions(OptionsResolverInterface $resolver); diff --git a/ResolvedFormType.php b/ResolvedFormType.php index 065189a42c..e3c897a981 100644 --- a/ResolvedFormType.php +++ b/ResolvedFormType.php @@ -205,8 +205,22 @@ public function getOptionsResolver() $this->innerType->setDefaultOptions($this->optionsResolver); + $reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions'); + $isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType'); + + if (true === $isOverwritten) { + trigger_error('The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED); + } + foreach ($this->typeExtensions as $extension) { $extension->setDefaultOptions($this->optionsResolver); + + $reflector = new \ReflectionMethod($extension, 'setDefaultOptions'); + $isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension'); + + if (true === $isOverwritten) { + trigger_error('The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED); + } } } diff --git a/Tests/Fixtures/AuthorType.php b/Tests/Fixtures/AuthorType.php index 147f6e4867..62c80cbb37 100644 --- a/Tests/Fixtures/AuthorType.php +++ b/Tests/Fixtures/AuthorType.php @@ -4,7 +4,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; class AuthorType extends AbstractType { @@ -21,7 +21,7 @@ public function getName() return 'author'; } - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', diff --git a/Tests/ResolvedFormTypeTest.php b/Tests/ResolvedFormTypeTest.php index 2f3fe61020..234d52cf39 100644 --- a/Tests/ResolvedFormTypeTest.php +++ b/Tests/ResolvedFormTypeTest.php @@ -12,9 +12,8 @@ namespace Symfony\Component\Form\Tests; use Symfony\Component\Form\ResolvedFormType; -use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormBuilder; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * @author Bernhard Schussek @@ -61,7 +60,7 @@ public function testGetOptionsResolver() $i = 0; $assertIndexAndAddOption = function ($index, $option, $default) use (&$i, $test) { - return function (OptionsResolverInterface $resolver) use (&$i, $test, $index, $option, $default) { + return function (OptionsResolver $resolver) use (&$i, $test, $index, $option, $default) { /* @var \PHPUnit_Framework_TestCase $test */ $test->assertEquals($index, $i, 'Executed at index '.$index); @@ -73,21 +72,21 @@ public function testGetOptionsResolver() // First the default options are generated for the super type $this->parentType->expects($this->once()) - ->method('setDefaultOptions') + ->method('configureOptions') ->will($this->returnCallback($assertIndexAndAddOption(0, 'a', 'a_default'))); // The form type itself $this->type->expects($this->once()) - ->method('setDefaultOptions') + ->method('configureOptions') ->will($this->returnCallback($assertIndexAndAddOption(1, 'b', 'b_default'))); // And its extensions $this->extension1->expects($this->once()) - ->method('setDefaultOptions') + ->method('configureOptions') ->will($this->returnCallback($assertIndexAndAddOption(2, 'c', 'c_default'))); $this->extension2->expects($this->once()) - ->method('setDefaultOptions') + ->method('configureOptions') ->will($this->returnCallback($assertIndexAndAddOption(3, 'd', 'd_default'))); $givenOptions = array('a' => 'a_custom', 'c' => 'c_custom'); @@ -311,7 +310,7 @@ public function testFinishView() */ private function getMockFormType() { - return $this->getMock('Symfony\Component\Form\FormTypeInterface'); + return $this->getMock('Symfony\Component\Form\AbstractType', array('getName', 'configureOptions', 'finishView', 'buildView', 'buildForm')); } /** @@ -319,7 +318,7 @@ private function getMockFormType() */ private function getMockFormTypeExtension() { - return $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface'); + return $this->getMock('Symfony\Component\Form\AbstractTypeExtension', array('getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm')); } /**