Example #1
0
<?php

define('BASE_PATH', str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath(dirname(__FILE__))));
require 'system/start.php';
$router = new Router();
$db = new BaseModel();
require 'app/start.php';
/*boot routes*/
$router->boot();
/*connect to mysql server*/
$db->connect();
$uri = $app['request']->getPathInfo();
/**
 * Append the URI to the Wordpress routes so it has priority
 */
$routes = RouteBuilder::make();
array_unshift($routes, $uri);
/**
 * Run our router to handle the closure/controller on the first route found and
 * put it in to the output variable.
 */
$routeInfo = $app['dispatcher']->dispatch($method, $routes);
if ($routeInfo[0] === FastRoute\Dispatcher::FOUND) {
    if ($routeInfo[3] === '404') {
        $app['response']->setStatusCode(404);
    }
    $content = Router::boot($routeInfo[1], $routeInfo[2], $app['request'], $app['response']);
    $app['event']->dispatch('routing.success');
} else {
    $app['event']->dispatch('routing.failure');
}
/**
 * Determine what to do with the output depending on what kind of data it is
 * and send it to the client
 */
foreach ($app_config['responseHandlers'] as $handler) {
    $handlerResponse = $handler::handle($content ?? null, $app['response']);
    if ($handlerResponse) {
        break;
    }
}
$handlerResponse->send();