|
14 | 14 | * example usage: php -S 127.0.0.41:8082 -t ./pub/ ./router.php
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -$debug = function($val){ |
18 |
| - return; |
19 |
| - if(is_array($val)){ |
20 |
| - $val = json_encode($val); |
| 17 | +/** |
| 18 | + * Set it to true to enable debug mode |
| 19 | + */ |
| 20 | +define('DEBUG_ROUTER', false); |
| 21 | + |
| 22 | +$debug = function ($val) { |
| 23 | + |
| 24 | + if (!DEBUG_ROUTER) { |
| 25 | + return; |
21 | 26 | }
|
| 27 | + |
| 28 | + if (is_array($val)) { |
| 29 | + $val = json_encode($val); |
| 30 | + } |
| 31 | + |
22 | 32 | echo 'debug: '.$val.PHP_EOL.'<br/>'.PHP_EOL;
|
23 | 33 | };
|
24 | 34 |
|
25 | 35 | /**
|
26 | 36 | * Caution, this is very experimental stuff
|
27 |
| - * no garant for working result |
28 |
| - * has tons of potencial big security holes |
| 37 | + * no guarantee for working result |
| 38 | + * has tons of potential big security holes |
29 | 39 | */
|
30 | 40 |
|
31 | 41 | if (php_sapi_name() === 'cli-server') {
|
|
42 | 52 | $debug($path);
|
43 | 53 | $debug($route);
|
44 | 54 |
|
45 |
| - if( $path["basename"] == 'favicon.ico' ){ |
| 55 | + if ($path["basename"] == 'favicon.ico') { |
46 | 56 | return false;
|
47 | 57 | }
|
48 | 58 |
|
49 | 59 | $debug($route);
|
50 | 60 | $debug(strpos($route, 'errors/default/css/'));
|
51 | 61 |
|
52 |
| - if(strpos($route, 'pub/errors/default/') === 0){ |
| 62 | + if (strpos($route, 'pub/errors/default/') === 0) { |
53 | 63 | $route = preg_replace('#pub/errors/default/#', 'errors/default/', $route, 1);
|
54 | 64 | }
|
55 | 65 |
|
56 | 66 | $debug($route);
|
57 | 67 |
|
58 |
| - |
59 |
| - if( |
| 68 | + if ( |
60 | 69 | strpos($route, 'media/') === 0 ||
|
61 | 70 | strpos($route, 'opt/') === 0 ||
|
62 | 71 | strpos($route, 'static/') === 0 ||
|
63 | 72 | strpos($route, 'errors/default/css/') === 0 ||
|
64 | 73 | strpos($route, 'errors/default/images/') === 0
|
65 |
| - ){ |
| 74 | + ) { |
66 | 75 | $magentoPackagePubDir = __DIR__."/../pub";
|
67 | 76 |
|
68 | 77 | $file = $magentoPackagePubDir.'/'.$route;
|
69 | 78 | $debug($file);
|
70 |
| - if(file_exists($file)){ |
71 |
| - $debug('file exists'); |
72 |
| - return false; |
73 |
| - }else{ |
74 |
| - $debug('file exists not'); |
75 |
| - if(strpos($route, 'static/') === 0){ |
| 79 | + if (file_exists($file)) { |
| 80 | + $debug('file exists'); |
| 81 | + return false; |
| 82 | + } else { |
| 83 | + $debug('file does not exist'); |
| 84 | + if (strpos($route, 'static/') === 0) { |
76 | 85 | $route = preg_replace('#static/#', '', $route, 1);
|
77 | 86 | $_GET['resource'] = $route;
|
78 | 87 | include($magentoPackagePubDir.'/static.php');
|
79 | 88 | exit;
|
80 |
| - }elseif(strpos($route, 'media/') === 0){ |
| 89 | + } elseif (strpos($route, 'media/') === 0) { |
81 | 90 | include($magentoPackagePubDir.'/get.php');
|
82 | 91 | exit;
|
83 | 92 | }
|
84 | 93 | }
|
85 | 94 | }
|
86 | 95 |
|
87 |
| -header('HTTP/1.0 404 Not Found'); |
88 |
| - |
| 96 | + header('HTTP/1.0 404 Not Found'); |
89 | 97 | }
|
0 commit comments