|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\Fixture; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 6 | +use Symfony\Component\Console\Command\Command; |
| 7 | +use Symfony\Component\Console\Input\InputInterface; |
| 8 | +use Symfony\Component\Console\Output\OutputInterface; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | +use Symfony\Component\Console\Input\InputOption; |
| 11 | + |
| 12 | +#[AsCommand(name: 'some_name')] |
| 13 | +final class WithOptionalArgument extends Command |
| 14 | +{ |
| 15 | + public function configure() |
| 16 | + { |
| 17 | + $this->addArgument('argument', InputArgument::OPTIONAL, 'Argument description'); |
| 18 | + $this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description'); |
| 19 | + } |
| 20 | + |
| 21 | + public function execute(InputInterface $input, OutputInterface $output): int |
| 22 | + { |
| 23 | + $someArgument = $input->getArgument('argument'); |
| 24 | + $someOption = $input->getOption('option'); |
| 25 | + |
| 26 | + // ... |
| 27 | + |
| 28 | + return 1; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +?> |
| 33 | +----- |
| 34 | +<?php |
| 35 | + |
| 36 | +namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\Fixture; |
| 37 | + |
| 38 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 39 | +use Symfony\Component\Console\Command\Command; |
| 40 | +use Symfony\Component\Console\Input\InputInterface; |
| 41 | +use Symfony\Component\Console\Output\OutputInterface; |
| 42 | +use Symfony\Component\Console\Input\InputArgument; |
| 43 | +use Symfony\Component\Console\Input\InputOption; |
| 44 | + |
| 45 | +#[AsCommand(name: 'some_name')] |
| 46 | +final class WithOptionalArgument |
| 47 | +{ |
| 48 | + public function __invoke(#[\Symfony\Component\Console\Attribute\Argument(name: 'argument', mode: InputArgument::OPTIONAL, description: 'Argument description')] |
| 49 | + ?string $argument, #[\Symfony\Component\Console\Attribute\Command\Option] |
| 50 | + $option, OutputInterface $output): int |
| 51 | + { |
| 52 | + $someArgument = $argument; |
| 53 | + $someOption = $option; |
| 54 | + |
| 55 | + // ... |
| 56 | + |
| 57 | + return 1; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +?> |
0 commit comments