/** * Display an Exception * * This function will load a predefined template page (in PHP form) in order to warn the user something has gone wrong. * * If an exception is provided, it will be detailed as much as possible ; if not, only a generic message will be displayed * * @date 20100918 * @date 20120511 (v1.1) (greg) output is captured in case we want to save it * @date 20120724 (v1.2) (greg) added "probable origin" * @version 1.2 * @author greg <*****@*****.**> * * @return string the whole output * * @param Exception $e (optional) the exception to explain * @param boolean $detailed whether the details should be displayed or replaced y a generic message */ public function showException(Exception $e = null, $detailed = true) { // we stop on the first unhandled error $this->I_give_up = true; if ($this->PHPDS_dependance()->isEmbedded()) { return; } PU_cleanBuffers(); if (is_a($e, 'Exception')) { $lineno = $e->getLine(); $filepath = $e->getFile(); $trace = is_a($e, 'PHPDS_exception') ? $e->getExtendedTrace() : $e->getTrace(); $ignore = is_a($e, 'PHPDS_exception') ? $e->getIgnoreLines() : -1; $filefragment = PHPDS_backtrace::fetchCodeFragment($filepath, $lineno); if (isset($trace[$ignore])) { $frame = $trace[$ignore]; $framefragment = PHPDS_backtrace::fetchCodeFragment($frame['file'], $frame['line']); } else { $ignore = -1; } $message = $e->getMessage(); $code = $e->getCode(); $extendedMessage = is_a($e, 'PHPDS_exception') ? $e->getExtendedMessage() : ''; $config = $this->configuration; if (!empty($config)) { if (isset($config['config_files_used'])) { $conf['used'] = PU_dumpArray($config['config_files_used']); } if (isset($config['config_files_missing'])) { $conf['missing'] = PU_dumpArray($config['config_files_missing']); } } $bt = PHPDS_backtrace::asHTML($ignore, $trace); } else { $message = "Unknown exception..."; $code = null; } // now use the theme's error page to format the actual display $protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; // Need this for absolute URL configuration to be sef safe. $aurl = $protocol . $_SERVER['SERVER_NAME'] . str_replace('/index.php', '', $_SERVER['PHP_SELF']); ob_start(); // Load error page: $e is the handled exception require BASEPATH . 'themes/default/error.php'; $output = ob_get_clean(); if (!empty($this->crumbs)) { $output = str_replace('<crumbs/>', implode("\n", $this->crumbs), $output); } if (PU_isAJAX()) { // If the error occurred during an AJAX request, we'll send back a lightweight ouput $message = $this->display ? "{$message} - file {$filepath} line {$lineno}" : 'Error Concealed - Disabled in config'; PU_silentHeader('Status: 500 ' . $message); PU_silentHeader('HTTP/1.1 500 ' . $message); print $message; } else { // for a regular request, we present a nicely formatted html page; if provided, an extended description of the error is displayed if ($detailed) { echo $output; } else { $message = ''; require BASEPATH . 'themes/default/error.php'; // $message being empty, only a genetic message is output } } return $output; }
/** * Display an Exception * * This function will load a predefined template page (in PHP form) in order to warn the user something has gone wrong. * * If an exception is provided, it will be detailed as much as possible ; if not, only a generic message will be displayed * * @date 20100918 * @date 20120511 (v1.1) (greg) output is captured in case we want to save it * @version 1.1 * @author greg * * @return string the whole output * * @param Exception $e (optional) */ public function showException(Exception $e = null, $display = true) { // we stop on the first unhandled error $this->I_give_up = true; if ($this->PHPDS_dependance()->isEmbedded()) { return; } PU_cleanBuffers(); if (is_a($e, 'Exception')) { $lineno = $e->getLine(); $filepath = $e->getFile(); $trace = is_a($e, 'PHPDS_exception') ? $e->getExtendedTrace() : $e->getTrace(); $ignore = is_a($e, 'PHPDS_exception') ? $e->getIgnoreLines() : 1; $filefragment = PHPDS_backtrace::fetchCodeFragment($filepath, $lineno); $message = $e->getMessage(); $extendedMessage = is_a($e, 'PHPDS_exception') ? $e->getExtendedMessage() : ''; $config = $this->configuration; if (!empty($config)) { if (isset($config['config_files_used'])) { $conf['used'] = PU_dumpArray($config['config_files_used']); } if (isset($config['config_files_missing'])) { $conf['missing'] = PU_dumpArray($config['config_files_missing']); } } $bt = PHPDS_backtrace::asHTML($ignore, $trace); } $protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; // Need this for absolute URL configuration to be sef safe. $aurl = $protocol . $_SERVER['SERVER_NAME'] . str_replace('/index.php', '', $_SERVER['PHP_SELF']); ob_start(); // Load error page: $e is the handled exception require_once BASEPATH . 'themes/cloud/error.php'; $output = ob_get_clean(); if ($display) { echo $output; } return $output; }