@@ -65,8 +65,54 @@ public function hasCacheableSupportsMethod(): bool
6565 return true ;
6666 }
6767
68+ /**
69+ * return string[].
70+ */
71+ protected function getViolations (ConstraintViolationListInterface $ constraintViolationList ): array
72+ {
73+ $ violations = [];
74+
75+ foreach ($ constraintViolationList as $ violation ) {
76+ $ class = \is_object ($ root = $ violation ->getRoot ()) ? $ root ::class : null ;
77+
78+ if ($ this ->nameConverter instanceof AdvancedNameConverterInterface) {
79+ $ propertyPath = $ this ->nameConverter ->normalize ($ violation ->getPropertyPath (), $ class , static ::FORMAT );
80+ } elseif ($ this ->nameConverter instanceof NameConverterInterface) {
81+ $ propertyPath = $ this ->nameConverter ->normalize ($ violation ->getPropertyPath ());
82+ } else {
83+ $ propertyPath = $ violation ->getPropertyPath ();
84+ }
85+
86+ $ violationData = [
87+ 'propertyPath ' => $ propertyPath ,
88+ 'message ' => $ violation ->getMessage (),
89+ 'code ' => $ violation ->getCode (),
90+ ];
91+
92+ if ($ hint = $ violation ->getParameters ()['hint ' ] ?? false ) {
93+ $ violationData ['hint ' ] = $ hint ;
94+ }
95+
96+ $ constraint = $ violation instanceof ConstraintViolation ? $ violation ->getConstraint () : null ;
97+ if (
98+ [] !== $ this ->serializePayloadFields
99+ && $ constraint
100+ && $ constraint ->payload
101+ // If some fields are whitelisted, only them are added
102+ && $ payloadFields = null === $ this ->serializePayloadFields ? $ constraint ->payload : array_intersect_key ($ constraint ->payload , $ this ->serializePayloadFields )
103+ ) {
104+ $ violationData ['payload ' ] = $ payloadFields ;
105+ }
106+
107+ $ violations [] = $ violationData ;
108+ }
109+
110+ return $ violations ;
111+ }
112+
68113 protected function getMessagesAndViolations (ConstraintViolationListInterface $ constraintViolationList ): array
69114 {
115+ trigger_deprecation ('api-platform ' , '3.2 ' , sprintf ('"%s::%s" will be removed in 4.0, use "%1$s::%s ' , __CLASS__ , __METHOD__ , 'getViolations ' ));
70116 $ violations = $ messages = [];
71117
72118 foreach ($ constraintViolationList as $ violation ) {
0 commit comments