Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e42adf7

Browse files
committed
Remove wrong deprecation triggers for forms in the DI extension
When a form type provides a BC layer with old form names (all core types do), the form registry will ask for type extensions registered on the legacy name for BC, and trigger a warning if it finds any. The DependencyInjectionExtension should not trigger warnings on its own when being asked for such extensions (especially when it has none registered). Core extensions are also registered using the proper extended type rather than legacy names.
1 parent cecc2ee commit e42adf7

File tree

6 files changed

+10
-80
lines changed

6 files changed

+10
-80
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FormPass.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,14 @@ public function process(ContainerBuilder $container)
3333
// Builds an array with service IDs as keys and tag aliases as values
3434
$types = array();
3535

36-
// Remember which names will not be supported in Symfony 3.0 to trigger
37-
// deprecation errors
38-
$legacyNames = array();
39-
4036
foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
4137
// The following if-else block is deprecated and will be removed
4238
// in Symfony 3.0
43-
// Deprecation errors are triggered in DependencyInjectionExtension
39+
// Deprecation errors are triggered in the form registry
4440
if (isset($tag[0]['alias'])) {
4541
$types[$tag[0]['alias']] = $serviceId;
46-
$legacyNames[$tag[0]['alias']] = true;
4742
} else {
4843
$types[$serviceId] = $serviceId;
49-
$legacyNames[$serviceId] = true;
5044
}
5145

5246
// Support type access by FQCN
@@ -55,7 +49,6 @@ public function process(ContainerBuilder $container)
5549
}
5650

5751
$definition->replaceArgument(1, $types);
58-
$definition->replaceArgument(4, $legacyNames);
5952

6053
$typeExtensions = array();
6154

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
<argument type="collection" />
4747
<!-- All services with tag "form.type_guesser" are inserted here by FormPass -->
4848
<argument type="collection" />
49-
<!-- The deprecated type names are inserted here by FormPass -->
50-
<argument type="collection" />
5149
</service>
5250

5351
<!-- ValidatorTypeGuesser -->
@@ -157,7 +155,7 @@
157155
<!-- FormTypeHttpFoundationExtension -->
158156
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
159157
<argument type="service" id="form.type_extension.form.request_handler" />
160-
<tag name="form.type_extension" alias="form" />
158+
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
161159
</service>
162160

163161
<!-- HttpFoundationRequestHandler -->
@@ -171,14 +169,14 @@
171169

172170
<!-- FormTypeValidatorExtension -->
173171
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
174-
<tag name="form.type_extension" alias="form" />
172+
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
175173
<argument type="service" id="validator" />
176174
</service>
177175
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
178-
<tag name="form.type_extension" alias="repeated" />
176+
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\RepeatedType" />
179177
</service>
180178
<service id="form.type_extension.submit.validator" class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
181-
<tag name="form.type_extension" alias="submit" />
179+
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\SubmitType" />
182180
</service>
183181
</services>
184182
</container>

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</service>
1111

1212
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
13-
<tag name="form.type_extension" alias="form" />
13+
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
1414
<argument type="service" id="security.csrf.token_manager" />
1515
<argument>%form.type_extension.csrf.enabled%</argument>
1616
<argument>%form.type_extension.csrf.field_name%</argument>

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<!-- DataCollectorTypeExtension -->
2323
<service id="form.type_extension.form.data_collector" class="%form.type_extension.form.data_collector.class%">
24-
<tag name="form.type_extension" alias="form" />
24+
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
2525
<argument type="service" id="data_collector.form" />
2626
</service>
2727

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/FormPassTest.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function testAddTaggedTypes()
4343
array(),
4444
array(),
4545
array(),
46-
array(),
4746
));
4847

4948
$definition1 = new Definition(__CLASS__.'_Type1');
@@ -80,7 +79,6 @@ public function testUseCustomAliasIfSet()
8079
array(),
8180
array(),
8281
array(),
83-
array(),
8482
));
8583

8684
$definition1 = new Definition(__CLASS__.'_Type1');
@@ -104,41 +102,6 @@ public function testUseCustomAliasIfSet()
104102
), $extDefinition->getArgument(1));
105103
}
106104

107-
public function testPassLegacyNames()
108-
{
109-
$container = new ContainerBuilder();
110-
$container->addCompilerPass(new FormPass());
111-
112-
$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
113-
$extDefinition->setArguments(array(
114-
new Reference('service_container'),
115-
array(),
116-
array(),
117-
array(),
118-
array(),
119-
));
120-
121-
$definition1 = new Definition(__CLASS__.'_Type1');
122-
$definition1->addTag('form.type');
123-
$definition2 = new Definition(__CLASS__.'_Type2');
124-
$definition2->addTag('form.type', array('alias' => 'mytype2'));
125-
126-
$container->setDefinition('form.extension', $extDefinition);
127-
$container->setDefinition('my.type1', $definition1);
128-
$container->setDefinition('my.type2', $definition2);
129-
130-
$container->compile();
131-
132-
$extDefinition = $container->getDefinition('form.extension');
133-
134-
$this->assertEquals(array(
135-
// Service ID if no alias is set
136-
'my.type1' => true,
137-
// Alias if set
138-
'mytype2' => true,
139-
), $extDefinition->getArgument(4));
140-
}
141-
142105
public function testAddTaggedTypeExtensions()
143106
{
144107
$container = new ContainerBuilder();
@@ -150,7 +113,6 @@ public function testAddTaggedTypeExtensions()
150113
array(),
151114
array(),
152115
array(),
153-
array(),
154116
));
155117

156118
$definition1 = new Definition('stdClass');
@@ -191,7 +153,6 @@ public function testAddTaggedGuessers()
191153
array(),
192154
array(),
193155
array(),
194-
array(),
195156
));
196157

197158
$definition1 = new Definition('stdClass');

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

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@ class DependencyInjectionExtension implements FormExtensionInterface
2222
private $typeServiceIds;
2323
private $typeExtensionServiceIds;
2424
private $guesserServiceIds;
25-
private $legacyNames;
2625
private $guesser;
2726
private $guesserLoaded = false;
2827

2928
public function __construct(ContainerInterface $container,
3029
array $typeServiceIds, array $typeExtensionServiceIds,
31-
array $guesserServiceIds, array $legacyNames = array())
30+
array $guesserServiceIds)
3231
{
3332
$this->container = $container;
3433
$this->typeServiceIds = $typeServiceIds;
3534
$this->typeExtensionServiceIds = $typeExtensionServiceIds;
3635
$this->guesserServiceIds = $guesserServiceIds;
37-
$this->legacyNames = $legacyNames;
3836
}
3937

4038
public function getType($name)
@@ -43,14 +41,10 @@ public function getType($name)
4341
throw new InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name));
4442
}
4543

46-
if (isset($this->legacyNames[$name])) {
47-
@trigger_error('Accessing form types by type name/service ID is deprecated since version 2.8 and will not be supported in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
48-
}
49-
5044
$type = $this->container->get($this->typeServiceIds[$name]);
5145

5246
// BC: validate result of getName() for legacy names (non-FQCN)
53-
if (isset($this->legacyNames[$name]) && $type->getName() !== $name) {
47+
if ($name !== get_class($type) && $type->getName() !== $name) {
5448
throw new InvalidArgumentException(
5549
sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"',
5650
$this->typeServiceIds[$name],
@@ -65,23 +59,11 @@ public function getType($name)
6559

6660
public function hasType($name)
6761
{
68-
if (isset($this->typeServiceIds[$name])) {
69-
if (isset($this->legacyNames[$name])) {
70-
@trigger_error('Accessing form types by type name/service ID is deprecated since version 2.8 and will not be supported in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
71-
}
72-
73-
return true;
74-
}
75-
76-
return false;
62+
return isset($this->typeServiceIds[$name]);
7763
}
7864

7965
public function getTypeExtensions($name)
8066
{
81-
if (isset($this->legacyNames[$name])) {
82-
@trigger_error('Accessing form types by type name/service ID is deprecated since version 2.8 and will not be supported in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
83-
}
84-
8567
$extensions = array();
8668

8769
if (isset($this->typeExtensionServiceIds[$name])) {
@@ -95,10 +77,6 @@ public function getTypeExtensions($name)
9577

9678
public function hasTypeExtensions($name)
9779
{
98-
if (isset($this->legacyNames[$name])) {
99-
@trigger_error('Accessing form types by type name/service ID is deprecated since version 2.8 and will not be supported in 3.0. Use the fully-qualified type class name instead.', E_USER_DEPRECATED);
100-
}
101-
10280
return isset($this->typeExtensionServiceIds[$name]);
10381
}
10482

0 commit comments

Comments
 (0)