AsCommand.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Attribute;
  11. /**
  12. * Service tag to autoconfigure commands.
  13. *
  14. * @final since Symfony 7.3
  15. */
  16. #[\Attribute(\Attribute::TARGET_CLASS)]
  17. class AsCommand
  18. {
  19. /**
  20. * @param string $name The name of the command, used when calling it (i.e. "cache:clear")
  21. * @param string|null $description The description of the command, displayed with the help page
  22. * @param string[] $aliases The list of aliases of the command. The command will be executed when using one of them (i.e. "cache:clean")
  23. * @param bool $hidden If true, the command won't be shown when listing all the available commands, but it can still be run as any other command
  24. * @param string|null $help The help content of the command, displayed with the help page
  25. */
  26. public function __construct(
  27. public string $name,
  28. public ?string $description = null,
  29. array $aliases = [],
  30. bool $hidden = false,
  31. public ?string $help = null,
  32. ) {
  33. if (!$hidden && !$aliases) {
  34. return;
  35. }
  36. $name = explode('|', $name);
  37. $name = array_merge($name, $aliases);
  38. if ($hidden && '' !== $name[0]) {
  39. array_unshift($name, '');
  40. }
  41. $this->name = implode('|', $name);
  42. }
  43. }