8000 Remove legacy code related to getExtendedType() method · symfony/symfony@3c3bbf0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c3bbf0

Browse files
committed
Remove legacy code related to getExtendedType() method
1 parent 2bf74ce commit 3c3bbf0

12 files changed

+17
-206
lines changed

src/Symfony/Component/Form/AbstractExtension.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,9 @@ private function initTypeExtensions()
175175
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
176176
}
177177

178-
if (method_exists($extension, 'getExtendedTypes')) {
179-
$extendedTypes = [];
180-
181-
foreach ($extension::getExtendedTypes() as $extendedType) {
182-
$extendedTypes[] = $extendedType;
183-
}
184-
} else {
185-
@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);
186-
187-
$extendedTypes = [$extension->getExtendedType()];
178+
$extendedTypes = [];
179+
foreach ($extension::getExtendedTypes() as $extendedType) {
180+
$extendedTypes[] = $extendedType;
188181
}
189182

190183
foreach ($extendedTypes as $extendedType) {

src/Symfony/Component/Form/AbstractTypeExtension.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Exception\LogicException;
1514
use Symfony\Component\OptionsResolver\OptionsResolver;
1615

1716
/**
@@ -46,22 +45,4 @@ public function finishView(FormView $view, FormInterface $form, array $options)
4645
public function configureOptions(OptionsResolver $resolver)
4746
{
4847
}
49-
50-
/**
51-
* {@inheritdoc}
52-
*
53-
* @deprecated since Symfony 4.2, use getExtendedTypes() instead.
54-
*/
55-
public function getExtendedType()
56-
{
57-
if (!method_exists($this, 'getExtendedTypes')) {
58-
throw new LogicException(sprintf('You need to implement the static getExtendedTypes() method when implementing the %s in %s.', FormTypeExtensionInterface::class, static::class));
59-
}
60-
61-
@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);
62-
63-
foreach (static::getExtendedTypes() as $extendedType) {
64-
return $extendedType;
65-
}
66-
}
6748
}

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55
-----
66

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

911
4.3.0
1012
-----

src/Symfony/Component/Form/DependencyInjection/FormPass.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2020
use Symfony\Component\DependencyInjection\Reference;
21-
use Symfony\Component\Form\FormTypeExtensionInterface;
2221

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

9796
if (isset($tag[0]['extended_type'])) {
98-
if (!method_exists($typeExtensionClass, 'getExtendedTypes')) {
99-
@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);
100-
}
101-
10297
$typeExtensions[$tag[0]['extended_type']][] = new Reference($serviceId);
10398
$typeExtensionsClasses[] = $typeExtensionClass;
104-
} elseif (method_exists($typeExtensionClass, 'getExtendedTypes')) {
99+
} else {
105100
$extendsTypes = false;
106101

107102
$typeExtensionsClasses[] = $typeExtensionClass;
@@ -113,8 +108,6 @@ private function processFormTypeExtensions(ContainerBuilder $container)
113108
if (!$extendsTypes) {
114109
throw new InvalidArgumentException(sprintf('The getExtendedTypes() method for service "%s" does not return any extended types.', $serviceId));
115110
}
116-
} else {
117-
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));
118111
}
119112
}
120113

src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,12 @@ public function getTypeExtensions($name)
5858
foreach ($this->typeExtensionServices[$name] as $serviceId => $extension) {
5959
$extensions[] = $extension;
6060

61-
if (method_exists($extension, 'getExtendedTypes')) {
62-
$extendedTypes = [];
63-
64-
foreach ($extension::getExtendedTypes() as $extendedType) {
65-
$extendedTypes[] = $extendedType;
66-
}
67-
} else {
68-
$extendedTypes = [$extension->getExtendedType()];
61+
$extendedTypes = [];
62+
foreach ($extension::getExtendedTypes() as $extendedType) {
63+
$extendedTypes[] = $extendedType;
6964
}
7065

71-
// validate the result of getExtendedTypes()/getExtendedType() to ensure it is consistent with the service definition
66+
// validate the result of getExtendedTypes() to ensure it is consistent with the service definition
7267
if (!\in_array($name, $extendedTypes, true)) {
7368
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)));
7469
}

src/Symfony/Component/Form/FormFactoryBuilder.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,8 @@ public function addTypes(array $types)
112112
*/
113113
public function addTypeExtension(FormTypeExtensionInterface $typeExtension)
114114
{
115-
if (method_exists($typeExtension, 'getExtendedTypes')) {
116-
foreach ($typeExtension::getExtendedTypes() as $extendedType) {
117-
$this->typeExtensions[$extendedType][] = $typeExtension;
118-
}
119-
} else {
120-
$this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension;
115+
foreach ($typeExtension::getExtendedTypes() as $extendedType) {
116+
$this->typeExtensions[$extendedType][] = $typeExtension;
121117
}
122118

123119
return $this;

src/Symfony/Component/Form/FormTypeExtensionInterface.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

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

6058
/**
61-
* Returns the name of the type being extended.
62-
*
63-
* @return string The name of the type being extended
59+
* Gets the extended types.
6460
*
65-
* @deprecated since Symfony 4.2, use getExtendedTypes() instead.
61+
* @return string[] Gets the extended types
6662
*/
67-
public function getExtendedType();
63+
public static function getExtendedTypes(): iterable;
6864
}

src/Symfony/Component/Form/PreloadedExtension.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ class PreloadedExtension implements FormExtensionInterface
3333
*/
3434
public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface $typeGuesser = null)
3535
{
36-
foreach ($typeExtensions as $extensions) {
37-
foreach ($extensions as $typeExtension) {
38-
if (!method_exists($typeExtension, 'getExtendedTypes')) {
39-
@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);
40-
}
41-
}
42-
}
43-
4436
$this->typeExtensions = $typeExtensions;
4537
$this->typeGuesser = $typeGuesser;
4638

src/Symfony/Component/Form/Tests/AbstractTypeExtensionTest.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/Symfony/Component/Form/Tests/DependencyInjection/FormPassTest.php

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -219,87 +219,6 @@ public function addTaggedTypeExtensionsDataProvider()
219219
];
220220
}
221221

222-
/**
223-
* @group legacy
224-
* @dataProvider addLegacyTaggedTypeExtensionsDataProvider
225-
*/
226-
public function testAddLegacyTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions)
227-
{
228-
$container = $this->createContainerBuilder();
229-
230-
$container->setDefinition('form.extension', $this->createExtensionDefinition());
231-
232-
foreach ($extensions as $serviceId => $tag) {
233-
$container->register($serviceId, 'stdClass')->addTag('form.type_extension', $tag);
234-
}
235-
236-
$container->compile();
237-
238-
$extDefinition = $container->getDefinition('form.extension');
239-
$this->assertEquals($expectedRegisteredExtensions, $extDefinition->getArgument(1));
240-
}
241-
242-
/**
243-
* @return array
244-
*/
245-
public function addLegacyTaggedTypeExtensionsDataProvider()
246-
{
247-
return [
248-
[
249-
[
250-
'my.type_extension1' => ['extended_type' => 'type1'],
251-
'my.type_extension2' => ['extended_type' => 'type1'],
252-
'my.type_extension3' => ['extended_type' => 'type2'],
253-
],
254-
[
255-
'type1' => new IteratorArgument([
256-
new Reference('my.type_extension1'),
257-
new Reference('my.type_extension2'),
258-
]),
259-
'type2' => new IteratorArgument([new Reference('my.type_extension3')]),
260-
],
261-
],
262-
[
263-
[
264-
'my.type_extension1' => ['extended_type' => 'type1', 'priority' => 1],
265-
'my.type_extension2' => ['extended_type' => 'type1', 'priority' => 2],
266-
'my.type_extension3' => ['extended_type' => 'type1', 'priority' => -1],
267-
'my.type_extension4' => ['extended_type' => 'type2', 'priority' => 2],
268-
'my.type_extension5' => ['extended_type' => 'type2', 'priority' => 1],
269-
'my.type_extension6' => ['extended_type' => 'type2', 'priority' => 1],
270-
],
271-
[
272-
'type1' => new IteratorArgument([
273-
new Reference('my.type_extension2'),
274-
new Reference('my.type_extension1'),
275-
new Reference('my.type_extension3'),
276-
]),
277-
'type2' => new IteratorArgument([
278-
new Reference('my.type_extension4'),
279-
new Reference('my.type_extension5'),
280-
new Reference('my.type_extension6'),
281-
]),
282-
],
283-
],
284-
];
285-
}
286-
287-
/**
288-
* @expectedException \InvalidArgumentException
289-
* @expectedExceptionMessage "form.type_extension" tagged services have to implement the static getExtendedTypes() method. Class "stdClass" for service "my.type_extension" does not implement it.
290-
*/
291-
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttributeNorImplementingGetExtendedTypes()
292-
{
293-
$container = $this->createContainerBuilder();
294-
295-
$container->setDefinition('form.extension', $this->createExtensionDefinition());
296-
$container->register('my.type_extension', 'stdClass')
297-
->setPublic(true)
298-
->addTag('form.type_extension');
299-
300-
$container->compile();
301-
}
302-
303222
/**
304223
* @expectedException \InvalidArgumentException
305224
* @expectedExceptionMessage The getExtendedTypes() method for service "my.type_extension" does not return any extended types.

src/Symfony/Component/Form/Tests/Extension/DataCollector/Type/DataCollectorTypeExtensionTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ protected function setUp()
3232
$this->extension = new DataCollectorTypeExtension($this->dataCollector);
3333
}
3434

35-
/**
36-
* @group legacy
37-
*/
3835
public function testGetExtendedType()
3936
{
40-
$this->assertEquals('Symfony\Component\Form\Extension\Core\Type\FormType', $this->extension->getExtendedType());
37+
$this->assertEquals(['Symfony\Component\Form\Extension\Core\Type\FormType'], $this->extension::getExtendedTypes());
4138
}
4239

4340
public function testBuildForm()

src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private function getMockFormType($typeClass = 'Symfony\Component\Form\AbstractTy
371371
*/
372372
private function getMockFormTypeExtension()
373373
{
374-
return $this->getMockBuilder('Symfony\Component\Form\AbstractTypeExtension')->setMethods(['getExtendedType', 'configureOptions', 'finishView', 'buildView', 'buildForm'])->getMock();
374+
return $this->getMockBuilder('Symfony\Component\Form\AbstractTypeExtension')->setMethods(['getExtendedTypes', 'configureOptions', 'finishView', 'buildView', 'buildForm'])->getMock();
375375
}
376376

377377
/**

0 commit comments

Comments
 (0)
0