1 | <?php |
||
29 | class Set implements \Caridea\Validate\Rule, \IteratorAggregate, \Countable |
||
30 | { |
||
31 | /** |
||
32 | * @var \Caridea\Validate\Rule[] The rules |
||
33 | */ |
||
34 | private $rules = []; |
||
35 | /** |
||
36 | * @var string Optional error code to return |
||
37 | */ |
||
38 | private $error; |
||
39 | |||
40 | /** |
||
41 | * Creates a new Set. |
||
42 | * |
||
43 | * @param \Caridea\Validate\Rule[] $rules The rules to add |
||
44 | * @param string|null $error Optional error code to return |
||
45 | * @throws \InvalidArgumentException if `$rules` contains invalid types |
||
46 | */ |
||
47 | 8 | public function __construct(array $rules = [], ?string $error = null) |
|
52 | |||
53 | /** |
||
54 | * Adds one or more `Rule`s into this `Set`. |
||
55 | * |
||
56 | * @param \Caridea\Validate\Rule ...$rules The rules to add |
||
57 | * @return $this Provides a fluent interface |
||
58 | */ |
||
59 | 6 | public function add(\Caridea\Validate\Rule ...$rules): self |
|
64 | |||
65 | /** |
||
66 | * Adds several `Rule`s into this `Set`. |
||
67 | * |
||
68 | * @param \Caridea\Validate\Rule[] $rules The rules to add |
||
69 | * @return $this Provides a fluent interface |
||
70 | * @throws \InvalidArgumentException if `$rules` contains invalid types |
||
71 | */ |
||
72 | 5 | public function addAll(array $rules): self |
|
80 | |||
81 | /** |
||
82 | * Adds the entries from another `Set` into this one. |
||
83 | * |
||
84 | * @param \Caridea\Validate\Rule\Set $rules The rules to add |
||
85 | * @return $this Provides a fluent interface |
||
86 | */ |
||
87 | 1 | public function merge(Set $rules): self |
|
92 | |||
93 | /** |
||
94 | * Gets the error code, or `null` |
||
95 | * |
||
96 | * @return string|null The error code or `null` |
||
97 | */ |
||
98 | 1 | public function getError(): ?string |
|
102 | |||
103 | /** |
||
104 | * Sets the error code. |
||
105 | * |
||
106 | * @param string|null $error The error code or `null` |
||
107 | * @return $this provides a fluent interface |
||
108 | */ |
||
109 | 1 | public function setError(?string $error): self |
|
114 | |||
115 | /** |
||
116 | * Count elements of an object |
||
117 | * |
||
118 | * @return int Custom count as an integer |
||
119 | */ |
||
120 | 1 | public function count(): int |
|
124 | |||
125 | /** |
||
126 | * Retrieve an external iterator |
||
127 | * |
||
128 | * @return \Traversable An instance of an object implementing Iterator or Traversable |
||
129 | */ |
||
130 | 1 | public function getIterator(): \Traversable |
|
134 | |||
135 | /** |
||
136 | * {@inheritDoc} |
||
137 | */ |
||
138 | 2 | public function apply($value, $data = []): ?array |
|
152 | } |
||
153 |