From: Christian Weiske Date: Fri, 4 Jul 2014 05:30:37 +0000 (+0200) Subject: use rewrite map in .phar X-Git-Tag: v0.4.0~31 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/bbe055e8c11da1ec0eddee461a31fb5acf382c92?hp=8c586a69c21bfa036193b6ae6bfd5fd28dd7596f use rewrite map in .phar --- diff --git a/src/stub-phar.php b/src/stub-phar.php index 72e367d..ac82a38 100644 --- a/src/stub-phar.php +++ b/src/stub-phar.php @@ -45,10 +45,38 @@ function rewritePath($path) return 'www/index.php'; } - if (substr($path, -4) == '.css') { + $path = rewriteWithHtaccess($path); + + if (substr($path, -4) == '.css' || substr($path, -3) == '.js') { header('Expires: ' . date('r', time() + 86400 * 7)); } - return $path; + return 'www' . $path; +} + +function rewriteWithHtaccess($path) +{ + //remove the trailing slash / + $cpath = substr($path, 1); + $bFoundMatch = false; + $map = include(__DIR__ . '/../src/gen-rewritemap.php'); + foreach ($map as $pattern => $replace) { + if (preg_match($pattern, $cpath, $matches)) { + $bFoundMatch = true; + break; + } + } + if (!$bFoundMatch) { + return $path; + } + $newcpath = preg_replace($pattern, $replace, $cpath); + if (strpos($newcpath, '?') === false) { + return '/' . $newcpath; + } + list($cfile, $getParams) = explode('?', $newcpath, 2); + if ($getParams != '') { + parse_str($getParams, $_GET); + } + return '/' . $cfile; } //Phar::interceptFileFuncs();