public function error(LimeError $error) { $this->errors++; $message = sprintf("%s: %s\n(in %s on line %s)", $error->getType(), $error->getMessage(), $this->stripBaseDir($error->getFile()), $error->getLine()); $this->printer->printLargeBox($message, LimePrinter::ERROR); $this->printer->printLine('Exception trace:', LimePrinter::COMMENT); $this->printTrace(null, $error->getFile(), $error->getLine()); foreach ($error->getTrace() as $trace) { // hide the part of the trace that is responsible for getting the // annotations to work if (strpos($trace['function'], '__lime_annotation_') === 0 && !$this->options['verbose']) { break; } if (array_key_exists('class', $trace)) { $method = sprintf('%s%s%s()', $trace['class'], $trace['type'], $trace['function']); } else { $method = sprintf('%s()', $trace['function']); } if (array_key_exists('file', $trace)) { $this->printTrace($method, $trace['file'], $trace['line']); } else { $this->printTrace($method); } } $this->printer->printLine(''); }
private function printError(LimeError $error) { $message = sprintf("%s: %s", $error->getType(), $error->getMessage()); if ($error->getFile()) { $message .= sprintf("\n(in %s on line %s)", $this->stripBaseDir($error->getFile()), $error->getLine()); } if ($error->getType() == 'Warning' || $error->getType() == 'Notice') { $lineStyle = LimePrinter::WARNING; } else { $lineStyle = LimePrinter::ERROR; } $this->printer->printLargeBox($message, $lineStyle); if (is_readable($error->getFile())) { $this->printer->printLine('Source code:', LimePrinter::COMMENT); $file = fopen($error->getFile(), 'r'); $indentation = strlen($error->getLine() + 5) + 4; $i = 1; $l = $error->getLine() - 2; while ($i < $l) { fgets($file); ++$i; } while ($i < $l + 5) { $line = rtrim(fgets($file), "\n"); $line = ' ' . $i . '. ' . wordwrap($line, 80 - $indentation, "\n" . str_repeat(' ', $indentation)); $lines = explode("\n", $line); $style = $i == $error->getLine() ? $lineStyle : null; foreach ($lines as $line) { $this->printer->printLine(str_pad($line, 80, ' '), $style); } ++$i; } fclose($file); $this->printer->printLine(''); } if (count($error->getInvocationTrace()) > 0) { $this->printer->printLine('Invocation trace:', LimePrinter::COMMENT); foreach ($error->getInvocationTrace() as $i => $trace) { $this->printer->printLine(' ' . ($i + 1) . ') ' . $trace); } $this->printer->printLine(''); } if (count($error->getTrace()) > 0) { $this->printer->printLine('Exception trace:', LimePrinter::COMMENT); $this->printTrace(null, $error->getFile(), $error->getLine()); foreach ($error->getTrace() as $trace) { if (array_key_exists('class', $trace)) { $method = sprintf('%s%s%s()', $trace['class'], $trace['type'], $trace['function']); } else { $method = sprintf('%s()', $trace['function']); } if (array_key_exists('file', $trace)) { $this->printTrace($method, $trace['file'], $trace['line']); } else { $this->printTrace($method); } } $this->printer->printLine(''); } }