Exemplo n.º 1
0
 public static function factory($code, $body = null, array $header = array())
 {
     $error = new static(\Lysine\HTTP::getStatusMessage($code), $code);
     $more = array();
     if ($body) {
         $more['body'] = $body;
     }
     if ($header) {
         $more['header'] = $header;
     }
     $error->setMore($more);
     return $error;
 }
Exemplo n.º 2
0
 protected function compileHeader()
 {
     $header = array();
     $header[] = \Lysine\HTTP::getStatusHeader($this->code ?: 200);
     foreach ($this->header as $key => $val) {
         $header[] = $val === null ? $key : $key . ': ' . $val;
     }
     return $header;
 }
Exemplo n.º 3
0
<?php

use Lysine\HTTP;
$__start__ = microtime(true);
set_exception_handler('__exception_handler');
try {
    $app = (require __DIR__ . '/config/boot.php');
    $response = $app->execute();
} catch (HTTP\Exception $exception) {
    Lysine\logger()->debug(HTTP::getStatusHeader($exception->getCode()));
    $response = __exception_response($exception->getCode(), $exception);
} catch (\Exception $exception) {
    $response = __exception_handler($exception, true);
}
$__runtime__ = round(microtime(true) - $__start__, 6);
$response->setHeader('X-Runtime: ' . $__runtime__ . 's')->execute();
if (!DEBUG && PHP_SAPI == 'fpm-fcgi') {
    fastcgi_finish_request();
}
////////////////////////////////////////////////////////////////////////////////
function __exception_handler($exception, $call = false)
{
    try {
        \Lysine\logger()->exception($exception);
        if (PHP_SAPI == 'cli') {
            echo $exception . PHP_EOL;
            exit(1);
        }
        $response = __exception_response(HTTP::INTERNAL_SERVER_ERROR, $exception);
        if ($call) {
            return $response;