/** * Displays a message in the text console. * * @param Exception $exception */ public static function showConsoleException($exception) { $isXTermColor = false; if (isset($_ENV['TERM'])) { foreach (array('256color') as $term) { if (preg_match('/' . $term . '/', $_ENV['TERM'])) { $isXTermColor = true; } } } $isSupportedShell = false; if ($isXTermColor) { if (isset($_ENV['SHELL'])) { foreach (array('bash', 'tcl') as $shell) { if (preg_match('/' . $shell . '/', $_ENV['SHELL'])) { $isSupportedShell = true; } } } } ScriptColor::setFlags($isSupportedShell && $isSupportedShell); $output = ""; $output .= ScriptColor::colorize(get_class($exception) . ': ', ScriptColor::RED, ScriptColor::BOLD); $message = str_replace("\"", "\\\"", $exception->getMessage()); $message .= ' (' . $exception->getCode() . ')'; $output .= ScriptColor::colorize($message, ScriptColor::WHITE, ScriptColor::BOLD); $output .= '\\n'; $output .= Highlight::getString(file_get_contents($exception->getFile()), 'console', array('firstLine' => $exception->getLine() - 3 < 0 ? $exception->getLine() : $exception->getLine() - 3, 'lastLine' => $exception->getLine() + 3)); $i = 1; $getcwd = getcwd(); foreach ($exception->getTrace() as $trace) { $output .= ScriptColor::colorize('#' . $i, ScriptColor::WHITE, ScriptColor::UNDERLINE); $output .= ' '; if (isset($trace['file'])) { $file = str_replace($getcwd, '', $trace['file']); $output .= ScriptColor::colorize($file . '\\n', ScriptColor::NORMAL); } $i++; } if ($isSupportedShell) { system('echo -e "' . $output . '"'); } else { echo $output; } }