Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Remove console deprecations #41312

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
May 23, 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
[Console] Remove console deprecations
  • Loading branch information
jschaedl authored and nicolas-grekas committed May 23, 2021
commit 4afe73c42b5a14a99a1269e1533ff3fb0ecf7cde
8 changes: 8 additions & 0 deletions 8 src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
5 changes: 1 addition & 4 deletions 5 src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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();
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions 24 src/Symfony/Component/Console/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved
{
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.
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testAddOption()
public function testSetHidden()
{
$command = new \TestCommand();
$command->setHidden(true);
$command->setHidden();
$this->assertTrue($command->isHidden());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected function configure()
$this
->setName('bar:hidden')
->setAliases(['abarhidden'])
->setHidden(true)
->setHidden()
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function configure()
->setName('descriptor:command3')
->setDescription('command 3 description')
->setHelp('command 3 help')
->setHidden(true)
->setHidden()
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected function configure()
$this
->setName('foo:hidden')
->setAliases(['afoohidden'])
->setHidden(true)
->setHidden()
;
}

Expand Down
1 change: 0 additions & 1 deletion 1 src/Symfony/Component/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.