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