1 | <?php |
||
16 | class Validation { |
||
17 | /// Properties /// |
||
18 | |||
19 | protected $errors = []; |
||
20 | |||
21 | protected $mainMessage; |
||
22 | |||
23 | protected $status; |
||
24 | |||
25 | /// Methods /// |
||
26 | |||
27 | /** |
||
28 | * Initialize an instance of the {@link Validation} class. |
||
29 | * |
||
30 | * @param array $errors An array of errors. |
||
31 | * @param string $mainMessage The main message of the error. |
||
32 | * @param int $status The http status code of the error or 0 to build the status code from the indivdual errors. |
||
33 | */ |
||
34 | 68 | public function __construct(array $errors = [], $mainMessage = '', $status = 0) { |
|
39 | |||
40 | /** |
||
41 | * Gets the error message from an error. |
||
42 | * |
||
43 | * Errors are stored with either a message or a translation code. |
||
44 | * This method will look at both to determine the full message. |
||
45 | * |
||
46 | * @param array $error The error array. |
||
47 | * @return string Returns the message from the error. |
||
48 | */ |
||
49 | public static function errorMessage(array $error) { |
||
60 | |||
61 | /** |
||
62 | * Add an error. |
||
63 | * |
||
64 | * @param string $messageCode The message translation code. |
||
65 | * If you add a message that starts with "@" then no translation will take place. |
||
66 | * @param string|array $field The name of the field to add or an array of fields if the error applies to |
||
67 | * more than one field. |
||
68 | * @param int|array $options An array of additional information to add to the error entry or a numeric error code. |
||
69 | * @return Validation Returns $this for fluent calls. |
||
70 | */ |
||
71 | 42 | public function addError($messageCode, $field = '*', $options = []) { |
|
106 | |||
107 | /** |
||
108 | * Gets the main error message for the validation. |
||
109 | * |
||
110 | * @param string|null $value Pass a new main message or null to get the current main message. |
||
111 | * @return Validation|string Returns the main message or $this for fluent sets. |
||
112 | */ |
||
113 | public function mainMessage($value = null) { |
||
121 | |||
122 | /** |
||
123 | * Get or set the error status code. |
||
124 | * |
||
125 | * The status code is an http resonse code and should be of the 4xx variety. |
||
126 | * |
||
127 | * @param int|null $value Pass a new status code or null to get the current code. |
||
128 | * @return Validation|int Returns the current status code or $this for fluent sets. |
||
129 | */ |
||
130 | public function status($value = null) { |
||
150 | |||
151 | /** |
||
152 | * Get the message for this exception. |
||
153 | * |
||
154 | * @return string Returns the exception message. |
||
155 | */ |
||
156 | 1 | public function getMessage() { |
|
183 | |||
184 | /** |
||
185 | * Gets all of the errors as a flat array. |
||
186 | * |
||
187 | * The errors are internally stored indexed by field. This method flattens them for final error returns. |
||
188 | * |
||
189 | * @return array Returns all of the errors. |
||
190 | */ |
||
191 | public function getErrorsFlat() { |
||
200 | |||
201 | /** |
||
202 | * Check whether or not the validation is free of errors. |
||
203 | * |
||
204 | * @return bool Returns true if there are no errors, false otherwise. |
||
205 | */ |
||
206 | 68 | public function isValid() { |
|
209 | |||
210 | /** |
||
211 | * Check whether or not a particular field is has errors. |
||
212 | * |
||
213 | * @param string $field The name of the field to check for validity. |
||
214 | * @return bool Returns true if the field has no errors, false otherwise. |
||
215 | */ |
||
216 | 33 | public function fieldValid($field) { |
|
220 | } |
||
221 |