@@ -8,6 +8,16 @@ There is a lot of way to create and declare such classes.
88> ** Note :** It is pretty much like [ declaring classic enums] ( declaring-enum.md ) ,
99> but with a dependency to ` symfony/translator ` .
1010
11+ Services declarations assume that your services files has the following defaults section :
12+
13+ ``` yaml
14+ services :
15+ _defaults :
16+ public : false
17+ autowire : true
18+ autconfigure : true
19+ ` ` `
20+
1121
1222The classic way
1323---------------
@@ -41,16 +51,11 @@ class GenderEnum extends AbstractTranslatedEnum
4151}
4252` ` `
4353
44- Define an enum service for it.
54+ Define an enum service for it (optional if you are using the default Symfony services file) .
4555
4656` ` ` yaml
4757services:
48- enum.member.gender :
49- class : ' App\Enum\GenderEnum'
50- public : false
51- tags : ['enum']
52- arguments :
53- - " @translator"
58+ App\E num\G enderEnum: ~
5459` ` `
5560
5661
@@ -84,16 +89,11 @@ class GenderEnum extends AbstractTranslatedEnum
8489}
8590` ` `
8691
87- Define an enum service for it.
92+ Define an enum service for it (optional if you are using the default Symfony services file) .
8893
8994` ` ` yaml
9095services:
91- enum.member.gender:
92- class: 'App\E num\G enderEnum'
93- public: false
94- tags: ['enum']
95- arguments:
96- - "@translator"
96+ App\E num\G enderEnum: ~
9797` ` `
9898
9999
@@ -105,14 +105,11 @@ No need for a class, just use the `ConfigurableTranslatedEnum` class and define
105105` ` ` yaml
106106services:
107107 enum.member.gender:
108- class: 'Yokai\E numBundle\C onfigurableTranslatedEnum'
109- public: false
110- tags: ['enum']
108+ class: Yokai\E numBundle\C onfigurableTranslatedEnum
111109 arguments:
112- - "@translator"
113- - "enum.gender.%s"
114- - "gender"
115- - ['m', 'f']
110+ $transPattern: 'enum.gender.%s'
111+ $name: 'gender'
112+ $values: ['m', 'f']
116113` ` `
117114
118115The configurable way extracting constant list
@@ -124,13 +121,9 @@ No need for a class, just use the `ConstantListTranslatedEnum` class and define
124121` ` ` yaml
125122services:
126123 enum.member.gender:
127- class: 'Yokai\E numBundle\C onstantListTranslatedEnum'
128- public: false
129- tags: ['enum']
124+ class: Yokai\E numBundle\C onstantListTranslatedEnum
130125 arguments:
131- - '@yokai_enum.constant_extractor'
132- - 'App\\ Model\\ Person::GENDER_*'
133- - "@translator"
134- - "enum.gender.%s"
135- - "gender"
126+ $constantsPattern: 'App\\ Model\\ Person::GENDER_*'
127+ $transPattern: 'enum.gender.%s'
128+ $name: 'gender'
136129` ` `
0 commit comments