We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Enums represent a closed list of possible values. Supporting backed enums as option or argument type would enable:
suggestedValues: BackedEnum::cases()
BackedEnum::tryFrom($input)
__invoke
In Symfony itself, most of the --format options could be enums.
--format
Given a backed enum like this:
enum EmbeddingType: string { case Image = 'image'; case Description = 'description'; }
The argument parameter should accept a backed enum type,
#[AsCommand(name: 'app:regenerate')] class RegenerateCommand { public function __invoke(#[Argument] EmbeddingType $type): int { $this->generator->generate($type); } }
If the command is run with an invalid value, an error is returned.
$ app/console app:regenerate yolo The "yolo" value is not accepted. Use one of "image", "description".
The text was updated successfully, but these errors were encountered:
We can modify the argument and option definition classes to add a $values property that would accept an array of scalars or a backed enum.
$values
Sorry, something went wrong.
For backed enums, I don't think we should need to add anything in the attributes. This can be inferred from the parameter type.
Sure, my comment was if we want to support backed enum in regular command definition. Which is an other topic.
Object support will come with value resolvers
@chalasr this won't provide automatic completion for backed enum values if we don't have a special handling for them.
But anyway, we have 5 months to figure out the solution for Symfony 7.4.
No branches or pull requests
Description
Enums represent a closed list of possible values. Supporting backed enums as option or argument type would enable:
suggestedValues: BackedEnum::cases()
values)BackedEnum::tryFrom($input)
in the command__invoke
.In Symfony itself, most of the
--format
options could be enums.Example
Given a backed enum like this:
The argument parameter should accept a backed enum type,
If the command is run with an invalid value, an error is returned.
The text was updated successfully, but these errors were encountered: