1 | <?php |
||
19 | class Errors implements IteratorAggregate, Countable, ArrayAccess |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private $stack = []; |
||
25 | |||
26 | /** |
||
27 | * @var Model |
||
28 | */ |
||
29 | private $model; |
||
30 | |||
31 | /** |
||
32 | * @var Locale |
||
33 | */ |
||
34 | private $locale; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $pointer = 0; |
||
|
|||
40 | |||
41 | /** |
||
42 | * @param string $model class name of model |
||
43 | * |
||
44 | * @var Locale |
||
45 | */ |
||
46 | public function __construct($model, Locale $locale = null) |
||
55 | |||
56 | /** |
||
57 | * Gets the locale instance. |
||
58 | * |
||
59 | * @return Locale |
||
60 | */ |
||
61 | public function getLocale() |
||
65 | |||
66 | /** |
||
67 | * Adds an error message to the stack. |
||
68 | * |
||
69 | * @param string $property name of property the error is about |
||
70 | * @param string $error error code or message |
||
71 | * |
||
72 | * @return self |
||
73 | */ |
||
74 | public function add($property, $error) |
||
84 | |||
85 | /** |
||
86 | * Gets all of the errors on the stack and also attempts |
||
87 | * translation using the Locale class. |
||
88 | * |
||
89 | * @param string|false $property property to filter by |
||
90 | * @param string|false $locale locale name to translate to |
||
91 | * |
||
92 | * @return array errors |
||
93 | */ |
||
94 | public function all($property = false, $locale = false) |
||
115 | |||
116 | /** |
||
117 | * Checks if a property has an error. |
||
118 | * |
||
119 | * @param string $property |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function has($property) |
||
127 | |||
128 | /** |
||
129 | * Clears all errors. |
||
130 | * |
||
131 | * @return self |
||
132 | */ |
||
133 | public function clear() |
||
139 | |||
140 | /** |
||
141 | * Parses an error message before displaying it. |
||
142 | * |
||
143 | * @param string $property |
||
144 | * @param string $error |
||
145 | * @param string|false $locale |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | private function parse($property, $error, $locale) |
||
159 | |||
160 | ////////////////////////// |
||
161 | // IteratorAggregate Interface |
||
162 | ////////////////////////// |
||
163 | |||
164 | public function getIterator() |
||
168 | |||
169 | ////////////////////////// |
||
170 | // Countable Interface |
||
171 | ////////////////////////// |
||
172 | |||
173 | /** |
||
174 | * Get total number of errors. |
||
175 | * |
||
176 | * @return int |
||
177 | */ |
||
178 | public function count() |
||
182 | |||
183 | ///////////////////////////// |
||
184 | // ArrayAccess Interface |
||
185 | ///////////////////////////// |
||
186 | |||
187 | public function offsetExists($offset) |
||
191 | |||
192 | public function offsetGet($offset) |
||
196 | |||
197 | public function offsetSet($offset, $error) |
||
201 | |||
202 | public function offsetUnset($offset) |
||
208 | } |
||
209 |
This check marks private properties in classes that are never used. Those properties can be removed.