/** * Process the exception. Calls the Exception::getTrace() method to * get the backtrace. Gets the relevant lines of code for each step * in the backtrace. */ public function getTrace($e) { $trace = $e->getTrace(); foreach ($trace as $i => &$entry) { if (isset($entry['class'])) { try { $refl = new ReflectionMethod($entry['class'], $entry['function']); if (isset($trace[$i - 1]) && isset($trace[$i - 1]['line'])) { $entry['caller'] = (int) $trace[$i - 1]['line'] - 1; } else { if ($i === 0) { $entry['caller'] = (int) $e->getLine() - 1; } } $start = $entry['caller'] - self::BACKTRACE_CONTEXT; if ($start < $refl->getStartLine()) { $start = $refl->getStartLine() - 1; } $end = $entry['caller'] + self::BACKTRACE_CONTEXT; if ($end > $refl->getEndLine()) { $end = $refl->getEndLine(); } $entry['source'] = $this->getSourceFromFile($refl->getFileName(), $start, $end); } catch (Exception $e) { $entry['caller'] = null; $entry['source'] = ''; } } if (isset($entry['args'])) { // Duplicate so we don't overwrite by-reference variables $args = array(); foreach ($entry['args'] as $i => $arg) { $args[$i] = gettype($arg); } $entry['args'] = $args; } } $exceptionParams = array(); if (method_exists($e, 'getParams')) { $exceptionParams = $e->getParams(); } $d = array('backtrace' => $trace, 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'name' => api_helpers_class::getBaseName($e), 'params' => $exceptionParams); if (!empty($e->userInfo)) { $d['userInfo'] = $e->userInfo; } return $d; }
/** * Get the base name of this exception. * @return string: Base name */ public function getName() { return api_helpers_class::getBaseName($this); }
/** * Returns the relative path to the XSLT file for this exception * handler. Passed on to api_controller::setXsl(). * @return string: XSLT file name. */ public function getXsl() { $xslName = api_helpers_class::getBaseName($this); return self::VIEWDIR . DIRECTORY_SEPARATOR . $xslName . '.xsl'; }
/** * Creates a new exception handler instances for the given class name. * * Will look up the following keys in that order in the configuration * and use the first exception handler for which a handler can be * instantiated. Uses api_exceptionhandler::getExceptionHandler(). * - $eClassname * - basename of $eClassname (see api_helpers_class::getBaseName) * - Wildcard (api_exceptionhandler::EXCEPTION_WILDCARD) * * If none of these three tests returns an exception handler then * the default handler as specified in api_exceptionhandler::DEFAULT_HANDLER * is loaded. * * @param $eClassName string: Class name of the exception to create the * exception handler for. * @return api_exceptionhandler_base instance */ private static function createInstance($eClassName) { $variations = array($eClassName, api_helpers_class::getBaseName($eClassName), self::EXCEPTION_WILDCARD); $cfg = api_config::getInstance()->exceptionhandler; if (is_array($cfg)) { foreach ($variations as $handler) { if (isset($cfg[$handler])) { $handler = self::getExceptionHandlerClassName($cfg[$handler]); return new $handler(); } } } $handler = self::getExceptionHandlerClassName(self::DEFAULT_HANDLER); return new $handler(); }
public function handle(Exception $e) { print "<h1>" . api_helpers_class::getBaseName($e) . " Exception</h1>"; return true; }