1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12:
13:
14: 15: 16: 17: 18: 19:
20: class DibiException extends Exception
21: {
22:
23: private $sql;
24:
25:
26: 27: 28: 29: 30: 31:
32: public function __construct($message = NULL, $code = 0, $sql = NULL)
33: {
34: parent::__construct($message, (int) $code);
35: $this->sql = $sql;
36: }
37:
38:
39:
40: 41: 42:
43: final public function getSql()
44: {
45: return $this->sql;
46: }
47:
48:
49:
50: 51: 52:
53: public function __toString()
54: {
55: return parent::__toString() . ($this->sql ? "\nSQL: " . $this->sql : '');
56: }
57:
58: }
59:
60:
61:
62:
63: 64: 65: 66: 67: 68:
69: class DibiDriverException extends DibiException
70: {
71:
72:
73:
74:
75:
76:
77: private static $errorMsg;
78:
79:
80:
81: 82: 83: 84:
85: public static function tryError()
86: {
87: set_error_handler(array(__CLASS__, '_errorHandler'), E_ALL);
88: self::$errorMsg = NULL;
89: }
90:
91:
92:
93: 94: 95: 96: 97:
98: public static function catchError(& $message)
99: {
100: restore_error_handler();
101: $message = self::$errorMsg;
102: self::$errorMsg = NULL;
103: return $message !== NULL;
104: }
105:
106:
107:
108: 109: 110: 111:
112: public static function _errorHandler($code, $message)
113: {
114: restore_error_handler();
115:
116: if (ini_get('html_errors')) {
117: $message = strip_tags($message);
118: $message = html_entity_decode($message);
119: }
120:
121: self::$errorMsg = $message;
122: }
123:
124: }
125:
126:
127:
128:
129: 130: 131: 132: 133: 134:
135: class DibiPcreException extends Exception {
136:
137: public function __construct($message = '%msg.')
138: {
139: static $messages = array(
140: PREG_INTERNAL_ERROR => 'Internal error',
141: PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
142: PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
143: PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data',
144: 5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point',
145: );
146: $code = preg_last_error();
147: parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
148: }
149: }
150:
151:
152:
153: 154: 155:
156: class DibiNotImplementedException extends DibiException
157: {}
158:
159:
160:
161: 162: 163:
164: class DibiNotSupportedException extends DibiException
165: {}
166: