|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Smoren\Validator\Rules; |
|
6
|
|
|
|
|
7
|
|
|
use Smoren\Validator\Factories\Checks\ContainerCheckFactory; |
|
8
|
|
|
use Smoren\Validator\Interfaces\MixedRuleInterface; |
|
9
|
|
|
use Smoren\Validator\Interfaces\ContainerRuleInterface; |
|
10
|
|
|
use Smoren\Validator\Interfaces\IntegerRuleInterface; |
|
11
|
|
|
|
|
12
|
|
|
final class ContainerRule extends MixedRule implements ContainerRuleInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* ContainerRule constructor. |
|
16
|
|
|
*/ |
|
17
|
69 |
|
public function __construct(string $name) |
|
18
|
|
|
{ |
|
19
|
69 |
|
parent::__construct($name); |
|
20
|
69 |
|
$this->check(ContainerCheckFactory::getNumericCheck(), true); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritDoc} |
|
25
|
|
|
* |
|
26
|
|
|
* @return static |
|
27
|
|
|
*/ |
|
28
|
10 |
|
public function array(): self |
|
29
|
|
|
{ |
|
30
|
10 |
|
return $this->check(ContainerCheckFactory::getArrayCheck(), true); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritDoc} |
|
35
|
|
|
* |
|
36
|
|
|
* @return static |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function indexedArray(): self |
|
39
|
|
|
{ |
|
40
|
2 |
|
return $this->check(ContainerCheckFactory::getIndexedArrayCheck(), true); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritDoc} |
|
45
|
|
|
* |
|
46
|
|
|
* @return static |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function associativeArray(): self |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->check(ContainerCheckFactory::getAssociativeArrayCheck(), true); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritDoc} |
|
55
|
|
|
* |
|
56
|
|
|
* @return static |
|
57
|
|
|
*/ |
|
58
|
2 |
|
public function arrayAccessible(): self |
|
59
|
|
|
{ |
|
60
|
2 |
|
return $this->check(ContainerCheckFactory::getArrayAccessibleCheck(), true); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritDoc} |
|
65
|
|
|
* |
|
66
|
|
|
* @return static |
|
67
|
|
|
*/ |
|
68
|
2 |
|
public function iterable(): self |
|
69
|
|
|
{ |
|
70
|
2 |
|
return $this->check(ContainerCheckFactory::getIterableCheck(), true); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritDoc} |
|
75
|
|
|
* |
|
76
|
|
|
* @return static |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function countable(): self |
|
79
|
|
|
{ |
|
80
|
2 |
|
return $this->check(ContainerCheckFactory::getCountableCheck(), true); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritDoc} |
|
85
|
|
|
* |
|
86
|
|
|
* @return static |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public function object(): self |
|
89
|
|
|
{ |
|
90
|
2 |
|
return $this->check(ContainerCheckFactory::getObjectCheck(), true); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* {@inheritDoc} |
|
95
|
|
|
* |
|
96
|
|
|
* @return static |
|
97
|
|
|
*/ |
|
98
|
3 |
|
public function stdObject(): self |
|
99
|
|
|
{ |
|
100
|
3 |
|
return $this->check(ContainerCheckFactory::getStdObjectCheck(), true); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritDoc} |
|
105
|
|
|
* |
|
106
|
|
|
* @return static |
|
107
|
|
|
*/ |
|
108
|
3 |
|
public function instanceOf(string $class): self |
|
109
|
|
|
{ |
|
110
|
3 |
|
return $this->check(ContainerCheckFactory::getInstanceOfCheck($class), true); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* {@inheritDoc} |
|
115
|
|
|
* |
|
116
|
|
|
* @return static |
|
117
|
|
|
*/ |
|
118
|
2 |
|
public function empty(): self |
|
119
|
|
|
{ |
|
120
|
2 |
|
return $this->check(ContainerCheckFactory::getEmptyCheck()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* {@inheritDoc} |
|
125
|
|
|
* |
|
126
|
|
|
* @return static |
|
127
|
|
|
*/ |
|
128
|
2 |
|
public function notEmpty(): self |
|
129
|
|
|
{ |
|
130
|
2 |
|
return $this->check(ContainerCheckFactory::getNotEmptyCheck()); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* {@inheritDoc} |
|
135
|
|
|
* |
|
136
|
|
|
* @return static |
|
137
|
|
|
*/ |
|
138
|
10 |
|
public function lengthIs(IntegerRuleInterface $rule): self |
|
139
|
|
|
{ |
|
140
|
10 |
|
return $this->check(ContainerCheckFactory::getLengthIsCheck($rule)); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* {@inheritDoc} |
|
145
|
|
|
* |
|
146
|
|
|
* @return static |
|
147
|
|
|
*/ |
|
148
|
22 |
|
public function hasAttribute(string $name, ?MixedRuleInterface $rule = null): self |
|
149
|
|
|
{ |
|
150
|
22 |
|
if ($rule === null) { |
|
151
|
2 |
|
return $this->check(ContainerCheckFactory::getHasAttributeCheck($name)); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
20 |
|
return $this->check(ContainerCheckFactory::getAttributeIsCheck($name, $rule)); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* {@inheritDoc} |
|
159
|
|
|
* |
|
160
|
|
|
* @return static |
|
161
|
|
|
*/ |
|
162
|
2 |
|
public function hasOptionalAttribute(string $name, MixedRuleInterface $rule): self |
|
163
|
|
|
{ |
|
164
|
2 |
|
return $this->check(ContainerCheckFactory::getHasOptionalAttributeCheck($name, $rule)); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* {@inheritDoc} |
|
169
|
|
|
* |
|
170
|
|
|
* @return static |
|
171
|
|
|
*/ |
|
172
|
5 |
|
public function hasIndex(int $index, ?MixedRuleInterface $rule = null): self |
|
173
|
|
|
{ |
|
174
|
5 |
|
if ($rule === null) { |
|
175
|
2 |
|
return $this->check(ContainerCheckFactory::getHasIndexCheck($index)); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
3 |
|
return $this->check(ContainerCheckFactory::getValueByIndexIsCheck($index, $rule)); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* {@inheritDoc} |
|
183
|
|
|
* |
|
184
|
|
|
* @return static |
|
185
|
|
|
*/ |
|
186
|
6 |
|
public function allKeysAre(MixedRuleInterface $rule): self |
|
187
|
|
|
{ |
|
188
|
6 |
|
return $this->check(ContainerCheckFactory::getAllKeysAreCheck($rule)); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* {@inheritDoc} |
|
193
|
|
|
* |
|
194
|
|
|
* @return static |
|
195
|
|
|
*/ |
|
196
|
3 |
|
public function someKeyIs(MixedRuleInterface $rule): self |
|
197
|
|
|
{ |
|
198
|
3 |
|
return $this->check(ContainerCheckFactory::getSomeKeyIsCheck($rule)); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* {@inheritDoc} |
|
203
|
|
|
* |
|
204
|
|
|
* @return static |
|
205
|
|
|
*/ |
|
206
|
13 |
|
public function allValuesAre(MixedRuleInterface $rule): self |
|
207
|
|
|
{ |
|
208
|
13 |
|
return $this->check(ContainerCheckFactory::getAllValuesAreCheck($rule)); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* {@inheritDoc} |
|
213
|
|
|
* |
|
214
|
|
|
* @return static |
|
215
|
|
|
*/ |
|
216
|
3 |
|
public function someValueIs(MixedRuleInterface $rule): self |
|
217
|
|
|
{ |
|
218
|
3 |
|
return $this->check(ContainerCheckFactory::getSomeValueIsCheck($rule)); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|