Commit 7fc548d
committed
feature #52230 [Yaml] Allow to get all the enum cases (phansys)
This PR was merged into the 7.1 branch.
Discussion
----------
[Yaml] Allow to get all the enum cases
| Q | A
| ------------- | ---
| Branch? | 7.1
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | n/a
| License | MIT
<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the latest branch.
- For new features, provide some code snippets to help understand usage.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
With this addition, the `!php/enum` syntax is allowed to expose an array with all the enum cases (the result from [`UnitEnum::cases()`](https://www.php.net/manual/en/unitenum.cases.php)). This is useful for cases like `choices` option from the `Choice` validation constraint:
**BEFORE**:
```yaml
App\Entity\User:
properties:
status:
- Choice:
choices:
- !php/enum 'App\Entity\Enum\UserStatus::Enabled'
- !php/enum 'App\Entity\Enum\UserStatus::Disabled'
- !php/enum 'App\Entity\Enum\UserStatus::Blocked'
```
**AFTER**:
```yaml
App\Entity\User:
properties:
status:
- Choice:
choices: !php/enum 'App\Entity\Enum\UserStatus'
```
Prior to the support for enumerations, this was allowed by array constants:
```yaml
App\Entity\User:
properties:
status:
- Choice:
choices: !php/const 'App\Entity\User::AVAILABLE_STATUSES'
```
Commits
-------
3286539bef [Yaml] Allow Yaml component to get all the enum cases3 files changed
+37
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
4 | 9 | | |
5 | 10 | | |
6 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
651 | 651 | | |
652 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
653 | 659 | | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
| 660 | + | |
| 661 | + | |
658 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
659 | 666 | | |
660 | 667 | | |
661 | 668 | | |
662 | 669 | | |
663 | | - | |
| 670 | + | |
664 | 671 | | |
665 | 672 | | |
666 | 673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
86 | | - | |
| 93 | + | |
87 | 94 | | |
88 | 95 | | |
89 | 96 | | |
| |||
718 | 725 | | |
719 | 726 | | |
720 | 727 | | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
721 | 733 | | |
722 | 734 | | |
723 | 735 | | |
| |||
0 commit comments