1 | <?php |
||
5 | final class ValidationError implements \JsonSerializable |
||
6 | { |
||
7 | const KEYWORD = 'keyword'; |
||
8 | const PARAMETER = 'parameter'; |
||
9 | const DATA = 'data'; |
||
10 | const DATA_PATH = 'data_path'; |
||
11 | const SCHEMA = 'schema'; |
||
12 | const SCHEMA_PATH = 'schema_path'; |
||
13 | const CAUSE = 'cause'; |
||
14 | const MESSAGE = 'message'; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $message; |
||
20 | |||
21 | /** |
||
22 | * @var string|null |
||
23 | */ |
||
24 | private $interpolatedMessage; |
||
25 | |||
26 | /** |
||
27 | * @var mixed |
||
28 | */ |
||
29 | private $cause; |
||
30 | |||
31 | /** |
||
32 | * @var string[]|null |
||
33 | */ |
||
34 | private $context; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | 154 | private $keyword; |
|
40 | |||
41 | 154 | /** |
|
42 | 154 | * @var mixed |
|
43 | 154 | */ |
|
44 | 154 | private $parameter; |
|
45 | 154 | ||
46 | 154 | /** |
|
47 | * @var mixed |
||
48 | */ |
||
49 | private $data; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | 20 | */ |
|
54 | private $dataPath; |
||
55 | 20 | ||
56 | /** |
||
57 | * @var object |
||
58 | */ |
||
59 | private $schema; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | private $schemaPath; |
||
65 | |||
66 | 20 | public function __construct( |
|
83 | 14 | ||
84 | /** |
||
85 | * Get the human readable error message for this error. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getMessage() |
||
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | 14 | public function getKeyword() |
|
105 | |||
106 | /** |
||
107 | * @return mixed |
||
108 | */ |
||
109 | public function getParameter() |
||
113 | 16 | ||
114 | /** |
||
115 | * @return mixed |
||
116 | */ |
||
117 | public function getData() |
||
121 | |||
122 | 14 | /** |
|
123 | 14 | * @return string |
|
124 | 14 | */ |
|
125 | 14 | public function getDataPath() |
|
129 | |||
130 | /** |
||
131 | * @return object |
||
132 | */ |
||
133 | public function getSchema() |
||
137 | 2 | ||
138 | /** |
||
139 | 2 | * @return string |
|
140 | */ |
||
141 | public function getSchemaPath() |
||
145 | |||
146 | /** |
||
147 | * Get the cause of the error. The cause is either the the value itself |
||
148 | * or the subset of the value that failed validation. For example, the |
||
149 | * cause of a failed minimum constraint would be the number itself, while |
||
150 | * the cause of a failed additionalProperties constraint would be the |
||
151 | * additional properties in the value that are not allowed. |
||
152 | * |
||
153 | * @return mixed |
||
154 | */ |
||
155 | public function getCause() |
||
159 | |||
160 | /** |
||
161 | * @param $cause |
||
162 | * |
||
163 | * @return \League\JsonGuard\ValidationError |
||
164 | */ |
||
165 | public function withCause($cause) |
||
172 | 12 | ||
173 | /** |
||
174 | 12 | * Get the context that applied to the failed assertion. |
|
175 | 12 | * |
|
176 | * @return string[] |
||
177 | */ |
||
178 | public function getContext() |
||
197 | |||
198 | /** |
||
199 | * @return array |
||
200 | */ |
||
201 | public function toArray() |
||
214 | |||
215 | /** |
||
216 | * @inheritdoc |
||
217 | */ |
||
218 | public function jsonSerialize() |
||
222 | |||
223 | /** |
||
224 | * Interpolate the context values into the message placeholders. |
||
225 | * |
||
226 | * @param string $message |
||
227 | * @param array $context |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | private function interpolate($message, array $context = []) |
||
240 | } |
||
241 |