blog-app/core/Bootstrap.php
2021-11-13 14:19:55 +08:00

36 lines
845 B
PHP

<?php
session_start();
header("X-Frame-Options: DENY");
if (! isset($_SESSION['_token'])) {
$_SESSION['_token'] = Illuminate\Support\Str::random(40);
}
use Phroute\Phroute\Dispatcher;
use Phroute\Phroute\Exception\HttpMethodNotAllowedException;
use Phroute\Phroute\Exception\HttpRouteNotFoundException;
use Phroute\Phroute\RouteCollector;
use Phroute\Phroute\RouteParser;
$route = new RouteCollector(new RouteParser);
require 'Routes.php';
$dispatcher = new Dispatcher($route->getData());
try {
$response = $dispatcher->dispatch(
$_SERVER['REQUEST_METHOD'],
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
echo $response;
} catch (HttpRouteNotFoundException $e) {
header('Location: /404');
die();
} catch (HttpMethodNotAllowedException $e) {
header('HTTP/1.0 403 Forbidden');
die();
}