Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Argument|Option|self>
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Console/Command/InvokableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

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;

#[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);
Expand All @@ -47,7 +47,7 @@ final class UserDto
#[Argument]
public string $password;

#[Input]
#[MapInput]
public UserGroupDto $group;

#[Option]
Expand Down
Loading