Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Exception.php 7490 2010-03-29 19:53:27Z jwage $
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.doctrine-project.org>.
20
 */
21
 
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.doctrine-project.org
30
 * @since       1.0
31
 * @version     $Revision: 7490 $
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
     * Generate a message with all classes that have exceptions
66
     */
67
    private function generateMessage()
68
    {
69
        $message = '';
70
        foreach ($this->invalid as $record) {
71
            $message .= $record->getErrorStackAsString();
72
        }
73
        return $message;
74
    }
75
 
76
    /**
77
     * This method will apply the value of the $function variable as a user_func
78
     * to tall errorstack objects in the exception
79
     *
80
     * @param mixed Either string with function name or array with object,
81
     * functionname. See call_user_func in php manual for more inforamtion
82
     */
83
    public function inspect($function)
84
    {
85
        foreach ($this->invalid as $record) {
86
            call_user_func($function, $record->getErrorStack());
87
        }
88
    }
89
}