1 | <?php |
||
22 | class ErrorCollection implements \IteratorAggregate |
||
23 | { |
||
24 | /** |
||
25 | * Stored errors. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $errors = array(); |
||
30 | |||
31 | /** |
||
32 | * Construct. |
||
33 | * |
||
34 | * @param array $errors Initial error messages. |
||
35 | */ |
||
36 | public function __construct(array $errors = array()) |
||
40 | |||
41 | /** |
||
42 | * Add a new error. |
||
43 | * |
||
44 | * @param string $message Error message. |
||
45 | * @param array $params Params for the error message. |
||
46 | * @param ErrorCollection $collection Option. Child collection of the error. |
||
47 | * |
||
48 | * @return $this |
||
49 | */ |
||
50 | public function addError(string $message, array $params = array(), ErrorCollection $collection = null) |
||
56 | |||
57 | /** |
||
58 | * Check if any error isset. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function hasErrors(): bool |
||
66 | |||
67 | /** |
||
68 | * Count error messages. |
||
69 | * |
||
70 | * @return int |
||
71 | */ |
||
72 | public function countErrors(): int |
||
76 | |||
77 | /** |
||
78 | * Get an error by it's index. |
||
79 | * |
||
80 | * @param int $index Error index. |
||
81 | * |
||
82 | * @throws \InvalidArgumentException If error index is not set. |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | public function getError(int $index): array |
||
94 | |||
95 | /** |
||
96 | * Reset error collection. |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function reset(): self |
||
106 | |||
107 | /** |
||
108 | * Add a set of errors. |
||
109 | * |
||
110 | * @param array $errors List of errors. |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function addErrors(array $errors): self |
||
124 | |||
125 | /** |
||
126 | * Get all errors. |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | public function getErrors(): array |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function getIterator(): iterable |
||
142 | |||
143 | /** |
||
144 | * Convert error collection to an array. |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | public function toArray(): array |
||
163 | } |
||
164 |