Skip to content

Commit 522fe71

Browse files
committed
Fix last comments
1 parent 6ecb745 commit 522fe71

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,24 @@ public function normalize($object, $format = null, array $context = array())
3232
$violations = array();
3333
$messages = array();
3434
foreach ($object as $violation) {
35-
$violations[] = array(
36-
'propertyPath' => $violation->getPropertyPath(),
37-
'type' => sprintf('urn:uuid:%s', $violation->getCode()),
35+
$propertyPath = $violation->getPropertyPath();
36+
37+
$violationEntry = array(
38+
'propertyPath' => $propertyPath,
3839
'title' => $violation->getMessage(),
3940
);
40-
$propertyPath = $violation->getPropertyPath();
41+
if (null !== $code = $violation->getCode()) {
42+
$violationEntry['type'] = sprintf('urn:uuid:%s', $code);
43+
}
44+
45+
$violations[] = $violationEntry;
46+
4147
$prefix = $propertyPath ? sprintf('%s: ', $propertyPath) : '';
4248
$messages[] = $prefix.$violation->getMessage();
4349
}
4450

4551
$result = array(
46-
'type' => $context['type'] ?? 'https://symfony.com/validation-error',
52+
'type' => $context['type'] ?? 'https://symfony.com/errors/validation',
4753
'title' => $context['title'] ?? 'Validation Failed',
4854
);
4955
if (isset($context['status'])) {

src/Symfony/Component/Serializer/Tests/Normalizer/ConstraintViolationListNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ public function testNormalize()
4343
));
4444

4545
$expected = array(
46-
'type' => 'https://symfony.com/validation-error',
46+
'type' => 'https://symfony.com/errors/validation',
4747
'title' => 'Validation Failed',
4848
'detail' => 'd: a
4949
4: 1',
5050
'violations' => array(
5151
array(
5252
'propertyPath' => 'd',
53-
'type' => 'urn:uuid:f',
5453
'title' => 'a',
54+
'type' => 'urn:uuid:f',
5555
),
5656
array(
5757
'propertyPath' => '4',
58-
'type' => 'urn:uuid:6',
5958
'title' => '1',
59+
'type' => 'urn:uuid:6',
6060
),
6161
),
6262
);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy