8000 bug #31201 [Form] resolve class name parameters (xabbuh) · symfony/symfony@571647f · GitHub
[go: up one dir, main page]

Skip to content

Commit 571647f

Browse files
committed
bug #31201 [Form] resolve class name parameters (xabbuh)
This PR was merged into the 4.2 branch. Discussion ---------- [Form] resolve class name parameters | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31052 | License | MIT | Doc PR | Commits ------- 5235be4 resolve class name parameters
2 parents 0773baf + 5235be4 commit 571647f

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,20 @@ private function processFormTypeExtensions(ContainerBuilder $container)
9292
$serviceDefinition = $container->getDefinition($serviceId);
9393

9494
$tag = $serviceDefinition->getTag($this->formTypeExtensionTag);
95+
$typeExtensionClass = $container->getParameterBag()->resolveValue($serviceDefinition->getClass());
96+
9597
if (isset($tag[0]['extended_type'])) {
96-
if (!method_exists($serviceDefinition->getClass(), 'getExtendedTypes')) {
97-
@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.', $serviceDefinition->getClass(), FormTypeExtensionInterface::class), E_USER_DEPRECATED);
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);
98100
}
99101

100102
$typeExtensions[$tag[0]['extended_type']][] = new Reference($serviceId);
101-
$typeExtensionsClasses[] = $serviceDefinition->getClass();
102-
} elseif (method_exists($serviceDefinition->getClass(), 'getExtendedTypes')) {
103+
$typeExtensionsClasses[] = $typeExtensionClass;
104+
} elseif (method_exists($typeExtensionClass, 'getExtendedTypes')) {
103105
$extendsTypes = false;
104106

105-
$typeExtensionsClasses[] = $serviceDefinition->getClass();
106-
foreach ($serviceDefinition->getClass()::getExtendedTypes() as $extendedType) {
107+
$typeExtensionsClasses[] = $typeExtensionClass;
108+
foreach ($typeExtensionClass::getExtendedTypes() as $extendedType) {
107109
$typeExtensions[$extendedType][] = new Reference($serviceId);
108110
$extendsTypes = true;
109111
}
@@ -112,7 +114,7 @@ private function processFormTypeExtensions(ContainerBuilder $container)
112114
throw new InvalidArgumentException(sprintf('The getExtendedTypes() method for service "%s" does not return any extended types.', $serviceId));
113115
}
114116
} else {
115-
throw new InvalidArgumentException(sprintf('"%s" tagged services have to implement the static getExtendedTypes() method. The class for service "%s" does not implement it.', $this->formTypeExtensionTag, $serviceId));
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));
116118
}
117119
}
118120

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ public function testAddTaggedTypesToDebugCommand()
9797
/**
9898
* @dataProvider addTaggedTypeExtensionsDataProvider
9999
*/
100-
public function testAddTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions)
100+
public function testAddTaggedTypeExtensions(array $extensions, array $expectedRegisteredExtensions, array $parameters = [])
101101
{
102102
$container = $this->createContainerBuilder();
103103

104+
foreach ($parameters as $name => $value) {
105+
$container->setParameter($name, $value);
106+
}
107+
104108
$container->setDefinition('form.extension', $this->createExtensionDefinition());
105109

106110
foreach ($extensions as $serviceId => $config) {
@@ -191,6 +195,27 @@ public function addTaggedTypeExtensionsDataProvider()
191195
]),
192196
],
193197
],
198+
[
199+
[
200+
'my.type_extension1' => [
201+
'class' => '%type1_extension_class%',
202+
'tag' => ['extended_type' => 'type1'],
203+
],
204+
'my.type_extension2' => [
205+
'class' => '%type1_extension_class%',
206+
'tag' => [],
207+
],
208+
],
209+
[
210+
'type1' => new IteratorArgument([
211+
new Reference('my.type_extension1'),
212+
new Reference('my.type_extension2'),
213+
]),
214+
],
215+
[
216+
'type1_extension_class' => Type1TypeExtension::class,
217+
],
218+
],
194219
];
195220
}
196221

@@ -261,7 +286,7 @@ public function addLegacyTaggedTypeExtensionsDataProvider()
261286

262287
/**
263288
* @expectedException \InvalidArgumentException
264-
* @expectedExceptionMessage "form.type_extension" tagged services have to implement the static getExtendedTypes() method. The class for service "my.type_extension" does not implement it.
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.
265290
*/
266291
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttributeNorImplementingGetExtendedTypes()
267292
{

0 commit comments

Comments
 (0)
0