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