1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JsonSchema\Schema; |
4
|
|
|
|
5
|
|
|
use JsonSchema\Keyword\AdditionalItemsKeyword; |
6
|
|
|
use JsonSchema\Keyword\ContainsKeyword; |
7
|
|
|
use JsonSchema\Keyword\ItemsKeyword; |
8
|
|
|
use JsonSchema\Keyword\MaxContainsKeyword; |
9
|
|
|
use JsonSchema\Keyword\MaxItemsKeyword; |
10
|
|
|
use JsonSchema\Keyword\MinContainsKeyword; |
11
|
|
|
use JsonSchema\Keyword\MinItemsKeyword; |
12
|
|
|
use JsonSchema\Keyword\TypeKeyword; |
13
|
|
|
use JsonSchema\Keyword\UnevaluatedItemsKeyword; |
14
|
|
|
use JsonSchema\Keyword\UniqueItemsKeyword; |
15
|
|
|
|
16
|
|
|
class ArraySchema extends AbstractSchema |
17
|
|
|
{ |
18
|
31 |
|
public function __construct() |
19
|
|
|
{ |
20
|
31 |
|
parent::__construct( |
21
|
31 |
|
new TypeKeyword('array') |
22
|
|
|
); |
23
|
31 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return static |
27
|
|
|
*/ |
28
|
1 |
|
public function nullable(bool $nullable = true): self |
29
|
|
|
{ |
30
|
1 |
|
if (!$nullable) { |
31
|
1 |
|
return $this->with( |
32
|
1 |
|
new TypeKeyword('array') |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
return $this->with( |
37
|
1 |
|
new TypeKeyword(['array', 'null']) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param SchemaInterface|SchemaInterface[]|null $items |
43
|
|
|
* |
44
|
|
|
* @return static |
45
|
|
|
*/ |
46
|
1 |
|
public function items($items): self |
47
|
|
|
{ |
48
|
1 |
|
return $this->with( |
49
|
1 |
|
new ItemsKeyword($items) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return static |
55
|
|
|
*/ |
56
|
1 |
|
public function contains(?SchemaInterface $contains): self |
57
|
|
|
{ |
58
|
1 |
|
return $this->with( |
59
|
1 |
|
new ContainsKeyword($contains) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param bool|SchemaInterface|null $additionalItems |
65
|
|
|
* |
66
|
|
|
* @return static |
67
|
|
|
*/ |
68
|
1 |
|
public function additionalItems($additionalItems): self |
69
|
|
|
{ |
70
|
1 |
|
return $this->with( |
71
|
1 |
|
new AdditionalItemsKeyword($additionalItems) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param bool|SchemaInterface|null $unevaluatedItems |
77
|
|
|
* |
78
|
|
|
* @return static |
79
|
|
|
*/ |
80
|
1 |
|
public function unevaluatedItems($unevaluatedItems): self |
81
|
|
|
{ |
82
|
1 |
|
return $this->with( |
83
|
1 |
|
new UnevaluatedItemsKeyword($unevaluatedItems) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return static |
89
|
|
|
*/ |
90
|
1 |
|
public function minItems(?int $minItems): self |
91
|
|
|
{ |
92
|
1 |
|
return $this->with( |
93
|
1 |
|
new MinItemsKeyword($minItems) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return static |
99
|
|
|
*/ |
100
|
1 |
|
public function maxItems(?int $maxItems): self |
101
|
|
|
{ |
102
|
1 |
|
return $this->with( |
103
|
1 |
|
new MaxItemsKeyword($maxItems) |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return static |
109
|
|
|
*/ |
110
|
1 |
|
public function minContains(?int $minContains): self |
111
|
|
|
{ |
112
|
1 |
|
return $this->with( |
113
|
1 |
|
new MinContainsKeyword($minContains) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return static |
119
|
|
|
*/ |
120
|
1 |
|
public function maxContains(?int $maxContains): self |
121
|
|
|
{ |
122
|
1 |
|
return $this->with( |
123
|
1 |
|
new MaxContainsKeyword($maxContains) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return static |
129
|
|
|
*/ |
130
|
1 |
|
public function uniqueItems(?bool $uniqueItems): self |
131
|
|
|
{ |
132
|
1 |
|
return $this->with( |
133
|
1 |
|
new UniqueItemsKeyword($uniqueItems) |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|