diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2020-04-28 19:36:59 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2020-04-28 19:36:59 +0200 |
commit | 5a307b0688f394156951af57efb54d65e94878c0 (patch) | |
tree | af24d5ddd73ae3a1ffc12d5a93e4ce2de96b04f4 | |
parent | 6d61bbcc339df6d7094010e975050afdcfbbe530 (diff) | |
download | ratatoeskr-cms-5a307b0688f394156951af57efb54d65e94878c0.tar.gz ratatoeskr-cms-5a307b0688f394156951af57efb54d65e94878c0.tar.bz2 ratatoeskr-cms-5a307b0688f394156951af57efb54d65e94878c0.zip |
Add router script for php's builtin development server
-rw-r--r-- | php-cli-server-router.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/php-cli-server-router.php b/php-cli-server-router.php new file mode 100644 index 0000000..4d7c5c5 --- /dev/null +++ b/php-cli-server-router.php @@ -0,0 +1,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; |