diff --git a/src/Symfony/Component/Console/Attribute/Input.php b/src/Symfony/Component/Console/Attribute/MapInput.php similarity index 97% rename from src/Symfony/Component/Console/Attribute/Input.php rename to src/Symfony/Component/Console/Attribute/MapInput.php index 65bbf4aef965f..5609e665582c5 100644 --- a/src/Symfony/Component/Console/Attribute/Input.php +++ b/src/Symfony/Component/Console/Attribute/MapInput.php @@ -15,8 +15,11 @@ use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Console\Input\InputInterface; +/** + * Maps a command input into an object (DTO). + */ #[\Attribute(\Attribute::TARGET_PARAMETER | \Attribute::TARGET_PROPERTY)] -final class Input +final class MapInput { /** * @var array diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index 51cafcd49428b..911196e12f017 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -11,7 +11,7 @@ CHANGELOG * Add `BackedEnum` support with `#[Argument]` and `#[Option]` inputs in invokable commands * Allow Usages to be specified via `#[AsCommand]` attribute. * Allow passing invokable commands to `Symfony\Component\Console\Tester\CommandTester` - * Add `#[Input]` attribute to support DTOs in commands + * Add `#[MapInput]` attribute to support DTOs in commands * Add optional timeout for interaction in `QuestionHelper` 7.3 diff --git a/src/Symfony/Component/Console/Command/InvokableCommand.php b/src/Symfony/Component/Console/Command/InvokableCommand.php index 9974589961a02..3d12a9ad140c3 100644 --- a/src/Symfony/Component/Console/Command/InvokableCommand.php +++ b/src/Symfony/Component/Console/Command/InvokableCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Attribute\Argument; -use Symfony\Component\Console\Attribute\Input; +use Symfony\Component\Console\Attribute\MapInput; use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Console\Exception\RuntimeException; @@ -87,7 +87,7 @@ public function configure(InputDefinition $definition): void continue; } - if ($input = Input::tryFrom($parameter)) { + if ($input = MapInput::tryFrom($parameter)) { $inputArguments = array_map(fn (Argument $a) => $a->toInputArgument(), iterator_to_array($input->getArguments(), false)); // make sure optional arguments are defined after required ones @@ -149,7 +149,7 @@ private function getParameters(InputInterface $input, OutputInterface $output): continue; } - if ($in = Input::tryFrom($parameter)) { + if ($in = MapInput::tryFrom($parameter)) { $parameters[] = $in->resolveValue($input); continue; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/InvokableWithInputTestCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/InvokableWithInputTestCommand.php index e3a3366425e4e..b7cadf11ccf5e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/InvokableWithInputTestCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/InvokableWithInputTestCommand.php @@ -13,7 +13,7 @@ use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; -use Symfony\Component\Console\Attribute\Input; +use Symfony\Component\Console\Attribute\MapInput; use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Style\SymfonyStyle; @@ -21,7 +21,7 @@ #[AsCommand('invokable:input:test')] class InvokableWithInputTestCommand { - public function __invoke(SymfonyStyle $io, #[Input] UserDto $user): int + public function __invoke(SymfonyStyle $io, #[MapInput] UserDto $user): int { $io->writeln($user->name); $io->writeln($user->email); @@ -47,7 +47,7 @@ final class UserDto #[Argument] public string $password; - #[Input] + #[MapInput] public UserGroupDto $group; #[Option]