示例#1
0
文件: Converter.php 项目: seytar/psx
 public function convert(Exception $exception)
 {
     if ($this->isDebug === true) {
         if ($exception instanceof ErrorException) {
             $exception = $exception->getOriginException();
         }
         $title = get_class($exception);
         $message = $exception->getMessage() . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine();
         $trace = $exception->getTraceAsString();
         $context = '';
         if (is_file($exception->getFile())) {
             $offset = $exception->getLine() - ($this->contextSize + 1);
             $length = $this->contextSize * 2 + 1;
             $length = $offset < 0 ? $length + $offset : $length;
             $offset = $offset < 0 ? 0 : $offset;
             $lines = file($exception->getFile());
             $lines = array_slice($lines, $offset, $length);
             foreach ($lines as $number => $line) {
                 $lineNo = $offset + $number + 1;
                 if ($lineNo == $exception->getLine()) {
                     $context .= '<b>' . str_pad($lineNo, 4) . htmlspecialchars($line) . '</b>';
                 } else {
                     $context .= str_pad($lineNo, 4) . htmlspecialchars($line);
                 }
             }
         }
     } else {
         // if we have an display exception we can use the error message else
         // we hide the message with an general error message
         if ($exception instanceof DisplayException) {
             $message = $exception->getMessage();
         } else {
             $message = 'The server encountered an internal error and was unable to complete your request.';
         }
         $title = 'Internal Server Error';
         $trace = null;
         $context = null;
     }
     $record = new ExceptionRecord();
     $record->setSuccess(false);
     $record->setTitle($title);
     $record->setMessage($message);
     $record->setTrace($trace);
     $record->setContext($context);
     return $record;
 }
示例#2
0
文件: SoapTest.php 项目: seytar/psx
    public function testWriteExceptionRecord()
    {
        $record = new ExceptionRecord();
        $record->setSuccess(false);
        $record->setTitle('An error occured');
        $record->setMessage('Foobar');
        $record->setTrace('Foo');
        $record->setContext('Bar');
        $writer = new Soap('http://foo.bar');
        $writer->setRequestMethod('GET');
        $actual = $writer->write($record);
        $expect = <<<TEXT
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
\t<soap:Fault>
\t  <faultcode>soap:Server</faultcode>
\t  <faultstring>Foobar</faultstring>
\t  <detail>
\t    <error xmlns="http://foo.bar">
\t      <success>false</success>
\t      <title>An error occured</title>
\t      <message>Foobar</message>
\t      <trace>Foo</trace>
\t      <context>Bar</context>
\t    </error>
\t  </detail>
\t</soap:Fault>
  </soap:Body>
</soap:Envelope>
TEXT;
        $this->assertXmlStringEqualsXmlString($expect, $actual);
    }