Exemple #1
0
        // Render the document.
        $document->render();
        // Render the document into the template, and display it.
        $output = $app->view()->render($document->template, ['page' => ['title' => $document->header['title'], 'content' => $document->output, 'header' => $document->header]]);
        $app->halt(200, $output);
    } catch (Exceptions\NoContentException $e) {
        if ($app->get('app.settings.debug')) {
            throw $e;
        } else {
            $app->notFound();
        }
    } catch (\Exception $e) {
        if ($app->get('app.settings.debug')) {
            ldd($e);
        } else {
            $app->error($e);
        }
    }
});
// Handle missing resources.
$app->map('notFound', function () use($app) {
    $output = $app->view()->render($app->get('app.templates.error404.file'), []);
    $app->halt(404, $output);
});
// Handle internal errors.
$app->map('error', function (\Exception $e) use($app) {
    $output = $app->view()->render($app->get('app.templates.error404.file'), ['error' => $e]);
    $app->halt(500, $output);
});
// Start the app.
$app->start();
Exemple #2
0
$app->map('/:ver/:args+/', 'App::Authenticate', function ($ver, $args) use($app) {
    $main = __DIR__ . '/' . $ver . '/main.php';
    if (count($args)) {
        $_POST = $app->request->post();
        $app->arguments = array_values($args);
        $fname = array_shift($args);
        $method = strtolower($app->request->getMethod());
        array_unshift($args, $app);
        $app->api_version = $ver;
        if ($fname && file_exists($main)) {
            @(require_once $main);
            $func = $app->API_PREFIX . $method . '_' . $fname;
            if (!function_exists($func)) {
                $func = $app->API_PREFIX . 'all_' . $fname;
                if (!function_exists($func)) {
                    $func = $app->API_PREFIX . $fname;
                    if (!function_exists($func)) {
                        $func = null;
                    }
                }
            }
            if ($func) {
                call_user_func_array($func, $args);
                return true;
            }
        }
        //find external api
        if ($fname == 'login' || $app->auth->getUserId() !== null) {
            $fi = __DIR__ . '/' . $ver . '/' . $fname . '.php';
            if ($fname && file_exists($fi)) {
                @(require_once $fi);
                $func = $app->API_PREFIX . $method . '_' . $fname;
                if (!function_exists($func)) {
                    $func = $app->API_PREFIX . 'all_' . $fname;
                    if (!function_exists($func)) {
                        $func = $app->API_PREFIX . $fname;
                        if (!function_exists($func)) {
                            $func = null;
                        }
                    }
                }
                if ($func) {
                    call_user_func_array($func, $args);
                    return true;
                }
            }
        }
    }
    $app->notFound();
})->via('GET', 'POST')->conditions(array('ver' => 'v\\d{1,}([.]\\d{1,}){0,1}'));