From 602678143f170826b18bb999d733ccd343e01a91 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 13 Jan 2015 21:58:30 +0100 Subject: [PATCH 1/2] Removed deprecated setDefaultOptions methods --- src/Symfony/Component/Form/AbstractType.php | 11 ---------- .../Component/Form/AbstractTypeExtension.php | 11 ---------- .../Form/FormTypeExtensionInterface.php | 11 ++++------ .../Component/Form/FormTypeInterface.php | 12 ++++------- .../Component/Form/ResolvedFormType.php | 20 +++---------------- .../Form/Tests/ResolvedFormTypeTest.php | 4 ++-- 6 files changed, 13 insertions(+), 56 deletions(-) diff --git a/src/Symfony/Component/Form/AbstractType.php b/src/Symfony/Component/Form/AbstractType.php index 08d69153445fe..e60fab0cf37ae 100644 --- a/src/Symfony/Component/Form/AbstractType.php +++ b/src/Symfony/Component/Form/AbstractType.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Form; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** * @author Bernhard Schussek @@ -43,16 +42,6 @@ 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/src/Symfony/Component/Form/AbstractTypeExtension.php b/src/Symfony/Component/Form/AbstractTypeExtension.php index 140fe5fdd6c8b..9d369bf294e96 100644 --- a/src/Symfony/Component/Form/AbstractTypeExtension.php +++ b/src/Symfony/Component/Form/AbstractTypeExtension.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Form; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** * @author Bernhard Schussek @@ -43,16 +42,6 @@ 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/src/Symfony/Component/Form/FormTypeExtensionInterface.php b/src/Symfony/Component/Form/FormTypeExtensionInterface.php index 220eb6f4b003c..deb87de79b57f 100644 --- a/src/Symfony/Component/Form/FormTypeExtensionInterface.php +++ b/src/Symfony/Component/Form/FormTypeExtensionInterface.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * @author Bernhard Schussek @@ -60,15 +60,12 @@ public function buildView(FormView $view, FormInterface $form, array $options); public function finishView(FormView $view, FormInterface $form, array $options); /** - * Overrides the default options from the extended type. + * Configures the options for this type. * - * @param OptionsResolverInterface $resolver The resolver for the options. + * @param OptionsResolver $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); + public function configureOptions(OptionsResolver $resolver); /** * Returns the name of the type being extended. diff --git a/src/Symfony/Component/Form/FormTypeInterface.php b/src/Symfony/Component/Form/FormTypeInterface.php index fc0bb046cb398..3f139aead767c 100644 --- a/src/Symfony/Component/Form/FormTypeInterface.php +++ b/src/Symfony/Component/Form/FormTypeInterface.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * @author Bernhard Schussek @@ -69,15 +69,11 @@ public function buildView(FormView $view, FormInterface $form, array $options); public function finishView(FormView $view, FormInterface $form, array $options); /** - * Sets the default options for this type. + * Configures the 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. + * @param OptionsResolver $resolver The resolver for the options. */ - public function setDefaultOptions(OptionsResolverInterface $resolver); + public function configureOptions(OptionsResolver $resolver); /** * Returns the name of the parent type. diff --git a/src/Symfony/Component/Form/ResolvedFormType.php b/src/Symfony/Component/Form/ResolvedFormType.php index e3c897a981653..ca832d90ceff4 100644 --- a/src/Symfony/Component/Form/ResolvedFormType.php +++ b/src/Symfony/Component/Form/ResolvedFormType.php @@ -192,7 +192,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) /** * Returns the configured options resolver used for this type. * - * @return \Symfony\Component\OptionsResolver\OptionsResolverInterface The options resolver. + * @return \Symfony\Component\OptionsResolver\OptionsResolver The options resolver. */ public function getOptionsResolver() { @@ -203,24 +203,10 @@ public function getOptionsResolver() $this->optionsResolver = new OptionsResolver(); } - $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); - } + $this->innerType->configureOptions($this->optionsResolver); 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); - } + $extension->configureOptions($this->optionsResolver); } } diff --git a/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php b/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php index e224cf31b0435..01f9b6e5fbcca 100644 --- a/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php @@ -99,7 +99,7 @@ public function testCreateBuilder() { $givenOptions = array('a' => 'a_custom', 'c' => 'c_custom'); $resolvedOptions = array('a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default'); - $optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface'); + $optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolver'); $this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType') ->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType)) @@ -127,7 +127,7 @@ public function testCreateBuilderWithDataClassOption() { $givenOptions = array('data_class' => 'Foo'); $resolvedOptions = array('data_class' => '\stdClass'); - $optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface'); + $optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolver'); $this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType') ->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType)) From 9b9158b4da5fd7d6a857e8abbd2a5b938cdf106f Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 20 Jan 2015 14:17:10 +0100 Subject: [PATCH 2/2] Remove the deprecated OptionsResolverInterface --- .../Form/ResolvedFormTypeInterface.php | 4 +- .../OptionsResolver/OptionsResolver.php | 2 +- .../OptionsResolverInterface.php | 214 ------------------ 3 files changed, 3 insertions(+), 217 deletions(-) delete mode 100644 src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php diff --git a/src/Symfony/Component/Form/ResolvedFormTypeInterface.php b/src/Symfony/Component/Form/ResolvedFormTypeInterface.php index e6a61c753b571..f8253e710c7e2 100644 --- a/src/Symfony/Component/Form/ResolvedFormTypeInterface.php +++ b/src/Symfony/Component/Form/ResolvedFormTypeInterface.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * A wrapper for a form type and its extensions. @@ -102,7 +102,7 @@ public function finishView(FormView $view, FormInterface $form, array $options); /** * Returns the configured options resolver used for this type. * - * @return OptionsResolverInterface The options resolver. + * @return OptionsResolver The options resolver. */ public function getOptionsResolver(); } diff --git a/src/Symfony/Component/OptionsResolver/OptionsResolver.php b/src/Symfony/Component/OptionsResolver/OptionsResolver.php index 96f28cc348ad8..69be826008d3a 100644 --- a/src/Symfony/Component/OptionsResolver/OptionsResolver.php +++ b/src/Symfony/Component/OptionsResolver/OptionsResolver.php @@ -24,7 +24,7 @@ * @author Bernhard Schussek * @author Tobias Schultze */ -class OptionsResolver implements Options, OptionsResolverInterface +class OptionsResolver implements Options { /** * The fully qualified name of the {@link Options} interface. diff --git a/src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php b/src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php deleted file mode 100644 index 7e983f22f958a..0000000000000 --- a/src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php +++ /dev/null @@ -1,214 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\OptionsResolver; - -use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; -use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; -use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException; - -/** - * @author Bernhard Schussek - * - * @deprecated since version 2.6, to be removed in Symfony 3.0. - * Use {@link OptionsResolver} instead. - * @deprecated since version 2.6, to be removed in 3.0. Use {@link OptionsResolver} instead. - */ -interface OptionsResolverInterface -{ - /** - * Sets default option values. - * - * The options can either be values of any types or closures that - * evaluate the option value lazily. These closures must have one - * of the following signatures: - * - * - * function (Options $options) - * function (Options $options, $value) - * - * - * The second parameter passed to the closure is the previously - * set default value, in case you are overwriting an existing - * default value. - * - * The closures should return the lazily created option value. - * - * @param array $defaultValues A list of option names as keys and default - * values or closures as values. - * - * @return OptionsResolverInterface The resolver instance. - */ - public function setDefaults(array $defaultValues); - - /** - * Replaces default option values. - * - * Old defaults are erased, which means that closures passed here cannot - * access the previous default value. This may be useful to improve - * performance if the previous default value is calculated by an expensive - * closure. - * - * @param array $defaultValues A list of option names as keys and default - * values or closures as values. - * - * @return OptionsResolverInterface The resolver instance. - */ - public function replaceDefaults(array $defaultValues); - - /** - * Sets optional options. - * - * This method declares valid option names without setting default values for them. - * If these options are not passed to {@link resolve()} and no default has been set - * for them, they will be missing in the final options array. This can be helpful - * if you want to determine whether an option has been set or not because otherwise - * {@link resolve()} would trigger an exception for unknown options. - * - * @param array $optionNames A list of option names. - * - * @return OptionsResolverInterface The resolver instance. - */ - public function setOptional(array $optionNames); - - /** - * Sets required options. - * - * If these options are not passed to {@link resolve()} and no default has been set for - * them, an exception will be thrown. - * - * @param array $optionNames A list of option names. - * - * @return OptionsResolverInterface The resolver instance. - */ - public function setRequired($optionNames); - - /** - * Sets allowed values for a list of options. - * - * @param array $allowedValues A list of option names as keys and arrays - * with values acceptable for that option as - * values. - * - * @return OptionsResolverInterface The resolver instance. - * - * @throws InvalidOptionsException If an option has not been defined - * (see {@link isKnown()}) for which - * an allowed value is set. - */ - public function setAllowedValues($allowedValues); - - /** - * Adds allowed values for a list of options. - * - * The values are merged with the allowed values defined previously. - * - * @param array $allowedValues A list of option names as keys and arrays - * with values acceptable for that option as - * values. - * - * @return OptionsResolverInterface The resolver instance. - * - * @throws InvalidOptionsException If an option has not been defined - * (see {@link isKnown()}) for which - * an allowed value is set. - */ - public function addAllowedValues($allowedValues); - - /** - * Sets allowed types for a list of options. - * - * @param array $allowedTypes A list of option names as keys and type - * names passed as string or array as values. - * - * @return OptionsResolverInterface The resolver instance. - * - * @throws InvalidOptionsException If an option has not been defined for - * which an allowed type is set. - */ - public function setAllowedTypes($allowedTypes); - - /** - * Adds allowed types for a list of options. - * - * The types are merged with the allowed types defined previously. - * - * @param array $allowedTypes A list of option names as keys and type - * names passed as string or array as values. - * - * @return OptionsResolverInterface The resolver instance. - * - * @throws InvalidOptionsException If an option has not been defined for - * which an allowed type is set. - */ - public function addAllowedTypes($allowedTypes); - - /** - * Sets normalizers that are applied on resolved options. - * - * The normalizers should be closures with the following signature: - * - * - * function (Options $options, $value) - * - * - * The second parameter passed to the closure is the value of - * the option. - * - * The closure should return the normalized value. - * - * @param array $normalizers An array of closures. - * - * @return OptionsResolverInterface The resolver instance. - */ - public function setNormalizers(array $normalizers); - - /** - * Returns whether an option is known. - * - * An option is known if it has been passed to either {@link setDefaults()}, - * {@link setRequired()} or {@link setOptional()} before. - * - * @param string $option The name of the option. - * - * @return bool Whether the option is known. - */ - public function isKnown($option); - - /** - * Returns whether an option is required. - * - * An option is required if it has been passed to {@link setRequired()}, - * but not to {@link setDefaults()}. That is, the option has been declared - * as required and no default value has been set. - * - * @param string $option The name of the option. - * - * @return bool Whether the option is required. - */ - public function isRequired($option); - - /** - * Returns the combination of the default and the passed options. - * - * @param array $options The custom option values. - * - * @return array A list of options and their values. - * - * @throws InvalidOptionsException If any of the passed options has not - * been defined or does not contain an - * allowed value. - * @throws MissingOptionsException If a required option is missing. - * @throws OptionDefinitionException If a cyclic dependency is detected - * between two lazy options. - */ - public function resolve(array $options = array()); -}