aboutsummaryrefslogtreecommitdiff
path: root/php-cli-server-router.php
blob: 4d7c5c5cf03b1768043ab7f2602b40a6d890c61e (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;