35 lines
877 B
PHP
35 lines
877 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', '1');
|
|
|
|
session_start();
|
|
|
|
require __DIR__ . '/../src/helpers.php';
|
|
require r('config/config.php');
|
|
|
|
require r('vendor/autoload.php');
|
|
$routes = require r('config/routes.php');
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
|
|
// detect base path
|
|
$scriptName = dirname($_SERVER['SCRIPT_NAME']); // e.g. /my32bctest/public
|
|
$requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
|
|
// format request for router
|
|
$path = '/' . ltrim(str_replace($scriptName, '', $requestUri), '/');
|
|
|
|
foreach ($routes as [$verb, $routePath, $handler]) {
|
|
if ($method === $verb && $path === $routePath) {
|
|
[$class, $action] = explode('@', $handler);
|
|
$fqcn = 'Cafe32\\My32bc\\Controller\\' . $class;
|
|
(new $fqcn())->$action();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
http_response_code(404);
|
|
echo 'Not found';
|
|
|