17
17
use Symfony \Component \Config \Definition \ConfigurationInterface ;
18
18
19
19
/**
20
- * This is the class that validates and merges configuration from app/config files
20
+ * This is the class that validates and merges configuration from app/config files.
21
21
*/
22
22
class Configuration implements ConfigurationInterface
23
23
{
@@ -77,14 +77,16 @@ private function addFiltersSection(ArrayNodeDefinition $rootNode)
77
77
->children ()
78
78
->arrayNode ('filters ' )
79
79
->validate ()
80
- ->ifTrue (function ($ v ) {
80
+ ->ifTrue (
81
+ function ($ v ) {
81
82
$ v = array_filter ($ v );
82
83
83
84
return empty ($ v );
84
- })
85
+ }
86
+ )
85
87
->thenInvalid ('At least single filter must be configured. ' )
86
88
->end ()
87
- // TODO: validate if filter names are unique
89
+ // TODO: validate if filter names are unique.
88
90
->isRequired ()
89
91
->append ($ this ->buildFilterTree ('choice ' ))
90
92
->append ($ this ->buildFilterTree ('match ' ))
@@ -97,7 +99,7 @@ private function addFiltersSection(ArrayNodeDefinition $rootNode)
97
99
}
98
100
99
101
/**
100
- * Builds filter config tree for given filter name
102
+ * Builds filter config tree for given filter name.
101
103
*
102
104
* @param string $filterName
103
105
*
@@ -131,14 +133,18 @@ private function buildFilterTree($filterName)
131
133
->arrayNode ('choices ' )
132
134
->prototype ('array ' )
133
135
->beforeNormalization ()
134
- ->ifTrue (function ($ v ) {
136
+ ->ifTrue (
137
+ function ($ v ) {
135
138
return empty ($ v ['label ' ]);
136
- })
137
- ->then (function ($ v ) {
139
+ }
140
+ )
141
+ ->then (
142
+ function ($ v ) {
138
143
$ v ['label ' ] = $ v ['field ' ];
139
144
140
145
return $ v ;
141
- })
146
+ }
147
+ )
142
148
->end ()
143
149
->children ()
144
150
->scalarNode ('label ' )->end ()
@@ -164,6 +170,9 @@ private function buildFilterTree($filterName)
164
170
->end ()
165
171
->end ();
166
172
break ;
173
+ default :
174
+ // Should not happen.
175
+ break ;
167
176
}
168
177
169
178
return $ filter ;
@@ -182,28 +191,36 @@ private function buildRelationsTree($relationType)
182
191
183
192
$ filter
184
193
->validate ()
185
- ->ifTrue (function ($ v ) {
186
- return empty ($ v ['include ' ]) && empty ($ v ['exclude ' ]);
187
- })
194
+ ->ifTrue (
195
+ function ($ v ) {
196
+ return empty ($ v ['include ' ]) && empty ($ v ['exclude ' ]);
197
+ }
198
+ )
188
199
->thenInvalid ('Relation must have "include" or "exclude" fields specified. ' )
189
200
->end ()
190
201
->validate ()
191
- ->ifTrue (function ($ v ) {
192
- return !empty ($ v ['include ' ]) && !empty ($ v ['exclude ' ]);
193
- })
202
+ ->ifTrue (
203
+ function ($ v ) {
204
+ return !empty ($ v ['include ' ]) && !empty ($ v ['exclude ' ]);
205
+ }
206
+ )
194
207
->thenInvalid ('Relation must have only "include" or "exclude" fields specified. ' )
195
208
->end ()
196
209
->children ()
197
210
->arrayNode ('include ' )
198
- ->beforeNormalization ()->ifString ()->then (function ($ v ) {
199
- return array ($ v );
200
- })->end ()
211
+ ->beforeNormalization ()->ifString ()->then (
212
+ function ($ v ) {
213
+ return [$ v ];
214
+ }
215
+ )->end ()
201
216
->prototype ('scalar ' )->end ()
202
217
->end ()
203
218
->arrayNode ('exclude ' )
204
- ->beforeNormalization ()->ifString ()->then (function ($ v ) {
205
- return array ($ v );
206
- })->end ()
219
+ ->beforeNormalization ()->ifString ()->then (
220
+ function ($ v ) {
221
+ return [$ v ];
222
+ }
223
+ )->end ()
207
224
->prototype ('scalar ' )->end ()
208
225
->end ()
209
226
->end ();
0 commit comments