@@ -152,15 +152,12 @@ protected function buildValidationTree(ValidationNode $rootObject, array $fields
152
152
153
153
if (isset ($ validation ['cascade ' ]) && isset ($ inputData [$ property ])) {
154
154
$ groups = $ validation ['cascade ' ];
155
-
156
- if ($ arg ['type ' ] instanceof Closure) {
157
- $ arg ['type ' ] = $ arg ['type ' ]();
158
- }
155
+ $ argType = $ this ->unclosure ($ arg ['type ' ]);
159
156
160
157
/** @var ObjectType|InputObjectType $type */
161
- $ type = Type::getNamedType ($ arg [ ' type ' ] );
158
+ $ type = Type::getNamedType ($ argType );
162
159
163
- if (static ::isListOfType ($ arg [ ' type ' ] )) {
160
+ if (static ::isListOfType ($ argType )) {
164
161
$ rootObject ->$ property = $ this ->createCollectionNode ($ inputData [$ property ], $ type , $ rootObject );
165
162
} else {
166
163
$ rootObject ->$ property = $ this ->createObjectNode ($ inputData [$ property ], $ type , $ rootObject );
@@ -273,10 +270,7 @@ private function applyClassValidation(ObjectMetadata $metadata, array $rules): v
273
270
$ metadata ->addConstraints ($ linkedMetadata ->getConstraints ());
274
271
break ;
275
272
case 'constraints ' :
276
- if ($ value instanceof Closure) {
277
- $ value = $ value ();
278
- }
279
- foreach ($ value as $ constraint ) {
273
+ foreach ($ this ->unclosure ($ value ) as $ constraint ) {
280
274
if ($ constraint instanceof Constraint) {
281
275
$ metadata ->addConstraint ($ constraint );
282
276
} elseif ($ constraint instanceof GroupSequence) {
@@ -311,6 +305,20 @@ public static function normalizeConfig($config): array
311
305
return $ config ;
312
306
}
313
307
308
+ /**
309
+ * @param mixed $value
310
+ *
311
+ * @return mixed
312
+ */
313
+ private function unclosure ($ value )
314
+ {
315
+ if ($ value instanceof Closure) {
316
+ return $ value ();
317
+ }
318
+
319
+ return $ value ;
320
+ }
321
+
314
322
/**
315
323
* @param string|array|null $groups
316
324
*
0 commit comments