Exemple #1
0
 public function __toString()
 {
     $lines = [];
     foreach ($this as $item) {
         $lines[] = Php::toString($item);
     }
     return implode(PHP_EOL, $lines);
 }
Exemple #2
0
 public function __toString()
 {
     $lines = [];
     foreach ($this as $key => $value) {
         $value = Php::toString($value);
         $lines[] = "{$key}: {$value}";
     }
     return implode(PHP_EOL, $lines);
 }
 public function __toString()
 {
     $lines = [];
     foreach ($this->sort() as $key => $values) {
         $key = implode("-", array_map("ucfirst", explode("-", $key)));
         if (null === $values) {
             $lines[] = $key;
             continue;
         }
         if (!Php::isIterable($values)) {
             $values = (array) $values;
         }
         foreach ($values as $value) {
             $lines[] = "{$key}: {$value}";
         }
     }
     return implode("\n", $lines);
 }
Exemple #4
0
 protected function createLogPanel(Request $request, HtmlResponse $response)
 {
     $requestTimestamp = $this->getRequestDateTime()->format("U.u");
     $records = $this->getRecords();
     $content = '
         <table>
     ';
     foreach ($records as $record) {
         if ($record["level"] >= Logger::ERROR) {
             $class = "panadas-text-error";
         } elseif ($record["level"] >= Logger::WARNING) {
             $class = "panadas-text-warning";
         } else {
             $class = "panadas-text-info";
         }
         $offset = sprintf("%.3f", $record["datetime"]->format("U.u") - $requestTimestamp);
         $message = $response->esc($record["message"]);
         if ($record["context"]) {
             $context = [];
             foreach ($record["context"] as $key => $value) {
                 $context[] = "{$key}: " . Php::toString($value);
             }
             $message .= '
                 <br>
                 <small>' . $response->esc(implode("<br>", $context)) . '</small>
             ';
         }
         $content .= '
             <tr class="' . $response->escAttr($class) . '">
                 <td>' . $response->esc($offset) . 's</td>
                 <td>' . $response->esc($record["level_name"]) . '</td>
                 <td width="100%">' . $message . '</td>
             </tr>
         ';
     }
     $content .= "</table>";
     return ["label" => "Log", "counter" => count($records), "content" => $content];
 }
    protected function send(\Exception $exception)
    {
        $application = $this->getApplication();
        $response = new HtmlResponse($application);
        if (!$application->isDebugMode()) {
            $content = '
                <div class="jumbotron">
                    <h1>Error</h1>
                    <p>Sorry, we are unable to process your request right now. Please try again later.</p>
                </div>
            ';
        } else {
            $path = $exception->getFile();
            try {
                $path = $application->getRelativePath($path);
            } catch (\Exception $ignore) {
            }
            $trace = $exception->getTrace();
            $index = count($trace);
            $traceContent = null;
            foreach ($trace as $line) {
                if (!array_key_exists("class", $line)) {
                    $line["class"] = null;
                }
                if (!array_key_exists("type", $line)) {
                    $line["type"] = null;
                }
                if (!array_key_exists("function", $line)) {
                    $line["function"] = null;
                }
                if (array_key_exists("args", $line)) {
                    array_walk($line["args"], function (&$arg) {
                        $arg = Php::toString($arg);
                    });
                    $line["args"] = implode(", ", $line["args"]);
                } else {
                    $line["args"] = null;
                }
                if (array_key_exists("file", $line)) {
                    try {
                        $line["file"] = $application->getRelativePath($line["file"]);
                    } catch (\Exception $ignore) {
                    }
                } else {
                    $line["file"] = null;
                }
                if (!array_key_exists("line", $line)) {
                    $line["line"] = null;
                }
                $traceContent .= sprintf('
                        <tr>
                            <td><span class="badge"><small>%d</small></span></td>
                            <td>
                                <small>
                                    <kbd>%s%s%s(<span class="text-muted">%s</span>)</kbd>
                                    <br>
                                    <code>%s:%d</code>
                                </small>
                            </td>
                        </tr>
                    ', $response->esc($index), $response->esc($line["class"]), $response->esc($line["type"]), $response->esc($line["function"]), $response->esc($line["args"]), $response->esc($line["file"]), $response->esc($line["line"]));
                $index--;
            }
            $content = <<<CONTENT
                <div class="jumbotron">
                    <h1>Exception</h1>
                </div>
                <div class="alert alert-danger">
                    <kbd>{$response->esc($exception->getMessage())}</kbd>
                </div>
                <dl class="dl-horizontal">
                    <dt>File</dt>
                    <dd><kbd>{$response->esc($path)}:{$response->esc($exception->getLine())}</kbd></dd>
                    <dt>Type</dt>
                    <dd><kbd>{$response->esc(get_class($exception))}</kbd></dd>
                    <dt>Code</dt>
                    <dd><kbd>{$response->esc($exception->getCode())}</kbd></dd>
                </dl>
                <h3>Trace</h3>
                <table class="table table-striped">
                    {$traceContent}
                </table>
CONTENT;
        }
        return $response->setStatusCode(500)->render($content)->send();
    }