aboutsummaryrefslogtreecommitdiff
path: root/php-cli-server-router.php
diff options
context:
space:
mode:
Diffstat (limited to 'php-cli-server-router.php')
-rw-r--r--php-cli-server-router.php34
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;