8000 [Console] Remove console deprecations · symfony/symfony@4afe73c · GitHub
[go: up one dir, main page]

Skip to content

Commit 4afe73c

Browse files
jschaedlnicolas-grekas
authored andcommitted
[Console] Remove console deprecations
1 parent 68563ec commit 4afe73c

File tree

9 files changed

+20
-57
lines changed

9 files changed

+20
-57
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
=========
33

4+
6.0
5+
---
6+
7+
* `Command::setHidden()` has a default value (`true`) for `$hidden` parameter and is final
8+
* Remove `Helper::strlen()`, use `Helper::width()` instead
9+
* Remove `Helper::strlenWithoutDecoration()`, use `Helper::removeDecoration()` instead
10+
* `AddConsoleCommandPass` can not be configured anymore
11+
412
5.3
513
---
614

src/Symfony/Component/Console/Command/Command.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,10 @@ public function getName()
495495

496496
/**
497497
* @param bool $hidden Whether or not the command should be hidden from the list of commands
498-
* The default value will be true in Symfony 6.0
499498
*
500499
* @return Command The current instance
501-
*
502-
* @final since Symfony 5.1
503500
*/
504-
public function setHidden(bool $hidden /*= true*/)
501+
final public function setHidden(bool $hidden = true): static
505502
{
506503
$this->hidden = $hidden;
507504

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,16 @@
2929
*/
3030
class AddConsoleCommandPass implements CompilerPassInterface
3131
{
32-
private $commandLoaderServiceId;
33-
private $commandTag;
34-
private $noPreloadTag;
35-
private $privateTagName;
36-
37-
public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private')
38-
{
39-
if (0 < \func_num_args()) {
40-
trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
41-
}
42-
43-
$this->commandLoaderServiceId = $commandLoaderServiceId;
44-
$this->commandTag = $commandTag;
45-
$this->noPreloadTag = $noPreloadTag;
46-
$this->privateTagName = $privateTagName;
47-
}
48-
4932
public function process(ContainerBuilder $container)
5033
{
51-
$commandServices = $container->findTaggedServiceIds($this->commandTag, true);
34+
$commandServices = $container->findTaggedServiceIds('console.command', true);
5235
$lazyCommandMap = [];
5336
$lazyCommandRefs = [];
5437
$serviceIds = [];
5538

5639
foreach ($commandServices as $id => $tags) {
5740
$definition = $container->getDefinition($id);
58-
$definition->addTag($this->noPreloadTag);
41+
$definition->addTag('container.no_preload');
5942
$class = $container->getParameterBag()->resolveValue($definition->getClass());
6043

6144
if (isset($tags[0]['command'])) {
@@ -65,7 +48,7 @@ public function process(ContainerBuilder $container)
6548
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
6649
}
6750
if (!$r->isSubclassOf(Command::class)) {
68-
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
51+
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class));
6952
}
7053
$aliases = $class::getDefaultName();
7154
}
@@ -78,7 +61,7 @@ public function process(ContainerBuilder $container)
7861
}
7962

8063
if (null === $commandName) {
81-
if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) {
64+
if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag('container.private')) {
8265
$commandId = 'console.command.public_alias.'.$id;
8366
$container->setAlias($commandId, $id)->setPublic(true);
8467
$id = $commandId;
@@ -122,7 +105,7 @@ public function process(ContainerBuilder $container)
122105
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
123106
}
124107
if (!$r->isSubclassOf(Command::class)) {
125-
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
108+
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class));
126109
}
127110
$description = $class::getDefaultDescription();
128111
}
@@ -138,9 +121,9 @@ public function process(ContainerBuilder $container)
138121
}
139122

140123
$container
141-
->register($this->commandLoaderServiceId, ContainerCommandLoader::class)
124+
->register('console.command_loader', ContainerCommandLoader::class)
142125
->setPublic(true)
143-
->addTag($this->noPreloadTag)
126+
->addTag('container.no_preload')
144127
->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]);
145128

146129
$container->setParameter('console.command.ids', $serviceIds);

src/Symfony/Component/Console/Helper/Helper.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ public function getHelperSet()
3939
return $this->helperSet;
4040
}
4141

42-
/**
43-
* Returns the length of a string, using mb_strwidth if it is available.
44-
*
45-
* @deprecated since 5.3
46-
*
47-
* @return int The length of the string
48-
*/
49-
public static function strlen(?string $string)
50-
{
51-
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__);
52-
53-
return self::width($string);
54-
}
55-
5642
/**
5743
* Returns the width of a string, using mb_strwidth if it is available.
5844
* The width is how many characters positions the string will use.
@@ -153,16 +139,6 @@ public static function formatMemory(int $memory)
153139
return sprintf('%d B', $memory);
154140
}
155141

156-
/**
157-
* @deprecated since 5.3
158-
*/
159-
public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string)
160-
{
161-
trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__);
162-
163-
return self::width(self::removeDecoration($formatter, $string));
164-
}
165-
166142
public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string)
167143
{
168144
$isDecorated = $formatter->isDecorated();

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testAddOption()
9696
public function testSetHidden()
9797
{
9898
$command = new \TestCommand();
99-
$command->setHidden(true);
99+
$command->setHidden();
100100
$this->assertTrue($command->isHidden());
101101
}
102102

src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protected function configure()
1111
$this
1212
->setName('bar:hidden')
1313
->setAliases(['abarhidden'])
14-
->setHidden(true)
14+
->setHidden()
1515
;
1616
}
1717

src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function configure()
2121
->setName('descriptor:command3')
2222
->setDescription('command 3 description')
2323
->setHelp('command 3 help')
24-
->setHidden(true)
24+
->setHidden()
2525
;
2626
}
2727
}

src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protected function configure()
1111
$this
1212
->setName('foo:hidden')
1313
->setAliases(['afoohidden'])
14-
->setHidden(true)
14+
->setHidden()
1515
;
1616
}
1717

src/Symfony/Component/Console/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
],
1818
"require": {
1919
"php": ">=8.0.2",
20-
"symfony/deprecation-contracts": "^2.1",
2120
"symfony/polyfill-mbstring": "~1.0",
2221
"symfony/service-contracts": "^1.1|^2",
2322
"symfony/string": "^5.1|^6.0"

0 commit comments

Comments
 (0)
0