Created
March 28, 2019 15:36
-
-
Save okayawright/c0eb8a61045a5a145734e8d45e18a47b to your computer and use it in GitHub Desktop.
Apache-like rules for the PHP internal CLI server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// public/cliserver.php (router script) | |
if (php_sapi_name() !== 'cli-server') { | |
die('this is only for the php development server'); | |
} | |
$path = $_SERVER['DOCUMENT_ROOT'].'/'.$_SERVER['SCRIPT_NAME']; | |
if (is_file($path)) { | |
return false; | |
} | |
function test($path) { | |
$file = $path . '/index.php'; | |
if ($path == '/' || $path=='\\' || is_file($_SERVER['DOCUMENT_ROOT'] . $file)) { | |
$_SERVER['SCRIPT_NAME'] = $file; | |
require ltrim(ltrim($file, '\\'), '/'); | |
return true; | |
} | |
$path = dirname($path); | |
return test($path); | |
} | |
test($_SERVER['SCRIPT_NAME']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment