1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the OpenapiBundle package. |
7
|
|
|
* |
8
|
|
|
* (c) Niels Nijens <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Nijens\OpenapiBundle\ExceptionHandling\Exception; |
15
|
|
|
|
16
|
|
|
use Throwable; |
17
|
|
|
|
18
|
|
|
final class InvalidRequestBodyProblemException extends ProblemException |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ViolationInterface[] |
22
|
|
|
*/ |
23
|
|
|
private $violations; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
string $typeUri, |
27
|
|
|
string $title, |
28
|
|
|
int $statusCode, |
29
|
|
|
string $message = '', |
30
|
|
|
Throwable $previous = null, |
31
|
|
|
?string $instanceUri = null, |
32
|
|
|
array $headers = [], |
33
|
|
|
array $violations = [] |
34
|
|
|
) { |
35
|
|
|
parent::__construct($typeUri, $title, $statusCode, $message, $previous, $instanceUri, $headers); |
36
|
|
|
|
37
|
|
|
$this->violations = $violations; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getViolations(): array |
41
|
|
|
{ |
42
|
|
|
return $this->violations; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ViolationInterface[] $violations |
47
|
|
|
*/ |
48
|
|
|
public function withViolations(array $violations): ProblemExceptionInterface |
49
|
|
|
{ |
50
|
|
|
$exception = $this->clone(); |
51
|
|
|
$exception->violations = $violations; |
52
|
|
|
|
53
|
|
|
return $exception; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function jsonSerialize(): array |
57
|
|
|
{ |
58
|
|
|
$data = parent::jsonSerialize(); |
59
|
|
|
$data['violations'] = $this->getViolations(); |
60
|
|
|
|
61
|
|
|
return $data; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function clone() |
65
|
|
|
{ |
66
|
|
|
$clone = parent::clone(); |
67
|
|
|
$clone->violations = $this->violations; |
68
|
|
|
|
69
|
|
|
return $clone; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|