|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\JsonGuard\Exception; |
|
4
|
|
|
|
|
5
|
|
|
final class InvalidSchemaException extends \RuntimeException |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var string |
|
9
|
|
|
*/ |
|
10
|
|
|
private $keyword; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
private $pointer; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $message |
|
19
|
|
|
* @param string $keyword |
|
20
|
|
|
* @param string $pointer |
|
21
|
|
|
*/ |
|
22
|
104 |
|
public function __construct($message, $keyword, $pointer) |
|
23
|
|
|
{ |
|
24
|
104 |
|
parent::__construct($message); |
|
25
|
|
|
|
|
26
|
104 |
|
$this->keyword = $keyword; |
|
27
|
104 |
|
$this->pointer = $pointer; |
|
28
|
104 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $actualType |
|
32
|
|
|
* @param array $allowedTypes |
|
33
|
|
|
* @param string $keyword |
|
34
|
|
|
* @param string $pointer |
|
35
|
|
|
* |
|
36
|
|
|
* @return \League\JsonGuard\Exception\InvalidSchemaException |
|
37
|
|
|
*/ |
|
38
|
58 |
|
public static function invalidParameterType($actualType, array $allowedTypes, $keyword, $pointer) |
|
39
|
|
|
{ |
|
40
|
58 |
|
$message = sprintf( |
|
41
|
58 |
|
'Value has type "%s" but must be one of: "%s"', |
|
42
|
58 |
|
$actualType, |
|
43
|
58 |
|
implode(', ', $allowedTypes) |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
58 |
|
return new self($message, $keyword, $pointer); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $actualParameter |
|
51
|
|
|
* @param array $allowedParameter |
|
52
|
|
|
* @param string $keyword |
|
53
|
|
|
* @param string $pointer |
|
54
|
|
|
* |
|
55
|
|
|
* @return \League\JsonGuard\Exception\InvalidSchemaException |
|
56
|
|
|
*/ |
|
57
|
18 |
|
public static function invalidParameter($actualParameter, array $allowedParameter, $keyword, $pointer) |
|
58
|
|
|
{ |
|
59
|
18 |
|
$message = sprintf( |
|
60
|
18 |
|
'Value is "%s" but must be one of: "%s"', |
|
61
|
18 |
|
$actualParameter, |
|
62
|
18 |
|
implode(', ', $allowedParameter) |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
18 |
|
return new self($message, $keyword, $pointer); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param integer $value |
|
70
|
|
|
* @param string $keyword |
|
71
|
|
|
* @param string $pointer |
|
72
|
|
|
* |
|
73
|
|
|
* @return \League\JsonGuard\Exception\InvalidSchemaException |
|
74
|
|
|
*/ |
|
75
|
18 |
|
public static function negativeValue($value, $keyword, $pointer) |
|
76
|
|
|
{ |
|
77
|
18 |
|
$message = sprintf( |
|
78
|
18 |
|
'Integer value "%d" must be greater than, or equal to, 0', |
|
79
|
18 |
|
$value |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
18 |
|
return new self($message, $keyword, $pointer); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $keyword |
|
87
|
|
|
* @param string $pointer |
|
88
|
|
|
* |
|
89
|
|
|
* @return \League\JsonGuard\Exception\InvalidSchemaException |
|
90
|
|
|
*/ |
|
91
|
8 |
|
public static function emptyArray($keyword, $pointer) |
|
92
|
|
|
{ |
|
93
|
8 |
|
return new self( |
|
94
|
8 |
|
'Array must have at least one element', |
|
95
|
8 |
|
$keyword, |
|
96
|
8 |
|
$pointer |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param string $property |
|
102
|
|
|
* @param string $keyword |
|
103
|
|
|
* @param string $pointer |
|
104
|
|
|
* |
|
105
|
|
|
* @return \League\JsonGuard\Exception\InvalidSchemaException |
|
106
|
|
|
*/ |
|
107
|
|
|
public static function missingProperty($property, $keyword, $pointer) |
|
108
|
|
|
{ |
|
109
|
|
|
$message = sprintf( |
|
110
|
|
|
'The schema must contain the property %s', |
|
111
|
|
|
$property |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
return new self($message, $keyword, $pointer); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return string |
|
119
|
|
|
*/ |
|
120
|
10 |
|
public function getKeyword() |
|
121
|
|
|
{ |
|
122
|
10 |
|
return $this->keyword; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
10 |
|
public function getPointer() |
|
129
|
|
|
{ |
|
130
|
10 |
|
return $this->pointer; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|