* @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ /** * @since 1.5.0 */ class PrestaShopExceptionCore extends Exception { /** * This method acts like an error handler, if dev mode is on, display the error else use a better silent way */ public function displayMessage() { header('HTTP/1.1 500 Internal Server Error'); if (_PS_MODE_DEV_ || defined('_PS_ADMIN_DIR_')) { // Display error message echo ''; echo '
'; echo '

['.get_class($this).']

'; echo $this->getExtendedMessage(); $this->displayFileDebug($this->getFile(), $this->getLine()); // Display debug backtrace echo ''; echo '
'; } else { // If not in mode dev, display an error page if (file_exists(_PS_ROOT_DIR_.'/error500.html')) echo file_get_contents(_PS_ROOT_DIR_.'/error500.html'); } // Log the error in the disk $this->logError(); exit; } /** * Display lines around current line * * @param string $file * @param int $line * @param string $id */ protected function displayFileDebug($file, $line, $id = null) { $lines = file($file); $offset = $line - 6; $total = 11; if ($offset < 0) { $total += $offset; $offset = 0; } $lines = array_slice($lines, $offset, $total); echo '
';
		foreach ($lines as $k => $l)
		{
			if ($offset + $k == $line - 1)
				echo ''.($offset + $k).'. '.htmlspecialchars($l).'';
			else
				echo ($offset + $k).'. '.htmlspecialchars($l);
		}
		echo '
'; } /** * Display arguments list of traced function * * @param array $args List of arguments * @param string $id ID of argument */ protected function displayArgsDebug($args, $id) { echo '
';
		foreach ($args as $arg => $value)
		{
			echo 'Argument ['.Tools::safeOutput($arg)."]\n";
			echo Tools::safeOutput(print_r($value, true));
			echo "\n";
		}
		echo '
'; } /** * Log the error on the disk */ protected function logError() { $logger = new FileLogger(); $logger->setFilename(_PS_ROOT_DIR_.'/log/'.date('Ymd').'_exception.log'); $logger->logError($this->getExtendedMessage(false)); } /** * @deprecated 1.5.5 */ protected function getExentedMessage($html = true) { Tools::displayAsDeprecated(); return $this->getExtendedMessage($html); } /** * Return the content of the Exception * @return string content of the exception */ protected function getExtendedMessage($html = true) { $format = '

%s
at line %d in file %s

'; if (!$html) $format = strip_tags(str_replace('
', ' ', $format)); return sprintf( $format, $this->getMessage(), $this->getLine(), ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/') ); } }