Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ValidateException is now tied to an entity

  • Loading branch information...
commit 6223571b8b71086d1455116913656a643e81a2f4 1 parent 528e51d
Mariano Iglesias authored

Showing 2 changed files with 13 additions and 12 deletions. Show diff stats Hide diff stats

  1. +2 2 models/BaseEntity.php
  2. +11 10 models/ValidateException.php
4 models/BaseEntity.php
@@ -105,7 +105,7 @@ public function onPostLoad(LifecycleEventArgs $eventArgs) {
105 105 public function onPrePersist(LifecycleEventArgs $eventArgs) {
106 106 $this->_exists = false;
107 107 if (!$this->validates()) {
108   - throw new ValidateException($this->_errors);
  108 + throw new ValidateException($this);
109 109 }
110 110 }
111 111
@@ -118,7 +118,7 @@ public function onPrePersist(LifecycleEventArgs $eventArgs) {
118 118 public function onPreUpdate(PreUpdateEventArgs $eventArgs) {
119 119 $this->_exists = true;
120 120 if (!$this->validates()) {
121   - throw new ValidateException($this->_errors);
  121 + throw new ValidateException($this);
122 122 }
123 123 }
124 124
21 models/ValidateException.php
@@ -2,23 +2,24 @@
2 2 namespace li3_doctrine2\models;
3 3
4 4 class ValidateException extends \Exception {
5   - protected $_errors;
  5 + protected $entity;
6 6
7   - public function __construct($field, $error = null) {
8   - $errors = $field;
9   - if (!is_array($field)) {
10   - $errors = array($field => array($error));
11   - }
12   - $this->_errors = $errors;
  7 + public function __construct(BaseEntity $entity) {
  8 + $this->entity = $entity;
  9 + $errors = $this->getErrors();
13 10 $message = '';
14   - if (!empty($this->_errors)) {
15   - $message = current(current($this->_errors));
  11 + if (!empty($errors)) {
  12 + $message = current(current($errors));
16 13 }
17 14 parent::__construct($message);
18 15 }
19 16
  17 + public function getEntity() {
  18 + return $this->entity;
  19 + }
  20 +
20 21 public function getErrors() {
21   - return $this->_errors;
  22 + return $this->entity->errors();
22 23 }
23 24 }
24 25 ?>

0 comments on commit 6223571

Please sign in to comment.
Something went wrong with that request. Please try again.