AsCommand.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #[\Attribute(\Attribute::TARGET_CLASS)]
  15. class AsCommand
  16. {
  17. /**
  18. * @param string $name The name of the command, used when calling it (i.e. "cache:clear")
  19. * @param string|null $description The description of the command, displayed with the help page
  20. * @param string[] $aliases The list of aliases of the command. The command will be executed when using one of them (i.e. "cache:clean")
  21. * @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
  22. */
  23. public function __construct(
  24. public string $name,
  25. public ?string $description = null,
  26. array $aliases = [],
  27. bool $hidden = false,
  28. ) {
  29. if (!$hidden && !$aliases) {
  30. return;
  31. }
  32. $name = explode('|', $name);
  33. $name = array_merge($name, $aliases);
  34. if ($hidden && '' !== $name[0]) {
  35. array_unshift($name, '');
  36. }
  37. $this->name = implode('|', $name);
  38. }
  39. }