1 |
<?php
|
2 |
/*
|
3 |
* $Id: Exception.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
|
4 |
*
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
*
|
17 |
* This software consists of voluntary contributions made by many individuals
|
18 |
* and is licensed under the LGPL. For more information, see
|
19 |
* <http://www.phpdoctrine.org>.
|
20 |
*/
|
21 |
Doctrine::autoload('Doctrine_Exception');
|
22 |
/**
|
23 |
* Doctrine_Validator_Exception
|
24 |
*
|
25 |
* @package Doctrine
|
26 |
* @subpackage Validator
|
27 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
28 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
29 |
* @link www.phpdoctrine.org
|
30 |
* @since 1.0
|
31 |
* @version $Revision: 2963 $
|
32 |
*/
|
33 |
class Doctrine_Validator_Exception extends Doctrine_Exception implements Countable, IteratorAggregate
|
34 |
{
|
35 |
/**
|
36 |
* @var array $invalid
|
37 |
*/
|
38 |
private $invalid = array();
|
39 |
|
40 |
/**
|
41 |
* @param Doctrine_Validator $validator
|
42 |
*/
|
43 |
public function __construct(array $invalid)
|
44 |
{
|
45 |
$this->invalid = $invalid;
|
46 |
parent::__construct($this->generateMessage());
|
47 |
}
|
48 |
|
49 |
public function getInvalidRecords()
|
50 |
{
|
51 |
return $this->invalid;
|
52 |
}
|
53 |
|
54 |
public function getIterator()
|
55 |
{
|
56 |
return new ArrayIterator($this->invalid);
|
57 |
}
|
58 |
|
59 |
public function count()
|
60 |
{
|
61 |
return count($this->invalid);
|
62 |
}
|
63 |
|
64 |
/**
|
65 |
* __toString
|
66 |
*
|
67 |
* @return string
|
68 |
*/
|
69 |
public function __toString()
|
70 |
{
|
71 |
|
72 |
return parent::__toString();
|
73 |
}
|
74 |
|
75 |
/**
|
76 |
* Generate a message with all classes that have exceptions
|
77 |
*/
|
78 |
private function generateMessage()
|
79 |
{
|
80 |
$message = "";
|
81 |
foreach ($this->invalid as $record) {
|
82 |
$message .= "Validaton error in class " . get_class($record) . " ";
|
83 |
}
|
84 |
return $message;
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
* This method will apply the value of the $function variable as a user_func
|
89 |
* to tall errorstack objects in the exception
|
90 |
*
|
91 |
* @param mixed Either string with function name or array with object,
|
92 |
* functionname. See call_user_func in php manual for more inforamtion
|
93 |
*/
|
94 |
public function inspect($function)
|
95 |
{
|
96 |
foreach ($this->invalid as $record) {
|
97 |
call_user_func($function, $record->getErrorStack());
|
98 |
}
|
99 |
}
|
100 |
} |