public function __construct($message, $data = array(), $use_callback = true) { parent::__construct($message); // This is so if an exception is generated using a true/false/1/0 type value // it'll still process into a predictable format if (is_scalar($data)) { $data = array("data" => $data); } foreach (Amslib_Array::valid($data) as $key => $value) { $this->setData($key, $value); } // NOTE: I have to test whether this records the correct location in all circumstances $this->setData("location", basename($this->getFile()) . "@" . $this->getLine()); // if this callback is usable, call it for the custom functionality if (self::$callback && is_callable(self::$callback) && $use_callback) { call_user_func(self::$callback, $this, Amslib_Debug::getStackTrace("type", "text")); } }
/** * method: __shutdown_exception * * todo: write documentation */ public static function __shutdown_exception($e) { $stack = Amslib_Debug::getStackTrace("exception", $e); if (empty($stack)) { $stack = array(array("file" => "__STACK_ERROR__", "line" => "__STACK_ERROR__")); } if (!array_key_exists("file", $stack[0])) { $stack[0]["file"] = "__FILE_NOT_AVAILABLE__"; } if (!array_key_exists("line", $stack[0])) { $stack[0]["line"] = "__LINE_NOT_AVAILABLE__"; } $data = array("error" => "Uncaught Exception", "code" => get_class($e), "msg" => $e->getMessage(), "data" => is_callable(array($e, "getData")) ? $e->getData() : false, "file" => $stack[0]["file"], "line" => $stack[0]["line"], "stack" => $stack, "uri" => $_SERVER["REQUEST_URI"], "root" => isset($_SERVER["__WEBSITE_ROOT__"]) ? $_SERVER["__WEBSITE_ROOT__"] : "/"); self::__exec_shutdown($data); }
protected static function processMessage($list) { $data = array(); $function = false; foreach ($list as $k => $a) { if (is_string($a) && strpos($a, "stack_trace") === 0) { $command = explode(",", $a); $stack = Amslib_Debug::getStackTrace("type", "text"); $stack = explode("\n", $stack); $c = count($command); if ($c == 2) { $stack = array_slice($stack, $command[1]); } else { if ($c == 3 && $command[2] > 0) { $stack = array_slice($stack, $command[1], $command[2]); } } $trace = array("\n"); foreach ($stack as $row) { $trace[] = "[STACK TRACE] " . str_replace("\n", "", Amslib_Debug::dump($row)); } $data[] = implode("\n", $trace); } else { if (is_string($a) && strpos($a, "func_offset") === 0) { $command = explode(",", array_shift($list)); if (count($command) == 1) { $function = $command[0]; } } else { if (is_object($a)) { $a = array(get_class($a), Amslib_Debug::dump($a)); } if (is_array($a)) { $a = Amslib_Debug::dump($a); } if (is_bool($a)) { $a = $a ? "true" : "false"; } if (is_null($a)) { $a = "null"; } $a = trim(preg_replace("/\\s+/", " ", $a)); $data[] = "arg[{$k}]=> {$a}"; } } } $function = self::getLogOrigin(); return $data; }