コード例 #1
0
ファイル: boot.php プロジェクト: yeaha/owl-site
function __ini_app(\Owl\Application $app)
{
    $app->middleware(function ($request, $response) {
        $start = microtime(true);
        yield;
        $use_time = (microtime(true) - $start) * 1000;
        $response->withHeader('x-run-time', (int) $use_time);
    });
    $router = new \Owl\Mvc\Router(['namespace' => '\\Controller']);
    $app->middleware(function ($request, $response) use($router) {
        $router->execute($request, $response);
    });
    $app->setExceptionHandler(function ($exception, $request, $response) {
        if ($exception instanceof \Owl\Http\Exception) {
            $status = $exception->getCode();
        } else {
            $status = 500;
            log_exception(get_logger('default'), $exception);
        }
        $response->withStatus($status);
        if (DEBUG) {
            foreach (__exception_headers($exception, 8) as $key => $value) {
                $response->withHeader($key, $value);
            }
        }
        if (!$request->isAjax()) {
            $view = new \Owl\Mvc\View(ROOT_DIR . '/View');
            $response->write($view->render('_error', ['exception' => $exception]));
        }
    });
    return $app;
}
コード例 #2
0
ファイル: boot.php プロジェクト: niceDreamer/owl
function __ini_app(\Owl\Application $app)
{
    $app->middleware(function ($request, $response) {
        $start = microtime(true);
        yield;
        $use_time = (microtime(true) - $start) * 1000;
        $response->setHeader('use-time', (int) $use_time . 'ms');
    });
    $router = new \Owl\Mvc\Router(['namespace' => '\\Controller']);
    $app->middleware(function ($request, $response) use($router) {
        $router->execute($request, $response);
    });
    $app->setExceptionHandler(function ($exception, $request, $response) {
        $status = 500;
        if ($exception instanceof \Owl\Http\Exception) {
            $status = $exception->getCode();
        }
        $response->setStatus($status);
        $view = new \Owl\Mvc\View(ROOT_DIR . '/View');
        $response->setBody($view->render('_error', ['exception' => $exception]));
    });
    return $app;
}