Example #1
0
 protected function get(Request $request)
 {
     $response = new HtmlResponse($this->getApplication());
     $args = $this->getArgs();
     $statusCode = $args->get("statusCode");
     $message = $args->get("message");
     $title = "HTTP {$response->esc($statusCode)}";
     $title .= " <small>{$response->esc($response::getStatusMessage($statusCode))}</small>";
     if (null !== $message) {
         $message = "<div class=\"alert alert-danger\">{$response->esc($message)}</div>";
     }
     return $response->setStatusCode($statusCode)->render('
                 <div class="jumbotron">
                     <h1>' . $title . '</h1>
                 </div>
                 ' . $message . '
             ');
 }
Example #2
0
 protected function get(Request $request)
 {
     $args = $this->getArgs();
     $uri = $args->get("uri");
     if (null === $uri) {
         throw new \InvalidArgumentException("A URI must be provided");
     }
     $response = new HtmlResponse($this->getApplication());
     $response->setStatusCode($args->get("statusCode", 302))->getHeaders()->set("Location", $uri);
     return $response->render('
                 <div class="jumbotron">
                     <h1>Redirecting&hellip;</h1>
                     <p>
                         You are being redirected to
                         <a href="' . $response->escAttr($uri) . '">' . $response->esc($uri) . '</a>
                     </p>
                 </div>
             ');
 }
Example #3
0
 protected function get(Request $request)
 {
     $response = new HtmlResponse($this->getApplication());
     if ($request->isPost()) {
         $response->setStatusCode(401);
     }
     return $response->render('
             <div class="jumbotron">
                 <h1>Sign In</h1>
             </div>
             <form method="post" class="form-horizontal" role="form">
                 <div class="form-group">
                     <label for="username" class="col-sm-4 control-label">Username</label>
                     <div class="col-sm-4">
                         <input type="email" id="username" name="username" class="form-control">
                     </div>
                 </div>
                 <div class="form-group">
                     <label for="password" class="col-sm-4 control-label">Password</label>
                     <div class="col-sm-4">
                         <input type="password" id="password" name="password" class="form-control">
                     </div>
                 </div>
                 <div class="form-group">
                     <div class="col-sm-offset-4 col-sm-8">
                         <div class="checkbox">
                             <label><input type="checkbox" name="persist"> Remember me</label>
                         </div>
                     </div>
                 </div>
                 <div class="form-group">
                     <div class="col-sm-offset-4 col-sm-8">
                         <button type="submit" class="btn btn-default">Sign in</button>
                     </div>
                 </div>
             </form>
         ');
 }
Example #4
0
    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();
    }