Exemple #1
0
    // Handle errors in the framework
    set_error_handler('errorHandler');
    set_exception_handler('exceptionHandler');
    register_shutdown_function('shutdownHandler');
    // TODO: Move this into a Session class and use a config setting
    // to decide if sessions are allowed to auto-start.
    session_start();
    // Init (loads application by route)
    $app_classname = $app_ns . '\\Application';
    $app = new $app_classname();
    $router = new AltoRouter();
    $router->setBasePath($app->config('basepath'));
    $app->defineRoutes($router);
    $router_match = $router->match();
    if ($router_match && is_callable($router_match['target'])) {
        $response = call_user_func_array($router_match['target'], $router_match['params'])->getResponse();
    } else {
        throw new Booya\Exception\HttpException('Path ' . $_SERVER['REQUEST_URI'] . ' not found', 404);
    }
} catch (Booya\Exception\HttpException $ex) {
    http_response_code($ex->getCode());
    $response_class = $app->config('response_class');
    $response = new $response_class();
    $controller = new Booya\ErrorController($app, 'error', $ex->getCode(), $response);
    $controller->setHttpException($ex);
}
if (is_object($response) && $response instanceof Booya\Response) {
    $response->render();
} else {
    echo 'No response from application';
}