Skip to content

[Form] Remove deprecated setDefaultOptions and OptionsResolverInterface #13407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/Symfony/Component/Form/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -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)
{
}
Expand Down
11 changes: 0 additions & 11 deletions src/Symfony/Component/Form/AbstractTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -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)
{
}
Expand Down
11 changes: 4 additions & 7 deletions src/Symfony/Component/Form/FormTypeExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Form/FormTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 3 additions & 17 deletions src/Symfony/Component/Form/ResolvedFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/ResolvedFormTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/OptionsResolver/OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Tobias Schultze <http://tobion.de>
*/
class OptionsResolver implements Options, OptionsResolverInterface
class OptionsResolver implements Options
{
/**
* The fully qualified name of the {@link Options} interface.
Expand Down
Loading