<?php
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri = rtrim($uri, '/');

if ($uri !== '' && file_exists(__DIR__ . $uri)) {
    return false;
}

$routes = [
    ''               => 'controllers/index.php',
    'rom'            => 'controllers/rom.php',
    'emuladores'     => 'controllers/emuladores.php',
];

if (isset($routes[$uri])) {
    require __DIR__ . '/' . $routes[$uri];
    return true;
}

if (preg_match('/^([A-Za-z0-9_-]+)\.php$/', ltrim($uri, '/'), $m)) {
    $file = __DIR__ . '/controllers/' . $m[1] . '.php';
    if (file_exists($file)) {
        require $file;
        return true;
    }
}

return false;
