You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
676 B
25 lines
676 B
<?php
|
|
|
|
class ValidationException extends Exception {
|
|
protected $errors;
|
|
|
|
public function __construct(array $errors, $message = "Validation errors occurred", $code = 0, Exception $previous = null) {
|
|
parent::__construct($message, $code, $previous);
|
|
$this->errors = $errors;
|
|
}
|
|
|
|
public function getErrors() {
|
|
return $this->errors;
|
|
}
|
|
|
|
public function __toString() {
|
|
return __CLASS__ . ": [{$this->code}]: {$this->message}\n" . $this->formatErrors();
|
|
}
|
|
|
|
protected function formatErrors() {
|
|
return implode("\n", array_map(function ($error) {
|
|
return "- {$error}";
|
|
}, $this->errors));
|
|
}
|
|
}
|