1: <?php
2: class QErrorAttribute {
3: public $Label;
4: public $Contents;
5: public $MultiLine;
6:
7: public function __construct($strLabel, $strContents, $blnMultiLine) {
8: $this->Label = $strLabel;
9: $this->Contents = $strContents;
10: $this->MultiLine = $blnMultiLine;
11: }
12: }
13:
14:
15: function QcubedHandleException($__exc_objException) {
16: if (class_exists('QApplicationBase'))
17: QApplicationBase::$ErrorFlag = true;
18:
19: global $__exc_strType;
20: if (isset($__exc_strType))
21: return;
22:
23: $__exc_objReflection = new ReflectionObject($__exc_objException);
24:
25: $__exc_strType = "Exception";
26: $__exc_errno = $__exc_objException->ErrorNumber;
27: $__exc_strMessage = $__exc_objException->getMessage();
28: $__exc_strObjectType = $__exc_objReflection->getName();
29:
30: if ($__exc_objException instanceof QDatabaseExceptionBase) {
31: $__exc_objErrorAttribute = new QErrorAttribute("Database Error Number", $__exc_errno, false);
32: $__exc_objErrorAttributeArray[0] = $__exc_objErrorAttribute;
33:
34: if ($__exc_objException->Query) {
35: $__exc_objErrorAttribute = new QErrorAttribute("Query", $__exc_objException->Query, true);
36: $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
37: }
38: }
39:
40: if ($__exc_objException instanceof QDataBindException) {
41: if ($__exc_objException->Query) {
42: $__exc_objErrorAttribute = new QErrorAttribute("Query", $__exc_objException->Query, true);
43: $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
44: }
45: }
46:
47: $__exc_strFilename = $__exc_objException->getFile();
48: $__exc_intLineNumber = $__exc_objException->getLine();
49: $__exc_strStackTrace = trim($__exc_objException->getTraceAsString());
50:
51: if (ob_get_length()) {
52: $__exc_strRenderedPage = ob_get_contents();
53: ob_clean();
54: }
55:
56:
57: if (defined('ERROR_PAGE_PATH')) {
58: require(__DOCROOT__ . ERROR_PAGE_PATH);
59: } else {
60:
61: echo "error: errno: ". $__exc_errno . "<br/>" . $__exc_strMessage . "<br/>" . $__exc_strFilename . ":" . $__exc_intLineNumber . "<br/>" . $__exc_strStackTrace ;
62: }
63: if (!defined('HHVM_VERSION')) {
64: exit();
65: }
66: }
67:
68: function QcubedHandleError($__exc_errno, $__exc_errstr, $__exc_errfile, $__exc_errline, $__exc_errcontext) {
69:
70: if (error_reporting() == 0)
71: return true;
72:
73: if (class_exists('QApplicationBase'))
74: QApplicationBase::$ErrorFlag = true;
75:
76: global $__exc_strType;
77: if (isset($__exc_strType))
78: return true;
79:
80: $__exc_strType = "Error";
81: $__exc_strMessage = $__exc_errstr;
82:
83: switch ($__exc_errno) {
84: case E_ERROR:
85: $__exc_strObjectType = "E_ERROR";
86: break;
87: case E_WARNING:
88: $__exc_strObjectType = "E_WARNING";
89: break;
90: case E_PARSE:
91: $__exc_strObjectType = "E_PARSE";
92: break;
93: case E_NOTICE:
94: $__exc_strObjectType = "E_NOTICE";
95: break;
96: case E_STRICT:
97: $__exc_strObjectType = "E_STRICT";
98: break;
99: case E_CORE_ERROR:
100: $__exc_strObjectType = "E_CORE_ERROR";
101: break;
102: case E_CORE_WARNING:
103: $__exc_strObjectType = "E_CORE_WARNING";
104: break;
105: case E_COMPILE_ERROR:
106: $__exc_strObjectType = "E_COMPILE_ERROR";
107: break;
108: case E_COMPILE_WARNING:
109: $__exc_strObjectType = "E_COMPILE_WARNING";
110: break;
111: case E_USER_ERROR:
112: $__exc_strObjectType = "E_USER_ERROR";
113: break;
114: case E_USER_WARNING:
115: $__exc_strObjectType = "E_USER_WARNING";
116: break;
117: case E_USER_NOTICE:
118: $__exc_strObjectType = "E_USER_NOTICE";
119: break;
120: case E_DEPRECATED:
121: $__exc_strObjectType = 'E_DEPRECATED';
122: break;
123: case E_USER_DEPRECATED:
124: $__exc_strObjectType = 'E_USER_DEPRECATED';
125: break;
126: case E_RECOVERABLE_ERROR:
127: $__exc_strObjectType = 'E_RECOVERABLE_ERROR';
128: break;
129: default:
130: $__exc_strObjectType = "Unknown";
131: break;
132: }
133:
134: $__exc_strFilename = $__exc_errfile;
135: $__exc_intLineNumber = $__exc_errline;
136: $__exc_strStackTrace = "";
137: $__exc_objBacktrace = debug_backtrace();
138: for ($__exc_intIndex = 0; $__exc_intIndex < count($__exc_objBacktrace); $__exc_intIndex++) {
139: $__exc_objItem = $__exc_objBacktrace[$__exc_intIndex];
140:
141: $__exc_strKeyFile = (array_key_exists("file", $__exc_objItem)) ? $__exc_objItem["file"] : "";
142: $__exc_strKeyLine = (array_key_exists("line", $__exc_objItem)) ? $__exc_objItem["line"] : "";
143: $__exc_strKeyClass = (array_key_exists("class", $__exc_objItem)) ? $__exc_objItem["class"] : "";
144: $__exc_strKeyType = (array_key_exists("type", $__exc_objItem)) ? $__exc_objItem["type"] : "";
145: $__exc_strKeyFunction = (array_key_exists("function", $__exc_objItem)) ? $__exc_objItem["function"] : "";
146:
147: $__exc_strStackTrace .= sprintf("#%s %s(%s): %s%s%s()\n",
148: $__exc_intIndex,
149: $__exc_strKeyFile,
150: $__exc_strKeyLine,
151: $__exc_strKeyClass,
152: $__exc_strKeyType,
153: $__exc_strKeyFunction);
154: }
155:
156: if (ob_get_length()) {
157: $__exc_strRenderedPage = ob_get_contents();
158: ob_clean();
159: }
160:
161:
162: if (defined('ERROR_PAGE_PATH')) {
163: require(__DOCROOT__ . ERROR_PAGE_PATH);
164: } else {
165:
166: echo "error: errno: ". $__exc_errno . "<br/>" . $__exc_errstr . "<br/>" . $__exc_errfile . ":" . $__exc_errline . "<br/>" . implode(', ', $__exc_errcontext) ;
167: }
168: exit();
169: }
170:
171: 172: 173: 174:
175:
176: function QCubedShutdown() {
177: if (defined ('__TIMER_OUT_FILE__')) {
178: $strTimerOutput = QTimer::VarDump(false);
179: if ($strTimerOutput) {
180: file_put_contents(__TIMER_OUT_FILE__, $strTimerOutput . "\n", FILE_APPEND);
181: }
182: }
183:
184: $error = error_get_last();
185: if ($error &&
186: is_array ($error) &&
187: (!defined ('QCodeGen::DebugMode') || QCodeGen::DebugMode)) {
188:
189: QcubedHandleError (
190: $error['type'],
191: $error['message'],
192: $error['file'],
193: $error['line'],
194: ''
195: );
196: }
197:
198:
199:
200: }