From bbe055e8c11da1ec0eddee461a31fb5acf382c92 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 4 Jul 2014 07:30:37 +0200 Subject: [PATCH 1/1] use rewrite map in .phar --- src/stub-phar.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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(); -- 2.30.2