@@ -277,16 +277,19 @@ private function _simpUtilsGetValidator($item, $attr, $call_type): ?Closure {
277
277
$ attr_instance = $ attr ->newInstance ();
278
278
$ valid = $ attr_instance ?->valid ?? false ;
279
279
280
+ $ t = null ;
281
+ if ($ item instanceof ReflectionProperty) {
282
+ $ t = $ item ?->getType();
283
+ } else if ($ item instanceof ReflectionMethod) {
284
+ $ param = $ item ->getParameters ()[0 ] ?? null ;
285
+ /** @var \ReflectionParameter $param */
286
+ $ t = $ param ?->getType();
287
+ }
288
+ $ _method = $ t && $ t ->allowsNull ()?'whenNullAllowed ' :'process ' ;
289
+
280
290
if ($ valid === true &&
281
291
$ validators_enabled === CommonMemoryCacheIndex::PROPERTY_VALIDATOR_ENABLED
282
292
) {
283
- if ($ item instanceof ReflectionProperty) {
284
- $ t = $ item ?->getType();
285
- } else if ($ item instanceof ReflectionMethod) {
286
- $ param = $ item ->getParameters ()[0 ] ?? null ;
287
- /** @var \ReflectionParameter $param */
288
- $ t = $ param ?->getType();
289
- }
290
293
if ($ t instanceof ReflectionUnionType) {
291
294
// NOTE Union-Types are not supported due to unpredictable nature
292
295
return null ; // @codeCoverageIgnore
@@ -304,18 +307,18 @@ private function _simpUtilsGetValidator($item, $attr, $call_type): ?Closure {
304
307
}
305
308
}
306
309
if (!empty ($ validators [$ class ]) && PHP ::isClass ($ validators [$ class ])) {
307
- $ closure = Closure::fromCallable ([$ validators [$ class ], ' process ' ]);
310
+ $ closure = Closure::fromCallable ([$ validators [$ class ], $ _method ]);
308
311
return $ closure ;
309
312
}
310
313
}
311
314
} else if (is_string ($ valid ) &&
312
315
$ validators_enabled >= CommonMemoryCacheIndex::PROPERTY_VALIDATOR_LIMITED
313
316
) {
314
317
if (!empty ($ validators [$ valid ])) {
315
- $ closure = Closure::fromCallable ([$ validators [$ valid ], ' process ' ]);
318
+ $ closure = Closure::fromCallable ([$ validators [$ valid ], $ _method ]);
316
319
return $ closure ;
317
320
} else if (PHP ::isClass ($ valid )) {
318
- $ closure = Closure::fromCallable ([$ valid , ' process ' ]);
321
+ $ closure = Closure::fromCallable ([$ valid , $ _method ]);
319
322
return $ closure ;
320
323
}
321
324
}
0 commit comments