Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ValidateException can now be used to raise non-entity bound errors

  • Loading branch information...
commit 87bd326be403fe9637a9acf8ebfcb8d9689a7284 1 parent 5d32bb4
@mariano authored
Showing with 13 additions and 6 deletions.
  1. +13 −6 models/ValidateException.php
View
19 models/ValidateException.php
@@ -3,13 +3,20 @@
class ValidateException extends \Exception {
protected $entity;
+ protected $errors;
+
+ public function __construct($entity) {
+ if ($entity instanceof BaseEntity) {
+ $this->entity = $entity;
+ $this->errors = $entity->errors();
+ } else {
+ $this->errors = $entity;
+ }
- public function __construct(BaseEntity $entity) {
- $this->entity = $entity;
- $errors = $this->getErrors();
$message = '';
- if (!empty($errors)) {
- $message = current(current($errors));
+ if (!empty($this->errors)) {
+ $first = current($this->errors);
+ $message = is_array($first) ? current($first) : $first;
}
parent::__construct($message);
}
@@ -19,7 +26,7 @@ public function getEntity() {
}
public function getErrors() {
- return $this->entity->errors();
+ return $this->errors();
}
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.