1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright 2016 Johannes M. Schmitt <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace JMS\Serializer\Handler; |
20
|
|
|
|
21
|
|
|
use JMS\Serializer\GraphNavigatorInterface; |
22
|
|
|
use JMS\Serializer\JsonSerializationVisitor; |
23
|
|
|
use JMS\Serializer\SerializationContext; |
24
|
|
|
use JMS\Serializer\XmlSerializationVisitor; |
25
|
|
|
use JMS\Serializer\YamlSerializationVisitor; |
|
|
|
|
26
|
|
|
use Symfony\Component\Validator\ConstraintViolation; |
27
|
|
|
use Symfony\Component\Validator\ConstraintViolationList; |
28
|
|
|
|
29
|
|
|
final class ConstraintViolationHandler implements SubscribingHandlerInterface |
30
|
|
|
{ |
31
|
258 |
|
public static function getSubscribingMethods() |
32
|
|
|
{ |
33
|
258 |
|
$methods = array(); |
34
|
258 |
|
$formats = array('xml', 'json'); |
35
|
258 |
|
$types = array('Symfony\Component\Validator\ConstraintViolationList' => 'serializeList', 'Symfony\Component\Validator\ConstraintViolation' => 'serializeViolation'); |
36
|
|
|
|
37
|
258 |
|
foreach ($types as $type => $method) { |
38
|
258 |
|
foreach ($formats as $format) { |
39
|
258 |
|
$methods[] = array( |
40
|
258 |
|
'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION, |
41
|
258 |
|
'type' => $type, |
42
|
258 |
|
'format' => $format, |
43
|
258 |
|
'method' => $method . 'To' . $format, |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
258 |
|
return $methods; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function serializeListToXml(XmlSerializationVisitor $visitor, ConstraintViolationList $list, array $type) |
|
|
|
|
52
|
|
|
{ |
53
|
1 |
|
$currentNode = $visitor->getCurrentNode(); |
54
|
1 |
|
if (!$currentNode) { |
55
|
1 |
|
$visitor->createRoot(); |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
foreach ($list as $violation) { |
59
|
1 |
|
$this->serializeViolationToXml($visitor, $violation); |
60
|
|
|
} |
61
|
1 |
|
} |
62
|
|
|
|
63
|
1 |
|
public function serializeListToJson(JsonSerializationVisitor $visitor, ConstraintViolationList $list, array $type, SerializationContext $context) |
|
|
|
|
64
|
|
|
{ |
65
|
1 |
|
return $visitor->visitArray(iterator_to_array($list), $type); |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
public function serializeViolationToXml(XmlSerializationVisitor $visitor, ConstraintViolation $violation, array $type = null) |
|
|
|
|
69
|
|
|
{ |
70
|
2 |
|
$violationNode = $visitor->getDocument()->createElement('violation'); |
71
|
|
|
|
72
|
2 |
|
$parent = $visitor->getCurrentNode(); |
73
|
2 |
|
if (!$parent) { |
74
|
1 |
|
$visitor->setCurrentAndRootNode($violationNode); |
75
|
|
|
} else { |
76
|
1 |
|
$parent->appendChild($violationNode); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
$violationNode->setAttribute('property_path', $violation->getPropertyPath()); |
80
|
2 |
|
$violationNode->appendChild($messageNode = $visitor->getDocument()->createElement('message')); |
81
|
|
|
|
82
|
2 |
|
$messageNode->appendChild($visitor->getDocument()->createCDATASection($violation->getMessage())); |
83
|
2 |
|
} |
84
|
|
|
|
85
|
2 |
|
public function serializeViolationToJson(JsonSerializationVisitor $visitor, ConstraintViolation $violation, array $type = null) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$data = array( |
88
|
2 |
|
'property_path' => $violation->getPropertyPath(), |
89
|
2 |
|
'message' => $violation->getMessage() |
90
|
|
|
); |
91
|
|
|
|
92
|
2 |
|
return $data; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths