forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.php
93 lines (77 loc) · 2.58 KB
/
router.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* this is a router file for the php Built-in web server
* https://secure.php.net/manual/en/features.commandline.webserver.php
*
* It provides the same "rewrites" as the .htaccess for apache,
* or the nginx.conf.sample for nginx.
*
* example usage: php -S 127.0.0.41:8082 -t ./pub/ ./router.php
*/
/**
* Set it to true to enable debug mode
*/
define('DEBUG_ROUTER', false);
$debug = function ($val) {
if (!DEBUG_ROUTER) {
return;
}
if (is_array($val)) {
$val = json_encode($val);
}
echo 'debug: ' . $val . PHP_EOL . '<br/>' . PHP_EOL;
};
/**
* Note: the code below is experimental and not intended to be used outside development environment.
* The code is protected against running outside of PHP built-in web server.
*/
if (php_sapi_name() === 'cli-server') {
$debug($_SERVER["REQUEST_URI"]);
if (preg_match('/^\/(index|get|static)\.php(\/)?/', $_SERVER["REQUEST_URI"])) {
return false; // serve the requested resource as-is.
}
$path = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$url = pathinfo(substr($_SERVER["REQUEST_URI"], 1));
$route = parse_url(substr($_SERVER["REQUEST_URI"], 1))["path"];
$debug($path);
$debug($route);
if ($path["basename"] == 'favicon.ico') {
return false;
}
$debug($route);
$debug(strpos($route, 'errors/default/css/'));
if (strpos($route, 'pub/errors/default/') === 0) {
$route = preg_replace('#pub/errors/default/#', 'errors/default/', $route, 1);
}
$debug($route);
if (strpos($route, 'media/') === 0 ||
strpos($route, 'opt/') === 0 ||
strpos($route, 'static/') === 0 ||
strpos($route, 'errors/default/css/') === 0 ||
strpos($route, 'errors/default/images/') === 0
) {
$magentoPackagePubDir = __DIR__ . "/../pub";
$file = $magentoPackagePubDir . '/' . $route;
$debug($file);
if (file_exists($file)) {
$debug('file exists');
return false;
} else {
$debug('file does not exist');
if (strpos($route, 'static/') === 0) {
$route = preg_replace('#static/#', '', $route, 1);
$_GET['resource'] = $route;
include $magentoPackagePubDir . '/static.php';
exit;
} elseif (strpos($route, 'media/') === 0) {
include $magentoPackagePubDir . '/get.php';
exit;
}
}
}
header('HTTP/1.0 404 Not Found');
}