aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-07-04 07:30:37 +0200
committerChristian Weiske <cweiske@cweiske.de>2014-07-04 07:30:37 +0200
commitbbe055e8c11da1ec0eddee461a31fb5acf382c92 (patch)
treed651fb888bc5d724bfb9748935b313e5be9e32e3 /src
parent8c586a69c21bfa036193b6ae6bfd5fd28dd7596f (diff)
downloadphorkie-bbe055e8c11da1ec0eddee461a31fb5acf382c92.tar.gz
phorkie-bbe055e8c11da1ec0eddee461a31fb5acf382c92.zip
use rewrite map in .phar
Diffstat (limited to 'src')
-rw-r--r--src/stub-phar.php32
1 files 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();