-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDataException.php
100 lines (91 loc) · 1.96 KB
/
DataException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Custom database-generated exception.
* See public.throw() stored procedure.
*/
class Mapper_DataException extends Mapper_Exception
{
/**
* Array with errors, field => errorType
*
* @var array
*/
private $_fields = array();
/**
* Array with exceptions, field => exception.
*
* @var array
*/
private $_exceptions = array();
/**
* Original exception
*
* @var Exception
*/
private $_origException = null;
/**
* Generator procedure name.
*
* @var string
*/
private $_procedureName = null;
/**
* Constructor.
*
* @param Exception $origException If present, means a single
* exception caused this one
* (usually DataException).
* @param string $_procedureName Invoker (if present).
*/
public function __construct($origException = null, $procedureName = null)
{
parent::__construct(($procedureName? $procedureName . ": " : ""));
$this->_procedureName = $procedureName;
$this->_origException = $origException;
}
/**
* Add an error.
*
* @param string $name
* @param string $error
* @return void
*/
public function addError($name, $error, Exception $origEx = null)
{
$this->_fields[$name] = $error;
if ($origEx) {
$this->_exceptions[$name] = $origEx;
}
$this->message .= "$name => $error" . ($origEx? "(" . $origEx->getMessage() . ")" : "") . ", ";
}
/**
* Return errors.
* Format: array(field => errorType)
*
* @return array
*/
public function getErrors()
{
return $this->_fields;
}
/**
* Return parent exceptions associated to field (if present).
* Exceptions may be associated not always.
*
* @return array
*/
public function getExceptions()
{
return $this->_exceptions;
}
/**
* Return generator procedure or null of no procedure
* is assigned to this exception.
*
* @return string
*/
public function getProcedureName()
{
return $this->_procedureName;
}
}