-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Console] Add #[Input]
attribute to support DTOs in invokable commands
#61478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.4
Are you sure you want to change the base?
Conversation
Nice, it was on my list! |
it seems we shared the same list at some point :) |
src/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php
Outdated
Show resolved
Hide resolved
1a792fb
to
0ed04d7
Compare
Appreciate the feedback @nicolas-grekas 🙏, all points have been addressed. |
6cdbc96
to
84d092f
Compare
84d092f
to
28f49fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failures unrelated
The Fabbot failures are false positives, are there any other failures I might have overlooked? |
This PR introduces support for using DTOs as command inputs in Console commands through a new
#[Input]
attribute. Especially useful for commands with many arguments and options, as it prevents cluttering the__invoke()
method with lengthy parameter lists and their associated attributes and options.Example:
The command's arguments and options are defined directly on the DTO's properties. These properties need to be public, and now you can use property hooks to normalize the value when necessary.
✨ Input validation and handling become naturally simpler 😉
It also supports splitting the command input across multiple DTOs (e.g. grouping inputs into
UserDto
andGroupDto
), or more complex structured like nested DTOs:Thus, we can model the command input while defining its arguments and options. Here's the resulting usage output from the previous definition:
Food for Future PRs
Cheers!