aboutsummaryrefslogtreecommitdiff
path: root/php-cli-server-router.php
blob: a718cedce4ba77b6972f9e1ab9e81cebb5e70cbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

// Use this as the router script with php -S

if (php_sapi_name() !== 'cli-server') {
    die("Only for use in 'cli-server' SAPI");
}

// Enable some development flags
define("DEV_SKIP_APACHE_CHK", true);

[$_cliserver_path, $_cliserver_query] = array_pad(explode("?", $_SERVER["REQUEST_URI"], 2), 2, "");

if (!empty($_cliserver_query)) {
    parse_str($_cliserver_query, $_GET);
}
unset($_cliserver_query);

if (!file_exists(__DIR__ . $_cliserver_path)) {
    $_GET['action'] = ltrim($_cliserver_path, "/");
    unset($_cliserver_path);

    require_once(__DIR__ . "/ratatoeskr/main.php");
    ratatoeskr();
    exit;
}

if (preg_match('/\.php$/', $_cliserver_path)) {
    require_once(__DIR__ . $_cliserver_path);
    exit;
}

// Serve as-is
return false;