From 4afe73c42b5a14a99a1269e1533ff3fb0ecf7cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Thu, 20 May 2021 07:16:46 +0100 Subject: [PATCH] [Console] Remove console deprecations --- src/Symfony/Component/Console/CHANGELOG.md | 8 +++++ .../Component/Console/Command/Command.php | 5 +-- .../AddConsoleCommandPass.php | 31 +++++-------------- .../Component/Console/Helper/Helper.php | 24 -------------- .../Console/Tests/Command/CommandTest.php | 2 +- .../Tests/Fixtures/BarHiddenCommand.php | 2 +- .../Tests/Fixtures/DescriptorCommand3.php | 2 +- .../Tests/Fixtures/FooHiddenCommand.php | 2 +- src/Symfony/Component/Console/composer.json | 1 - 9 files changed, 20 insertions(+), 57 deletions(-) diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index 8808563869273..9b39f52c9b929 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +6.0 +--- + + * `Command::setHidden()` has a default value (`true`) for `$hidden` parameter and is final + * Remove `Helper::strlen()`, use `Helper::width()` instead + * Remove `Helper::strlenWithoutDecoration()`, use `Helper::removeDecoration()` instead + * `AddConsoleCommandPass` can not be configured anymore + 5.3 --- diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index e35ae51ebfa28..8ffa95fc1c0f1 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -495,13 +495,10 @@ public function getName() /** * @param bool $hidden Whether or not the command should be hidden from the list of commands - * The default value will be true in Symfony 6.0 * * @return Command The current instance - * - * @final since Symfony 5.1 */ - public function setHidden(bool $hidden /*= true*/) + final public function setHidden(bool $hidden = true): static { $this->hidden = $hidden; diff --git a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php index 743e306d07b9a..efaf39a2c9a20 100644 --- a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php +++ b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php @@ -29,33 +29,16 @@ */ class AddConsoleCommandPass implements CompilerPassInterface { - private $commandLoaderServiceId; - private $commandTag; - private $noPreloadTag; - private $privateTagName; - - public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') - { - if (0 < \func_num_args()) { - trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); - } - - $this->commandLoaderServiceId = $commandLoaderServiceId; - $this->commandTag = $commandTag; - $this->noPreloadTag = $noPreloadTag; - $this->privateTagName = $privateTagName; - } - public function process(ContainerBuilder $container) { - $commandServices = $container->findTaggedServiceIds($this->commandTag, true); + $commandServices = $container->findTaggedServiceIds('console.command', true); $lazyCommandMap = []; $lazyCommandRefs = []; $serviceIds = []; foreach ($commandServices as $id => $tags) { $definition = $container->getDefinition($id); - $definition->addTag($this->noPreloadTag); + $definition->addTag('container.no_preload'); $class = $container->getParameterBag()->resolveValue($definition->getClass()); if (isset($tags[0]['command'])) { @@ -65,7 +48,7 @@ public function process(ContainerBuilder $container) throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$r->isSubclassOf(Command::class)) { - throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); + throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class)); } $aliases = $class::getDefaultName(); } @@ -78,7 +61,7 @@ public function process(ContainerBuilder $container) } if (null === $commandName) { - if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) { + if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag('container.private')) { $commandId = 'console.command.public_alias.'.$id; $container->setAlias($commandId, $id)->setPublic(true); $id = $commandId; @@ -122,7 +105,7 @@ public function process(ContainerBuilder $container) throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$r->isSubclassOf(Command::class)) { - throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); + throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class)); } $description = $class::getDefaultDescription(); } @@ -138,9 +121,9 @@ public function process(ContainerBuilder $container) } $container - ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) + ->register('console.command_loader', ContainerCommandLoader::class) ->setPublic(true) - ->addTag($this->noPreloadTag) + ->addTag('container.no_preload') ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); $container->setParameter('console.command.ids', $serviceIds); diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php index 881b4dc4fb4a1..320a73d80952b 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -39,20 +39,6 @@ public function getHelperSet() return $this->helperSet; } - /** - * Returns the length of a string, using mb_strwidth if it is available. - * - * @deprecated since 5.3 - * - * @return int The length of the string - */ - public static function strlen(?string $string) - { - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__); - - return self::width($string); - } - /** * Returns the width of a string, using mb_strwidth if it is available. * The width is how many characters positions the string will use. @@ -153,16 +139,6 @@ public static function formatMemory(int $memory) return sprintf('%d B', $memory); } - /** - * @deprecated since 5.3 - */ - public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) - { - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__); - - return self::width(self::removeDecoration($formatter, $string)); - } - public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) { $isDecorated = $formatter->isDecorated(); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index fad1f34589b96..74c2708a7796a 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -96,7 +96,7 @@ public function testAddOption() public function testSetHidden() { $command = new \TestCommand(); - $command->setHidden(true); + $command->setHidden(); $this->assertTrue($command->isHidden()); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php index 58af8d816c386..87add7f8e0c20 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php @@ -11,7 +11,7 @@ protected function configure() $this ->setName('bar:hidden') ->setAliases(['abarhidden']) - ->setHidden(true) + ->setHidden() ; } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php index 77f92e233f292..5dbb4eb5d3100 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php @@ -21,7 +21,7 @@ protected function configure() ->setName('descriptor:command3') ->setDescription('command 3 description') ->setHelp('command 3 help') - ->setHidden(true) + ->setHidden() ; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php index 68e495b7610f9..94c7d74ad8286 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php @@ -11,7 +11,7 @@ protected function configure() $this ->setName('foo:hidden') ->setAliases(['afoohidden']) - ->setHidden(true) + ->setHidden() ; } diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 46f8a44033cd0..ca1235a820be2 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -17,7 +17,6 @@ ], "require": { "php": ">=8.0.2", - "symfony/deprecation-contracts": "^2.1", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^1.1|^2", "symfony/string": "^5.1|^6.0"