Skip to content

[DependencyInjection] Remove deprecated code #41932

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
Jul 3, 2021
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 @@ -55,11 +55,12 @@ public function testProcess()
'Test\private_used_shared_service' => new ServiceClosureArgument(new Reference('Test\private_used_shared_service')),
'Test\private_used_non_shared_service' => new ServiceClosureArgument(new Reference('Test\private_used_non_shared_service')),
'Test\soon_private_service' => new ServiceClosureArgument(new Reference('.container.private.Test\soon_private_service')),
'Psr\Container\ContainerInterface' => new ServiceClosureArgument(new Reference('service_container')),
'Symfony\Component\DependencyInjection\ContainerInterface' => new ServiceClosureArgument(new Reference('service_container')),
];
$this->assertEquals($expected, $container->getDefinition('test.private_services_locator')->getArgument(0));
$this->assertSame($container, $container->get('test.private_services_locator')->get('Psr\Container\ContainerInterface'));
$actual = $container->getDefinition('test.private_services_locator')->getArgument(0);
// When testing against DependencyInjection 5.4, those deprecated services will still appear.
unset($actual['Psr\Container\ContainerInterface'], $actual['Symfony\Component\DependencyInjection\ContainerInterface']);

$this->assertEquals($expected, $actual);
$this->assertFalse($container->getDefinition('Test\private_used_non_shared_service')->isShared());
}
}
48 changes: 2 additions & 46 deletions src/Symfony/Component/DependencyInjection/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ public function setPublic(bool $boolean)
return $this;
}

/**
* Sets if this Alias is private.
*
* @return $this
*
* @deprecated since Symfony 5.2, use setPublic() instead
*/
public function setPrivate(bool $boolean)
{
trigger_deprecation('symfony/dependency-injection', '5.2', 'The "%s()" method is deprecated, use "setPublic()" instead.', __METHOD__);

return $this->setPublic(!$boolean);
}

/**
* Whether this alias is private.
*
Expand All @@ -85,28 +71,8 @@ public function isPrivate()
*
* @throws InvalidArgumentException when the message template is invalid
*/
public function setDeprecated(/* string $package, string $version, string $message */)
public function setDeprecated(string $package, string $version, string $message)
{
$args = \func_get_args();

if (\func_num_args() < 3) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);

$status = $args[0] ?? true;

if (!$status) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Passing a null message to un-deprecate a node is deprecated.');
}

$message = (string) ($args[1] ?? null);
$package = $version = '';
} else {
$status = true;
$package = (string) $args[0];
$version = (string) $args[1];
$message = (string) $args[2];
}

if ('' !== $message) {
if (preg_match('#[\r\n]|\*/#', $message)) {
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
Expand All @@ -117,7 +83,7 @@ public function setDeprecated(/* string $package, string $version, string $messa
}
}

$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE] : [];
$this->deprecation = ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE];

return $this;
}
Expand All @@ -127,16 +93,6 @@ public function isDeprecated(): bool
return (bool) $this->deprecation;
}

/**
* @deprecated since Symfony 5.1, use "getDeprecation()" instead.
*/
public function getDeprecationMessage(string $id): string
{
trigger_deprecation('symfony/dependency-injection', '5.1', 'The "%s()" method is deprecated, use "getDeprecation()" instead.', __METHOD__);

return $this->getDeprecation($id)['message'];
}

/**
* @param string $id Service id relying on this definition
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
=========

6.0
---

* Remove `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead
* Remove `inline()` in favor of `inline_service()` and `ref()` in favor of `service()` when using the PHP-DSL
* Remove `Definition::getDeprecationMessage()`, use `Definition::getDeprecation()` instead
* Remove `Alias::getDeprecationMessage()`, use `Alias::getDeprecation()` instead
* Remove the `Psr\Container\ContainerInterface` and `Symfony\Component\DependencyInjection\ContainerInterface` aliases of the `service_container` service

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,9 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
if (isset($changes['lazy'])) {
$def->setLazy($definition->isLazy());
}
if (isset($changes['deprecated'])) {
if ($definition->isDeprecated()) {
$deprecation = $definition->getDeprecation('%service_id%');
$def->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message']);
} else {
$def->setDeprecated(false);
}
if (isset($changes['deprecated']) && $definition->isDeprecated()) {
$deprecation = $definition->getDeprecation('%service_id%');
$def->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message']);
}
if (isset($changes['autowired'])) {
$def->setAutowired($definition->isAutowired());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\DependencyInjection;

use Composer\InstalledVersions;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Symfony\Component\Config\Resource\ClassExistenceResource;
use Symfony\Component\Config\Resource\ComposerResource;
use Symfony\Component\Config\Resource\DirectoryResource;
Expand Down Expand Up @@ -141,8 +140,6 @@ public function __construct(ParameterBagInterface $parameterBag = null)

$this->trackResources = interface_exists(ResourceInterface::class);
$this->setDefinition('service_container', (new Definition(ContainerInterface::class))->setSynthetic(true)->setPublic(true));
$this->setAlias(PsrContainerInterface::class, new Alias('service_container', false))->setDeprecated('symfony/dependency-injection', '5.1', $deprecationMessage = 'The "%alias_id%" autowiring alias is deprecated. Define it explicitly in your app if you want to keep using it.');
$this->setAlias(ContainerInterface::class, new Alias('service_container', false))->setDeprecated('symfony/dependency-injection', '5.1', $deprecationMessage);
}

/**
Expand Down
54 changes: 2 additions & 52 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,6 @@ public function isPublic()
return $this->public;
}

/**
* Sets if this service is private.
*
* @return $this
*
* @deprecated since Symfony 5.2, use setPublic() instead
*/
public function setPrivate(bool $boolean)
{
trigger_deprecation('symfony/dependency-injection', '5.2', 'The "%s()" method is deprecated, use "setPublic()" instead.', __METHOD__);

return $this->setPublic(!$boolean);
}

/**
* Whether this service is private.
*
Expand Down Expand Up @@ -698,28 +684,8 @@ public function isAbstract()
*
* @throws InvalidArgumentException when the message template is invalid
*/
public function setDeprecated(/* string $package, string $version, string $message */)
public function setDeprecated(string $package, string $version, string $message)
{
$args = \func_get_args();

if (\func_num_args() < 3) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);

$status = $args[0] ?? true;

if (!$status) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Passing a null message to un-deprecate a node is deprecated.');
}

$message = (string) ($args[1] ?? null);
$package = $version = '';
} else {
$status = true;
$package = (string) $args[0];
$version = (string) $args[1];
$message = (string) $args[2];
}

if ('' !== $message) {
if (preg_match('#[\r\n]|\*/#', $message)) {
throw new InvalidArgumentException('Invalid characters found in deprecation template.');
Expand All @@ -731,7 +697,7 @@ public function setDeprecated(/* string $package, string $version, string $messa
}

$this->changes['deprecated'] = true;
$this->deprecation = $status ? ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE] : [];
$this->deprecation = ['package' => $package, 'version' => $version, 'message' => $message ?: self::DEFAULT_DEPRECATION_TEMPLATE];

return $this;
}
Expand All @@ -747,22 +713,6 @@ public function isDeprecated()
return (bool) $this->deprecation;
}

/**
* Message to use if this definition is deprecated.
*
* @deprecated since Symfony 5.1, use "getDeprecation()" instead.
*
* @param string $id Service id relying on this definition
*
* @return string
*/
public function getDeprecationMessage(string $id)
{
trigger_deprecation('symfony/dependency-injection', '5.1', 'The "%s()" method is deprecated, use "getDeprecation()" instead.', __METHOD__);

return $this->getDeprecation($id)['message'];
}

/**
* @param string $id Service id relying on this definition
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ function param(string $name): ParamConfigurator
return new ParamConfigurator($name);
}

/**
* Creates a service reference.
*
* @deprecated since Symfony 5.1, use service() instead.
*/
function ref(string $id): ReferenceConfigurator
{
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "service()" instead.', __FUNCTION__);

return new ReferenceConfigurator($id);
}

/**
* Creates a reference to a service.
*/
Expand All @@ -123,18 +111,6 @@ function service(string $serviceId): ReferenceConfigurator
return new ReferenceConfigurator($serviceId);
}

/**
* Creates an inline service.
*
* @deprecated since Symfony 5.1, use inline_service() instead.
*/
function inline(string $class = null): InlineServiceConfigurator
{
trigger_deprecation('symfony/dependency-injection', '5.1', '"%s()" is deprecated, use "inline_service()" instead.', __FUNCTION__);

return new InlineServiceConfigurator(new Definition($class));
}

/**
* Creates an inline service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,8 @@ trait DeprecateTrait
*
* @throws InvalidArgumentException when the message template is invalid
*/
final public function deprecate(/* string $package, string $version, string $message */): self
final public function deprecate(string $package, string $version, string $message): self
{
$args = \func_get_args();
$package = $version = $message = '';

if (\func_num_args() < 3) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'The signature of method "%s()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', __METHOD__);

$message = (string) ($args[0] ?? null);
} else {
$package = (string) $args[0];
$version = (string) $args[1];
$message = (string) $args[2];
}

$this->definition->setDeprecated($package, $version, $message);

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
$version = $deprecated[0]->getAttribute('version') ?: '';

if (!$deprecated[0]->hasAttribute('package')) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.', $file);
throw new InvalidArgumentException(sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
}

if (!$deprecated[0]->hasAttribute('version')) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" in "%s" is deprecated.', $file);
throw new InvalidArgumentException(sprintf('Missing attribute "version" at node "deprecated" in "%s".', $file));
}

$alias->setDeprecated($package, $version, $message);
Expand Down Expand Up @@ -284,12 +284,12 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
$package = $deprecated[0]->getAttribute('package') ?: '';
$version = $deprecated[0]->getAttribute('version') ?: '';

if ('' === $package) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the node "deprecated" in "%s" is deprecated.', $file);
if (!$deprecated[0]->hasAttribute('package')) {
throw new InvalidArgumentException(sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
}

if ('' === $version) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the node "deprecated" in "%s" is deprecated.', $file);
if (!$deprecated[0]->hasAttribute('version')) {
throw new InvalidArgumentException(sprintf('Missing attribute "version" at node "deprecated" in "%s".', $file));
}

$definition->setDeprecated($package, $version, $message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
use Symfony\Component\DependencyInjection\Argument\ArgumentInterface;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
Expand Down Expand Up @@ -429,11 +428,11 @@ private function parseDefinition(string $id, array|string|null $service, string
$deprecation = \is_array($value) ? $value : ['message' => $value];

if (!isset($deprecation['package'])) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
throw new InvalidArgumentException(sprintf('Missing attribute "package" of the "deprecated" option in "%s".', $file));
}

if (!isset($deprecation['version'])) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
throw new InvalidArgumentException(sprintf('Missing attribute "version" of the "deprecated" option in "%s".', $file));
}

$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
Expand Down Expand Up @@ -500,11 +499,11 @@ private function parseDefinition(string $id, array|string|null $service, string
$deprecation = \is_array($service['deprecated']) ? $service['deprecated'] : ['message' => $service['deprecated']];

if (!isset($deprecation['package'])) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "package" of the "deprecated" option in "%s" is deprecated.', $file);
throw new InvalidArgumentException(sprintf('Missing attribute "package" of the "deprecated" option in "%s".', $file));
}

if (!isset($deprecation['version'])) {
trigger_deprecation('symfony/dependency-injection', '5.1', 'Not setting the attribute "version" of the "deprecated" option in "%s" is deprecated.', $file);
throw new InvalidArgumentException(sprintf('Missing attribute "version" of the "deprecated" option in "%s".', $file));
}

$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
Expand Down
Loading