@@ -53,40 +53,22 @@ public function getConfigTreeBuilder(): TreeBuilder
53
53
->scalarNode ('auto_generate_proxy_classes ' )
54
54
->defaultValue (ODMConfiguration::AUTOGENERATE_EVAL )
55
55
->beforeNormalization ()
56
- ->always (static function ($ v ) {
57
- if ($ v === false ) {
58
- return ODMConfiguration::AUTOGENERATE_EVAL ;
59
- }
60
-
61
- if ($ v === true ) {
62
- return ODMConfiguration::AUTOGENERATE_FILE_NOT_EXISTS ;
63
- }
64
-
65
- return $ v ;
66
- })
56
+ ->ifTrue ()->then (static fn ($ v ) => ODMConfiguration::AUTOGENERATE_FILE_NOT_EXISTS )
57
+ ->ifFalse ()->then (static fn ($ v ) => ODMConfiguration::AUTOGENERATE_NEVER )
67
58
->end ()
68
59
->end ()
69
60
->scalarNode ('hydrator_namespace ' )->defaultValue ('Hydrators ' )->end ()
70
61
->scalarNode ('hydrator_dir ' )->defaultValue ('%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators ' )->end ()
71
62
->scalarNode ('auto_generate_hydrator_classes ' )
72
63
->defaultValue (ODMConfiguration::AUTOGENERATE_NEVER )
73
64
->beforeNormalization ()
74
- ->always (static function ($ v ) {
75
- if ($ v === false ) {
76
- return ODMConfiguration::AUTOGENERATE_NEVER ;
77
- }
78
-
79
- if ($ v === true ) {
80
- return ODMConfiguration::AUTOGENERATE_ALWAYS ;
81
- }
82
-
83
- return $ v ;
84
- })
65
+ ->ifTrue ()->then (static fn ($ v ) => ODMConfiguration::AUTOGENERATE_ALWAYS )
66
+ ->ifFalse ()->then (static fn ($ v ) => ODMConfiguration::AUTOGENERATE_NEVER )
85
67
->end ()
86
68
->end ()
87
69
->scalarNode ('persistent_collection_namespace ' )->defaultValue ('PersistentCollections ' )->end ()
88
70
->scalarNode ('persistent_collection_dir ' )->defaultValue ('%kernel.cache_dir%/doctrine/odm/mongodb/PersistentCollections ' )->end ()
89
- ->scalarNode ('auto_generate_persistent_collection_classes ' )->defaultValue (ODMConfiguration::AUTOGENERATE_NEVER )->end ()
71
+ ->integerNode ('auto_generate_persistent_collection_classes ' )->defaultValue (ODMConfiguration::AUTOGENERATE_NEVER )->end ()
90
72
->scalarNode ('default_document_manager ' )->end ()
91
73
->scalarNode ('default_connection ' )->end ()
92
74
->scalarNode ('default_database ' )->defaultValue ('default ' )->end ()
@@ -149,20 +131,15 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void
149
131
->useAttributeAsKey ('name ' )
150
132
->prototype ('array ' )
151
133
->fixXmlConfig ('parameter ' )
152
- ->beforeNormalization ()
153
- ->ifString ()
154
- ->then (static function ($ v ) {
155
- return ['class ' => $ v ];
156
- })
157
- ->end ()
134
+ ->acceptAndWrap (['string ' ], 'class ' )
158
135
->beforeNormalization ()
159
136
// The content of the XML node is returned as the "value" key so we need to rename it
160
- ->ifTrue (static function ($ v ): bool {
161
- return is_array ($ v ) && isset ($ v ['value ' ]);
162
- })
137
+ ->ifArray ()
163
138
->then (static function ($ v ) {
164
- $ v ['class ' ] = $ v ['value ' ];
165
- unset($ v ['value ' ]);
139
+ if (isset ($ v ['value ' ]) && ! isset ($ v ['class ' ])) {
140
+ $ v ['class ' ] = $ v ['value ' ];
141
+ unset($ v ['value ' ]);
142
+ }
166
143
167
144
return $ v ;
168
145
})
@@ -175,13 +152,15 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void
175
152
->useAttributeAsKey ('name ' )
176
153
->prototype ('variable ' )
177
154
->beforeNormalization ()
178
- // Detect JSON object and array syntax (for XML)
179
- ->ifTrue (static function ($ v ): bool {
180
- return is_string ($ v ) && (preg_match ('/\[.*\]/ ' , $ v ) || preg_match ('/\{.*\}/ ' , $ v ));
181
- })
182
- // Decode objects to associative arrays for consistency with YAML
155
+ ->ifString ()
183
156
->then (static function ($ v ) {
184
- return json_decode ($ v , true );
157
+ // Detect JSON object and array syntax (for XML)
158
+ // Decode objects to associative arrays for consistency with YAML
159
+ if (is_string ($ v ) && (preg_match ('/\[.*\]/ ' , $ v ) || preg_match ('/\{.*\}/ ' , $ v ))) {
160
+ return json_decode ($ v , true );
161
+ }
162
+
163
+ return $ v ;
185
164
})
186
165
->end ()
187
166
->end ()
@@ -191,12 +170,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void
191
170
->end ()
192
171
->arrayNode ('metadata_cache_driver ' )
193
172
->addDefaultsIfNotSet ()
194
- ->beforeNormalization ()
195
- ->ifString ()
196
- ->then (static function ($ v ) {
197
- return ['type ' => $ v ];
198
- })
199
- ->end ()
173
+ ->acceptAndWrap (['string ' ], 'type ' )
200
174
->children ()
201
175
->scalarNode ('type ' )->defaultValue ('array ' )->end ()
202
176
->scalarNode ('class ' )->end ()
@@ -214,12 +188,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void
214
188
->arrayNode ('mappings ' )
215
189
->useAttributeAsKey ('name ' )
216
190
->prototype ('array ' )
217
- ->beforeNormalization ()
218
- ->ifString ()
219
- ->then (static function ($ v ) {
220
- return ['type ' => $ v ];
221
- })
222
- ->end ()
191
+ ->acceptAndWrap (['string ' ], 'type ' )
223
192
->treatNullLike ([])
224
193
->treatFalseLike (['mapping ' => false ])
225
194
->performNoDeepMerging ()
@@ -276,17 +245,18 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void
276
245
->performNoDeepMerging ()
277
246
->prototype ('array ' )
278
247
->beforeNormalization ()
279
- // Handle readPreferenceTag XML nodes
280
- ->ifTrue (static function ($ v ): bool {
281
- return isset ($ v ['readPreferenceTag ' ]);
282
- })
248
+ ->ifArray ()
283
249
->then (static function ($ v ) {
284
250
// Equivalent of fixXmlConfig() for inner node
285
251
if (isset ($ v ['readPreferenceTag ' ]['name ' ])) {
286
- $ v ['readPreferenceTag ' ] = [$ v ['readPreferenceTag ' ]];
252
+ return [$ v ['readPreferenceTag ' ]];
253
+ }
254
+
255
+ if (isset ($ v ['readPreferenceTag ' ])) {
256
+ return $ v ['readPreferenceTag ' ];
287
257
}
288
258
289
- return $ v[ ' readPreferenceTag ' ] ;
259
+ return $ v ;
290
260
})
291
261
->end ()
292
262
->useAttributeAsKey ('name ' )
@@ -323,11 +293,11 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void
323
293
->integerNode ('wTimeoutMS ' )->end ()
324
294
->end ()
325
295
->validate ()
326
- ->ifTrue (static function ($ v ): bool {
327
- return count ($ v ['readPreferenceTags ' ]) === 0 ;
328
- })
296
+ ->ifArray ()
329
297
->then (static function ($ v ) {
330
- unset($ v ['readPreferenceTags ' ]);
298
+ if (! $ v ['readPreferenceTags ' ]) {
299
+ unset($ v ['readPreferenceTags ' ]);
300
+ }
331
301
332
302
return $ v ;
333
303
})
@@ -399,16 +369,12 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void
399
369
->arrayNode ('encryptedFieldsMap ' )
400
370
->useAttributeAsKey ('name ' , false )
401
371
->beforeNormalization ()
402
- ->always (static function ($ v ) {
403
- // Create a PHP array representation of the Extended BSON that is later
404
- // converted to JSON string to create a BSON document from this JSON.
405
- // This lets the DI dumper transform the parameters in the string and dump it.
406
- if (is_string ($ v )) {
407
- return json_decode ($ v , true , 512 , JSON_THROW_ON_ERROR );
408
- }
409
-
410
- return $ v ;
411
- })->end ()
372
+ ->ifString ()
373
+ // Create a PHP array representation of the Extended BSON that is later
374
+ // converted to JSON string to create a BSON document from this JSON.
375
+ // This lets the DI dumper transform the parameters in the string and dump it.
376
+ ->then (static fn ($ v ) => json_decode ($ v , true , 512 , JSON_THROW_ON_ERROR ))
377
+ ->end ()
412
378
->prototype ('array ' )
413
379
->children ()
414
380
->arrayNode ('fields ' )
@@ -440,10 +406,7 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void
440
406
->booleanNode ('mongocryptdBypassSpawn ' )->end ()
441
407
->scalarNode ('mongocryptdSpawnPath ' )->end ()
442
408
->arrayNode ('mongocryptdSpawnArgs ' )
443
- ->beforeNormalization ()
444
- ->ifString ()
445
- ->then (static fn ($ v ) => [$ v ])
446
- ->end ()
409
+ ->acceptAndWrap (['string ' ])
447
410
->prototype ('scalar ' )->cannotBeEmpty ()->end ()
448
411
->end ()
449
412
->scalarNode ('cryptSharedLibPath ' )->end ()
@@ -517,10 +480,7 @@ private function addTypesSection(ArrayNodeDefinition $rootNode): void
517
480
->arrayNode ('types ' )
518
481
->useAttributeAsKey ('name ' )
519
482
->prototype ('array ' )
520
- ->beforeNormalization ()
521
- ->ifString ()
522
- ->then (static fn ($ v ) => ['class ' => $ v ])
523
- ->end ()
483
+ ->acceptAndWrap (['string ' ], 'class ' )
524
484
->children ()
525
485
->scalarNode ('class ' )->isRequired ()->end ()
526
486
->end ()
0 commit comments