<?php

/**
 * Dev-server router for `php -S` previews of the PPPHP app.
 *
 * The built-in server calls this for every request. Existing static files under
 * public/ are served as-is (return false); everything else is routed through the
 * front controller at public/index.php.
 */

$uri = urldecode((string) parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH));
$public = __DIR__ . '/public';
$target = $public . $uri;

// Let the built-in server serve a real static file (asset, image, etc.) directly.
if ($uri !== '/' && is_file($target)) {
    return false;
}

// Everything else → the front controller.
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SCRIPT_FILENAME'] = $public . '/index.php';
require $public . '/index.php';
