1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JsonSchema\Schema; |
4
|
|
|
|
5
|
|
|
use JsonSchema\Keyword\AdditionalPropertiesKeyword; |
6
|
|
|
use JsonSchema\Keyword\DependentRequiredKeyword; |
7
|
|
|
use JsonSchema\Keyword\DependentSchemasKeyword; |
8
|
|
|
use JsonSchema\Keyword\MaxPropertiesKeyword; |
9
|
|
|
use JsonSchema\Keyword\MinPropertiesKeyword; |
10
|
|
|
use JsonSchema\Keyword\PropertiesKeyword; |
11
|
|
|
use JsonSchema\Keyword\PropertyNamesKeyword; |
12
|
|
|
use JsonSchema\Keyword\RequiredKeyword; |
13
|
|
|
use JsonSchema\Keyword\TypeKeyword; |
14
|
|
|
use JsonSchema\Keyword\UnevaluatedPropertiesKeyword; |
15
|
|
|
use JsonSchema\Property\PropertyInterface; |
16
|
|
|
|
17
|
|
|
class ObjectSchema extends AbstractSchema |
18
|
|
|
{ |
19
|
28 |
|
public function __construct() |
20
|
|
|
{ |
21
|
28 |
|
parent::__construct( |
22
|
28 |
|
new TypeKeyword('object') |
23
|
|
|
); |
24
|
28 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return static |
28
|
|
|
*/ |
29
|
1 |
|
public function nullable(bool $nullable = true): self |
30
|
|
|
{ |
31
|
1 |
|
if (!$nullable) { |
32
|
1 |
|
return $this->with( |
33
|
1 |
|
new TypeKeyword('object') |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
return $this->with( |
38
|
1 |
|
new TypeKeyword(['object', 'null']) |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param PropertyInterface[]|null $properties |
44
|
|
|
* |
45
|
|
|
* @return static |
46
|
|
|
*/ |
47
|
1 |
|
public function properties(?array $properties): self |
48
|
|
|
{ |
49
|
|
|
return $this |
50
|
1 |
|
->with(new PropertiesKeyword($properties)) |
51
|
1 |
|
->with(new RequiredKeyword($properties)) |
52
|
1 |
|
->with(new DependentRequiredKeyword($properties)) |
53
|
1 |
|
->with(new DependentSchemasKeyword($properties)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param bool|SchemaInterface|null $additionalProperties |
58
|
|
|
* |
59
|
|
|
* @return static |
60
|
|
|
*/ |
61
|
1 |
|
public function additionalProperties($additionalProperties): self |
62
|
|
|
{ |
63
|
1 |
|
return $this->with( |
64
|
1 |
|
new AdditionalPropertiesKeyword($additionalProperties) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param bool|SchemaInterface|null $unevaluatedProperties |
70
|
|
|
* |
71
|
|
|
* @return static |
72
|
|
|
*/ |
73
|
1 |
|
public function unevaluatedProperties($unevaluatedProperties): self |
74
|
|
|
{ |
75
|
1 |
|
return $this->with( |
76
|
1 |
|
new UnevaluatedPropertiesKeyword($unevaluatedProperties) |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return static |
82
|
|
|
*/ |
83
|
1 |
|
public function minProperties(?int $minProperties): self |
84
|
|
|
{ |
85
|
1 |
|
return $this->with( |
86
|
1 |
|
new MinPropertiesKeyword($minProperties) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return static |
92
|
|
|
*/ |
93
|
1 |
|
public function maxProperties(?int $maxProperties): self |
94
|
|
|
{ |
95
|
1 |
|
return $this->with( |
96
|
1 |
|
new MaxPropertiesKeyword($maxProperties) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return static |
102
|
|
|
*/ |
103
|
1 |
|
public function propertyNames(?StringSchema $propertyNames): self |
104
|
|
|
{ |
105
|
1 |
|
return $this->with( |
106
|
1 |
|
new PropertyNamesKeyword($propertyNames) |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|