AsCommand.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. * @var string
  19. */
  20. public $name;
  21. /**
  22. * @var string|null
  23. */
  24. public $description;
  25. /**
  26. * @param string $name
  27. * @param string|null $description
  28. * @param mixed[] $aliases
  29. * @param bool $hidden
  30. */
  31. public function __construct($name, $description = null, $aliases = [], $hidden = false)
  32. {
  33. $this->name = $name;
  34. $this->description = $description;
  35. if (!$hidden && !$aliases) {
  36. return;
  37. }
  38. $name = explode('|', $name);
  39. $name = array_merge($name, $aliases);
  40. if ($hidden && '' !== $name[0]) {
  41. array_unshift($name, '');
  42. }
  43. $this->name = implode('|', $name);
  44. }
  45. }