Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Description
Enums represent aclosed list of possible values. Supportingbacked enums as option or argument type would enable:
- Auto-completion from enum cases values (ie:
suggestedValues: BackedEnum::cases()
values) - Validation of the input value with a nice error message
- No need to call
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:
enum EmbeddingType:string{case Image ='image';case Description ='description';}
The argument parameter should accept a backed enum type,
#[AsCommand(name:'app:regenerate')]class RegenerateCommand{publicfunction__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".