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 Model|string $model class name of model |
||
43 | * |
||
44 | * @var Locale |
||
45 | */ |
||
46 | public function __construct($model = null, Locale $locale = null) |
||
51 | |||
52 | /** |
||
53 | * Gets the model instance for these errors. |
||
54 | * |
||
55 | * @return Model|string|null |
||
56 | */ |
||
57 | public function getModel() |
||
61 | |||
62 | /** |
||
63 | * Gets the locale instance. |
||
64 | * |
||
65 | * @return Locale |
||
66 | */ |
||
67 | public function getLocale() |
||
71 | |||
72 | /** |
||
73 | * Adds an error message to the stack. |
||
74 | * |
||
75 | * @param string $property name of property the error is about |
||
76 | * @param string $error error code or message |
||
77 | * |
||
78 | * @return self |
||
79 | */ |
||
80 | public function add($property, $error) |
||
90 | |||
91 | /** |
||
92 | * Gets all of the errors on the stack and also attempts |
||
93 | * translation using the Locale class. |
||
94 | * |
||
95 | * @param string|false $property property to filter by |
||
96 | * @param string|false $locale locale name to translate to |
||
97 | * |
||
98 | * @return array errors |
||
99 | */ |
||
100 | public function all($property = false, $locale = false) |
||
121 | |||
122 | /** |
||
123 | * Checks if a property has an error. |
||
124 | * |
||
125 | * @param string $property |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | public function has($property) |
||
133 | |||
134 | /** |
||
135 | * Clears all errors. |
||
136 | * |
||
137 | * @return self |
||
138 | */ |
||
139 | public function clear() |
||
145 | |||
146 | /** |
||
147 | * Parses an error message before displaying it. |
||
148 | * |
||
149 | * @param string $property |
||
150 | * @param string $error |
||
151 | * @param string|false $locale |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | private function parse($property, $error, $locale) |
||
169 | |||
170 | ////////////////////////// |
||
171 | // IteratorAggregate Interface |
||
172 | ////////////////////////// |
||
173 | |||
174 | public function getIterator() |
||
178 | |||
179 | ////////////////////////// |
||
180 | // Countable Interface |
||
181 | ////////////////////////// |
||
182 | |||
183 | /** |
||
184 | * Get total number of errors. |
||
185 | * |
||
186 | * @return int |
||
187 | */ |
||
188 | public function count() |
||
192 | |||
193 | ///////////////////////////// |
||
194 | // ArrayAccess Interface |
||
195 | ///////////////////////////// |
||
196 | |||
197 | public function offsetExists($offset) |
||
201 | |||
202 | public function offsetGet($offset) |
||
206 | |||
207 | public function offsetSet($offset, $error) |
||
211 | |||
212 | public function offsetUnset($offset) |
||
218 | } |
||
219 |
This check marks private properties in classes that are never used. Those properties can be removed.