@@ -100,12 +100,13 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
100
100
if (!$ exception instanceof NotNormalizableValueException) {
101
101
continue ;
102
102
}
103
- $ message = (new Type ($ exception ->getExpectedTypes () ?? []))->message ;
103
+ $ expectedTypes = $ this ->normalizeExpectedTypes ($ exception ->getExpectedTypes ());
104
+ $ message = (new Type ($ expectedTypes ))->message ;
104
105
$ parameters = [];
105
106
if ($ exception ->canUseMessageForUser ()) {
106
107
$ parameters ['hint ' ] = $ exception ->getMessage ();
107
108
}
108
- $ violations ->add (new ConstraintViolation ($ this ->translator ->trans ($ message , ['{{ type }} ' => implode ('| ' , $ exception -> getExpectedTypes () ?? [] )], 'validators ' ), $ message , $ parameters , null , $ exception ->getPath (), null , null , (string ) Type::INVALID_TYPE_ERROR ));
109
+ $ violations ->add (new ConstraintViolation ($ this ->translator ->trans ($ message , ['{{ type }} ' => implode ('| ' , $ expectedTypes )], 'validators ' ), $ message , $ parameters , null , $ exception ->getPath (), null , null , (string ) Type::INVALID_TYPE_ERROR ));
109
110
}
110
111
if (0 !== \count ($ violations )) {
111
112
throw new ValidationException ($ violations );
@@ -114,4 +115,22 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
114
115
115
116
return $ data ;
116
117
}
118
+
119
+ private function normalizeExpectedTypes (?array $ expectedTypes = null ): array
120
+ {
121
+ $ normalizedTypes = [];
122
+
123
+ foreach ($ expectedTypes ?? [] as $ expectedType ) {
124
+ $ normalizedType = $ expectedType ;
125
+
126
+ if (class_exists ($ expectedType ) || interface_exists ($ expectedType )) {
127
+ $ classReflection = new \ReflectionClass ($ expectedType );
128
+ $ normalizedType = $ classReflection ->getShortName ();
129
+ }
130
+
131
+ $ normalizedTypes [] = $ normalizedType ;
132
+ }
133
+
134
+ return $ normalizedTypes ;
135
+ }
117
136
}
0 commit comments