Skip to content

HTTPS clone URL

Subversion checkout URL

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