14
14
namespace ApiPlatform \Symfony \Validator \State ;
15
15
16
16
use ApiPlatform \Metadata \Operation ;
17
+ use ApiPlatform \State \ParameterNotFound ;
17
18
use ApiPlatform \State \ProviderInterface ;
18
19
use ApiPlatform \State \Util \ParameterParserTrait ;
19
20
use ApiPlatform \Validator \Exception \ValidationException ;
@@ -39,19 +40,27 @@ public function __construct(
39
40
40
41
public function provide (Operation $ operation , array $ uriVariables = [], array $ context = []): object |array |null
41
42
{
42
- if (!($ request = $ context ['request ' ]) instanceof Request || false === $ operation -> getQueryParameterValidationEnabled () ) {
43
+ if (!($ request = $ context ['request ' ]) instanceof Request) {
43
44
return $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
44
45
}
45
46
46
47
$ operation = $ request ->attributes ->get ('_api_operation ' ) ?? $ operation ;
48
+ if (!($ operation ->getQueryParameterValidationEnabled () ?? true )) {
49
+ return $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
50
+ }
51
+
47
52
$ constraintViolationList = new ConstraintViolationList ();
48
53
foreach ($ operation ->getParameters () ?? [] as $ parameter ) {
49
54
if (!$ constraints = $ parameter ->getConstraints ()) {
50
55
continue ;
51
56
}
52
57
53
58
$ key = $ parameter ->getKey ();
54
- $ value = $ parameter ->getValue ()[$ key ] ?? null ;
59
+ $ value = $ parameter ->getValue ();
60
+ if ($ value instanceof ParameterNotFound) {
61
+ $ value = null ;
62
+ }
63
+
55
64
$ violations = $ this ->validator ->validate ($ value , $ constraints );
56
65
foreach ($ violations as $ violation ) {
57
66
$ constraintViolationList ->add (new ConstraintViolation (
0 commit comments