Skip to content

Remove wrong deprecation triggers for forms in the DI extension #15740

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
Sep 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@ public function process(ContainerBuilder $container)
// Builds an array with service IDs as keys and tag aliases as values
$types = array();

// Remember which names will not be supported in Symfony 3.0 to trigger
// deprecation errors
$legacyNames = array();

foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
// The following if-else block is deprecated and will be removed
// in Symfony 3.0
// Deprecation errors are triggered in DependencyInjectionExtension
// Deprecation errors are triggered in the form registry
if (isset($tag[0]['alias'])) {
$types[$tag[0]['alias']] = $serviceId;
$legacyNames[$tag[0]['alias']] = true;
} else {
$types[$serviceId] = $serviceId;
$legacyNames[$serviceId] = true;
}

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

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

$typeExtensions = array();

Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
<argument type="collection" />
<!-- All services with tag "form.type_guesser" are inserted here by FormPass -->
<argument type="collection" />
<!-- The deprecated type names are inserted here by FormPass -->
<argument type="collection" />
</service>

<!-- ValidatorTypeGuesser -->
Expand Down Expand Up @@ -157,7 +155,7 @@
<!-- FormTypeHttpFoundationExtension -->
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
<argument type="service" id="form.type_extension.form.request_handler" />
<tag name="form.type_extension" alias="form" />
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
</service>

<!-- HttpFoundationRequestHandler -->
Expand All @@ -171,14 +169,14 @@

<!-- FormTypeValidatorExtension -->
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
<tag name="form.type_extension" alias="form" />
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
<argument type="service" id="validator" />
</service>
<service id="form.type_extension.repeated.validator" class="Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension">
<tag name="form.type_extension" alias="repeated" />
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\RepeatedType" />
</service>
<service id="form.type_extension.submit.validator" class="Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension">
<tag name="form.type_extension" alias="submit" />
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\SubmitType" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</service>

<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">
<tag name="form.type_extension" alias="form" />
<tag name="form.type_extension" alias="Symfony\Component\Form\Extension\Core\Type\FormType" />
<argument type="service" id="security.csrf.token_manager" />
<argument>%form.type_extension.csrf.enabled%</argument>
<argument>%form.type_extension.csrf.field_name%</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function testAddTaggedTypes()
array(),
array(),
array(),
array(),
));

$definition1 = new Definition(__CLASS__.'_Type1');
Expand Down Expand Up @@ -80,7 +79,6 @@ public function testUseCustomAliasIfSet()
array(),
array(),
array(),
array(),
));

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

public function testPassLegacyNames()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new FormPass());

$extDefinition = new Definition('Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension');
$extDefinition->setArguments(array(
new Reference('service_container'),
array(),
array(),
array(),
array(),
));

$definition1 = new Definition(__CLASS__.'_Type1');
$definition1->addTag('form.type');
$definition2 = new Definition(__CLASS__.'_Type2');
$definition2->addTag('form.type', array('alias' => 'mytype2'));

$container->setDefinition('form.extension', $extDefinition);
$container->setDefinition('my.type1', $definition1);
$container->setDefinition('my.type2', $definition2);

$container->compile();

$extDefinition = $container->getDefinition('form.extension');

$this->assertEquals(array(
// Service ID if no alias is set
'my.type1' => true,
// Alias if set
'mytype2' => true,
), $extDefinition->getArgument(4));
}

public function testAddTaggedTypeExtensions()
{
$container = new ContainerBuilder();
Expand All @@ -150,7 +113,6 @@ public function testAddTaggedTypeExtensions()
array(),
array(),
array(),
array(),
));

$definition1 = new Definition('stdClass');
Expand Down Expand Up @@ -191,7 +153,6 @@ public function testAddTaggedGuessers()
array(),
array(),
array(),
array(),
));

$definition1 = new Definition('stdClass');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ class DependencyInjectionExtension implements FormExtensionInterface
private $typeServiceIds;
private $typeExtensionServiceIds;
private $guesserServiceIds;
private $legacyNames;
private $guesser;
private $guesserLoaded = false;

public function __construct(ContainerInterface $container,
array $typeServiceIds, array $typeExtensionServiceIds,
array $guesserServiceIds, array $legacyNames = array())
array $guesserServiceIds)
{
$this->container = $container;
$this->typeServiceIds = $typeServiceIds;
$this->typeExtensionServiceIds = $typeExtensionServiceIds;
$this->guesserServiceIds = $guesserServiceIds;
$this->legacyNames = $legacyNames;
}

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

if (isset($this->legacyNames[$name])) {
@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);
}

$type = $this->container->get($this->typeServiceIds[$name]);

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

public function hasType($name)
{
if (isset($this->typeServiceIds[$name])) {
if (isset($this->legacyNames[$name])) {
@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);
}

return true;
}

return false;
return isset($this->typeServiceIds[$name]);
}

public function getTypeExtensions($name)
{
if (isset($this->legacyNames[$name])) {
@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);
}

$extensions = array();

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

public function hasTypeExtensions($name)
{
if (isset($this->legacyNames[$name])) {
@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);
}

return isset($this->typeExtensionServiceIds[$name]);
}

Expand Down