* @copyright 2007-2012 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() { if (_PS_MODE_DEV_ || defined('_PS_ADMIN_DIR_')) { // Display error message echo ''; echo '
'; echo '

['.get_class($this).']

'; printf( '

%s
at line %d in file %s

', $this->getMessage(), $this->getLine(), ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/') ); $this->displayFileDebug($this->getFile(), $this->getLine()); // Display debug backtrace echo ''; echo '
'; } else { // If not in mode dev, launch a http 500 error header('HTTP/1.1 500 Internal Server Error'); if (file_exists(_PS_ROOT_DIR_.'/error500.html')) echo file_get_contents(_PS_ROOT_DIR_.'/error500.html'); } 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 ['.$arg."]\n";
			print_r($value);
			echo "\n";
		}
		echo '
'; } }