1 |
<?php
|
2 |
/*
|
3 |
* $Id: ErrorStack.php 2702 2007-10-03 21:43:22Z 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.com>.
|
20 |
*/
|
21 |
/**
|
22 |
* Doctrine_Validator_ErrorStack
|
23 |
*
|
24 |
* @package Doctrine
|
25 |
* @subpackage Validator
|
26 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
27 |
* @author Roman Borschel <roman@code-factory.org>
|
28 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
29 |
* @link www.phpdoctrine.com
|
30 |
* @since 1.0
|
31 |
* @version $Revision: 2702 $
|
32 |
*/
|
33 |
class Doctrine_Validator_ErrorStack extends Doctrine_Access implements Countable, IteratorAggregate
|
34 |
{
|
35 |
|
36 |
/**
|
37 |
* The errors of the error stack.
|
38 |
*
|
39 |
* @var array
|
40 |
*/
|
41 |
protected $errors = array();
|
42 |
protected $classname = "";
|
43 |
|
44 |
/**
|
45 |
* Constructor
|
46 |
*
|
47 |
*/
|
48 |
public function __construct($classname = "")
|
49 |
{
|
50 |
$this->classname = $classname;
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
* Adds an error to the stack.
|
55 |
*
|
56 |
* @param string $invalidFieldName
|
57 |
* @param string $errorType
|
58 |
*/
|
59 |
public function add($invalidFieldName, $errorCode = 'general')
|
60 |
{
|
61 |
$this->errors[$invalidFieldName][] = $errorCode;
|
62 |
}
|
63 |
|
64 |
/**
|
65 |
* Removes all existing errors for the specified field from the stack.
|
66 |
*
|
67 |
* @param string $fieldName
|
68 |
*/
|
69 |
public function remove($fieldName)
|
70 |
{
|
71 |
if (isset($this->errors[$fieldName])) {
|
72 |
unset($this->errors[$fieldName]);
|
73 |
}
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
* Enter description here...
|
78 |
*
|
79 |
* @param unknown_type $name
|
80 |
* @return unknown
|
81 |
*/
|
82 |
public function get($fieldName)
|
83 |
{
|
84 |
return isset($this->errors[$fieldName]) ? $this->errors[$fieldName] : null;
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
* Enter description here...
|
89 |
*
|
90 |
* @param unknown_type $name
|
91 |
*/
|
92 |
public function set($fieldName, $errorCode)
|
93 |
{
|
94 |
$this->add($fieldName, $errorCode);
|
95 |
}
|
96 |
|
97 |
/**
|
98 |
* Enter description here...
|
99 |
*
|
100 |
* @return unknown
|
101 |
*/
|
102 |
public function contains($fieldName)
|
103 |
{
|
104 |
return array_key_exists($fieldName, $this->errors);
|
105 |
}
|
106 |
|
107 |
/**
|
108 |
* Removes all errors from the stack.
|
109 |
*/
|
110 |
public function clear()
|
111 |
{
|
112 |
$this->errors = array();
|
113 |
}
|
114 |
|
115 |
/**
|
116 |
* Enter description here...
|
117 |
*
|
118 |
* @return unknown
|
119 |
*/
|
120 |
public function getIterator()
|
121 |
{
|
122 |
return new ArrayIterator($this->errors);
|
123 |
}
|
124 |
/**
|
125 |
* Enter description here...
|
126 |
*
|
127 |
* @return unknown
|
128 |
*/
|
129 |
public function count()
|
130 |
{
|
131 |
return count($this->errors);
|
132 |
}
|
133 |
|
134 |
/**
|
135 |
* Get the classname where the errors occured
|
136 |
*
|
137 |
*/
|
138 |
public function getClassname(){
|
139 |
return $this->classname;
|
140 |
}
|
141 |
} |