-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-routing.php
63 lines (35 loc) · 1.1 KB
/
dev-routing.php
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* I actually learned something about php's internal server with this file.
* If you return false for a file that exists, php will default to
* resolve it an return it.
*/
$root = $_SERVER['DOCUMENT_ROOT'];
$path = '/' . ltrim(parse_url(urldecode($_SERVER['REQUEST_URI']))['path'], '/');
if (is_dir($root . $path)) {
$index = __DIR__ . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . 'index.php';
if (file_exists($index)) {
require_once $index;
} else {
require_once __DIR__ . DIRECTORY_SEPARATOR . '/index.php';
}
exit;
}
if (file_exists($root . $path)) {
// Runs PHP file if it exists
if (str_ends_with($path, '.php')) {
chdir(dirname($root . $path));
if (false === include $root . $path) {
error_log('Failed including file :: ' . $root . $path . PHP_EOL);
exit(1);
}
return true;
}
$fp = fopen($root . $path, 'rb');
fpassthru($fp);
fclose($fp);
return true;
}
// Otherwise, run `index.php`
chdir($root);
require_once __DIR__ . DIRECTORY_SEPARATOR . 'index.php';