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