8000 [Form] Remove legacy code related to getExtendedType() method by yceruto · Pull Request #31703 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Remove legacy code related to getExtendedType() method #31703

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 1 commit into from
May 29, 2019
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
10000
13 changes: 3 additions & 10 deletions src/Symfony/Component/Form/AbstractExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,9 @@ private function initTypeExtensions()
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
}

if (method_exists($extension, 'getExtendedTypes')) {
$extendedTypes = [];

foreach ($extension::getExtendedTypes() as $extendedType) {
$extendedTypes[] = $extendedType;
}
} else {
@trigger_error(sprintf('Not implementing the static getExtendedTypes() method in %s when implementing the %s is deprecated since Symfony 4.2. The method will be added to the interface in 5.0.', \get_class($extension), FormTypeExtensionInterface::class), E_USER_DEPRECATED);

$extendedTypes = [$extension->getExtendedType()];
$extendedTypes = [];
foreach ($extension::getExtendedTypes() as $extendedType) {
$extendedTypes[] = $extendedType;
}

foreach ($extendedTypes as $extendedType) {
Expand Down
19 changes: 0 additions & 19 deletions src/Symfony/Component/Form/AbstractTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Form;

use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand Down Expand Up @@ -46,22 +45,4 @@ public function finishView(FormView $view, FormInterface $form, array $options)
public function configureOptions(OptionsResolver $resolver)
{
}

/**
* {@inheritdoc}
*
* @deprecated since Symfony 4.2, use getExtendedTypes() instead.
*/
public function getExtendedType()
{
if (!method_exists($this, 'getExtendedTypes')) {
throw new LogicException(sprintf('You need to implement the static getExtendedTypes() method when implementing the %s in %s.', FormTypeExtensionInterface::class, static::class));
}

@trigger_error(sprintf('The %s::getExtendedType() method is deprecated since Symfony 4.2 and will be removed in 5.0. Use getExtendedTypes() instead.', \get_class($this)), E_USER_DEPRECATED);

foreach (static::getExtendedTypes() as $extendedType) {
return $extendedType;
}
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CHANGELOG
-----

* removed the `ChoiceLoaderInterface` implementation in `CountryType`, `LanguageType`, `LocaleType` and `CurrencyType`
* removed `getExtendedType()` method of the `FormTypeExtensionInterface`
* added static `getExtendedTypes()` method to the `FormTypeExtensionInterface`

4.3.0
-----
Expand Down
9 changes: 1 addition & 8 deletions src/Symfony/Component/Form/DependencyInjection/FormPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Form\FormTypeExtensionInterface;

/**
* Adds all services with the tags "form.type", "form.type_extension" and
Expand Down Expand Up @@ -95,13 +94,9 @@ private function processFormTypeExtensions(ContainerBuilder $container)
$typeExtensionClass = $container->getParameterBag()->resolveValue($serviceDefinition->getClass());

if (isset($tag[0]['extended_type'])) {
if (!method_exists($typeExtensionClass, 'getExtendedTypes')) {
@trigger_error(sprintf('Not implementing the static getExtendedTypes() method in %s when implementing the %s is deprecated since Symfony 4.2. The method will be added to the interface in 5.0.', $typeExtensionClass, FormTypeExtensionInterface::class), E_USER_DEPRECATED);
}

$typeExtensions[$tag[0]['extended_type']][] = new Reference($serviceId);
$typeExtensionsClasses[] = $typeExtensionClass;
} elseif (method_exists($typeExtensionClass, 'getExtendedTypes')) {
} else {
$extendsTypes = false;

$typeExtensionsClasses[] = $typeExtensionClass;
Expand All @@ -113,8 +108,6 @@ private function processFormTypeExtensions(ContainerBuilder $container)
if (!$extendsTypes) {
throw new InvalidArgumentException(sprintf('The getExtendedTypes() method for service "%s" does not return any extended types.', $serviceId));
}
} else {
throw new InvalidArgumentException(sprintf('"%s" tagged services have to implement the static getExtendedTypes() method. Class "%s" for service "%s" does not implement it.', $this->formTypeExtensionTag, $typeExtensionClass, $serviceId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ public function getTypeExtensions($name)
foreach ($this->typeExtensionServices[$name] as $serviceId => $extension) {
$extensions[] = $extension;

if (method_exists($extension, 'getExtendedTypes')) {
$extendedTypes = [];

foreach ($extension::getExtendedTypes() as $extendedType) {
$extendedTypes[] = $extendedType;
}
} else {
$extendedTypes = [$extension->getExtendedType()];
$extendedTypes = [];
foreach ($extension::getExtendedTypes() as $extendedType) {
$extendedTypes[] = $extendedType;
}

// validate the result of getExtendedTypes()/getExtendedType() to ensure it is consistent with the service definition
// validate the result of getExtendedTypes() to ensure it is consistent with the service definition
if (!\in_array($name, $extendedTypes, true)) {
throw new InvalidArgumentException(sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".', $serviceId, $name, implode(', ', $extendedTypes)));
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Form/FormFactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ public function addTypes(array $types)
*/
public function addTypeExtension(FormTypeExtensionInterface $typeExtension)
{
if (method_exists($typeExtension, 'getExtendedTypes')) {
foreach ($typeExtension::getExtendedTypes() as $extendedType) {
$this->typeExtensions[$extendedType][] = $typeExtension;
}
} else {
$this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension;
foreach ($typeExtension::getExtendedTypes() as $extendedType) {
$this->typeExtensions[$extendedType][] = $typeExtension;
}

return $this;
Expand Down
10 changes: 3 additions & 7 deletions src/Symfony/Component/Form/FormTypeExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @method static iterable getExtendedTypes() Gets the extended types - not implementing it is deprecated since Symfony 4.2
*/
interface FormTypeExtensionInterface
{
Expand Down Expand Up @@ -58,11 +56,9 @@ public function finishView(FormView $view, FormInterface $form, array $options);
public function configureOptions(OptionsResolver $resolver);

/**
* Returns the name of the type being extended.
*
* @return string The name of the type being extended
* Gets the extended types.
*
* @deprecated since Symfony 4.2, use getExtendedTypes() instead.
* @return string[]
*/
public function getExtendedType();
public static function getExtendedTypes(): iterable;
}
8 changes: 0 additions & 8 deletions src/Symfony/Component/Form/PreloadedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ class PreloadedExtension implements FormExtensionInterface
*/
public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface $typeGuesser = null)
{
foreach ($typeExtensions as $extensions) {
foreach ($extensions as $typeExtension) {
if (!method_exists($typeExtension, 'getExtendedTypes')) {
@trigger_error(sprintf('Not implementing the static getExtendedTypes() method in %s when implementing the %s is deprecated since Symfony 4.2. The method will be added to the interface in 5.0.', \get_class($typeExtension), FormTypeExtensionInterface::class), E_USER_DEPRECATED);
}
}
}

$this->typeExtensions = $typeExtensions;
$this->typeGuesser = $typeGuesser;

Expand Down
53 changes: 0 additions & 53 deletions src/Symfony/Component/Form/Tests/AbstractTypeExtensionTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -219,87 +219,6 @@ public function addTaggedTypeExtensionsDataProvider()
];
}

/**
* @group legacy
* @dataProvider addLegacyTaggedTypeExtensionsDataProvider
*/
public function testAddLegacyTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions)
{
$container = $this->createContainerBuilder();

$container->setDefinition('form.extension', $this->createExtensionDefinition());

foreach ($extensions as $serviceId => $tag) {
$container->register($serviceId, 'stdClass')->addTag('form.type_extension', $tag);
}

$container->compile();

$extDefinition = $container->getDefinition('form.extension');
$this->assertEquals($expectedRegisteredExtensions, $extDefinition->getArgument(1));
}

/**
* @return array
*/
public function addLegacyTaggedTypeExtensionsDataProvider()
{
return [
[
[
'my.type_extension1' => ['extended_type' => 'type1'],
'my.type_extension2' => ['extended_type' => 'type1'],
'my.type_extension3' => ['extended_type' => 'type2'],
],
[
'type1' => new IteratorArgument([
new Reference('my.type_extension1'),
new Reference('my.type_extension2'),
]),
'type2' => new IteratorArgument([new Reference('my.type_extension3')]),
],
],
[
[
'my.type_extension1' => ['extended_type' => 'type1', 'priority' => 1],
'my.type_extension2' => ['extended_type' => 'type1', 'priority' => 2],
'my.type_extension3' => ['extended_type' => 'type1', 'priority' => -1],
'my.type_extension4' => ['extended_type' => 'type2', 'priority' => 2],
'my.type_extension5' => ['extended_type' => 'type2', 'priority' => 1],
'my.type_extension6' => ['extended_type' => 'type2', 'priority' => 1],
],
[
'type1' => new IteratorArgument([
new Reference('my.type_extension2'),
new Reference('my.type_extension1'),
new Reference('my.type_extension3'),
]),
'type2' => new IteratorArgument([
new Reference('my.type_extension4'),
new Reference('my.type_extension5'),
new Reference('my.type_extension6'),
]),
],
],
];
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage "form.type_extension" tagged services have to implement the static getExtendedTypes() method. Class "stdClass" for service "my.type_extension" does not implement it.
*/
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttributeNorImplementingGetExtendedTypes()
{
$container = $this->createContainerBuilder();

$container->setDefinition('form.extension', $this->createExtensionDefinition());
$container->register('my.type_extension', 'stdClass')
->setPublic(true)
->addTag('form.type_extension');

$container->compile();
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The getExtendedTypes() method for service "my.type_extension" does not return any extended types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ protected function setUp()
$this->extension = new DataCollectorTypeExtension($this->dataCollector);
}

/**
* @group legacy
*/
public function testGetExtendedType()
{
$this->assertEquals('Symfony\Component\Form\Extension\Core\Type\FormType', $this->extension->getExtendedType());
$this->assertEquals(['Symfony\Component\Form\Extension\Core\Type\FormType'], $this->extension::getExtendedTypes());
}

public function testBuildForm()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private function getMockFormType($typeClass = 'Symfony\Component\Form\AbstractTy
*/
private function getMockFormTypeExtension()
{
return $this->getMockBuilder('Symfony\Component\Form\AbstractTypeExtension')->setMethods(['getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm'])->getMock();
return $this->getMockBuilder('Symfony\Component\Form\AbstractTypeExtension')->setMethods(['getExtendedTypes', 'configureOptions', 'finishView', 'buildView', 'buildForm'])->getMock();
}

/**
Expand Down
0