-
|
i have this yaml, and i'd like to use enum (or const) value as a key. framework:
workflows:
test:
type: 'state_machine'
initial_marking: !php/enum App\Entity\Status::draft
places: !php/enum App\Entity\Status
transitions:
'!php/enum App\Entity\Status::draft': # this does not resolve -> transition name is literally this string
from:
- !php/enum App\Entity\Status::finished
- !php/enum App\Entity\Status::cancelled
to: !php/enum App\Entity\Status::draftwhen i quote it, then it's literal. when i remove the quotation, i get
so i guess it's not possible at all? or is there any special syntax for this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment · 1 reply
-
|
Using an enum as key is impossible because PHP arrays only allow string or integers as array keys, not objects (and enum cases are objects). The following is invalid PHP code, while it is exactly the equivalent of your feature request $transition = [
App\Entity\Status::draft: [ // <- invalid offset type
'from' => [App\Entity\Status::finished, App\Entity\Status::cancelled],
'to' => App\Entity\Status::draft,
]
];Side note: I assumed you meant |
Beta Was this translation helpful? Give feedback.
Using an enum as key is impossible because PHP arrays only allow string or integers as array keys, not objects (and enum cases are objects).
The following is invalid PHP code, while it is exactly the equivalent of your feature request
Side note: I assumed you meant
!php/enum App\Entity\Status::draftas key, not'!php/enum App\Entity\Status::draft'. In Yaml, quoted string literals are always literal strings. The Yaml tag syntax is unquoted.