|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the OpenapiBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Niels Nijens <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Nijens\OpenapiBundle\ExceptionHandling\Exception; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default violation implementation as part of {@see InvalidRequestBodyProblemException}. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Niels Nijens <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class Violation implements ViolationInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $propertyPath; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $message; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $constraint; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(string $propertyPath, string $message, string $constraint) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->propertyPath = $propertyPath; |
|
39
|
|
|
$this->message = $message; |
|
40
|
|
|
$this->constraint = $constraint; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getPropertyPath(): string |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->propertyPath; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getMessage(): string |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->message; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getConstraint(): string |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->constraint; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function jsonSerialize(): array |
|
59
|
|
|
{ |
|
60
|
|
|
return [ |
|
61
|
|
|
'property' => $this->getPropertyPath(), |
|
62
|
|
|
'message' => $this->getMessage(), |
|
63
|
|
|
'constraint' => $this->getConstraint(), |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function fromArray(array $violation): self |
|
68
|
|
|
{ |
|
69
|
|
|
return new static( |
|
70
|
|
|
$violation['property'] ?? $violation['propertyPath'] ?? '', |
|
71
|
|
|
$violation['message'] ?? '', |
|
72
|
|
|
$violation['constraint'] ?? '' |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|