/** * Formats an error as a string * * @param \r8\iface\Error $error The error to format * @return String Returns the formatted error */ public function format(\r8\iface\Error $error) { $result = "<table class='r8-Error' " . "style='background: white; border: 2px solid #C00; border-collapse: collapse; margin: 5px auto; min-width: 500px;'>\n" . $this->formatTitle("Error Encountered") . $this->formatArray($this->toArray($error)); $details = $error->getDetails(); if (!empty($details)) { $result .= $this->formatTitle("Details") . $this->formatArray($details); } $formatter = new \r8\Backtrace\Formatter(new \r8\Backtrace\Formatter\HTML()); $result .= $this->formatTitle("Backtrace") . " <tr>\n" . " <td colspan='2' style='padding: 4px 8px;'>" . rtrim($formatter->format($error->getBacktrace())) . "\n" . " </td>\n" . " </tr>\n" . "</table>\n"; return $result; }
/** * Formats an error as a string * * @param \r8\iface\Error $error The error to format * @return String Returns the formatted error */ public function format(\r8\iface\Error $error) { $formatter = new \r8\Backtrace\Formatter(new \r8\Backtrace\Formatter\JSON()); $result = "{" . $this->formatArray($this->toArray($error)); $details = $error->getDetails(); if (!empty($details)) { $result .= ', "Details":{' . $this->formatArray($details) . '}'; } $result .= ', "Backtrace":' . $formatter->format($error->getBacktrace()) . "}"; return $result; }
/** * Formats an error as a string * * @param \r8\iface\Error $error The error to format * @return String Returns the formatted error */ public function format(\r8\iface\Error $error) { $formatter = new \r8\Backtrace\Formatter(new \r8\Backtrace\Formatter\Text()); $result = "\n" . "PHP Error Encountered!\n"; foreach ($this->toArray($error) as $key => $value) { $result .= $key . ": " . $value . "\n"; } $details = $error->getDetails(); if (!empty($details)) { $result .= "Details:\n"; foreach ($details as $key => $value) { if (!\r8\isBasic($value)) { $value = \r8\getDump($value); } $result .= " " . $key . ": " . $value . "\n"; } } $result .= "Backtrace:\n" . " " . str_replace("\n", "\n ", $formatter->format($error->getBacktrace())) . "\n\n"; return $result; }
public function testFormat() { $each = $this->getMock('\\r8\\iface\\Backtrace\\Formatter'); $each->expects($this->at(0))->method('prefix')->will($this->returnValue("[prefix]")); $each->expects($this->at(1))->method('event')->with($this->equalTo(2), $this->equalTo("function"), $this->equalTo(array("arg")), $this->equalTo("/example/file.php"), $this->equalTo(5050))->will($this->returnValue("[event2]")); $each->expects($this->at(2))->method('event')->with($this->equalTo(1), $this->equalTo("method"), $this->equalTo(array(1234)), $this->equalTo("/example/other.php"), $this->equalTo(1000))->will($this->returnValue("[event1]")); $each->expects($this->at(3))->method('main')->with($this->equalTo(0), $this->equalTo("/example/main.php"))->will($this->returnValue("[main]")); $each->expects($this->at(4))->method('suffix')->will($this->returnValue("[suffix]")); $format = new \r8\Backtrace\Formatter($each); $backtrace = new \r8\Backtrace(); $backtrace->pushEvent($this->getMockEvent("function", array("arg"), "/example/file.php", 5050)); $backtrace->pushEvent($this->getMockEvent("method", array(1234), "/example/other.php", 1000)); $backtrace->pushEvent($this->getMockMain("/example/main.php")); $this->assertSame("[prefix][event2][event1][main][suffix]", $format->format($backtrace)); }