set expire header for css files in phar
[phancap.git] / src / phar-stub.php
index 04aa11190ad1f67383486de65108c2f0bd5f9d8d..b5cdf4d8f43165567d82fa1a0dfa3b9efe3f930b 100644 (file)
@@ -28,25 +28,35 @@ $web = 'www/index.php';
  */
 function rewritePath($path)
 {
-    if ($path == '' || $path == '/') {
+    if ($path == '') {
+        //we need a / to get the relative links on index.php work
+        if (!isset($_SERVER['REQUEST_SCHEME'])) {
+            $_SERVER['REQUEST_SCHEME'] = 'http';
+        }
+        $url = $_SERVER['REQUEST_SCHEME'] . '://'
+            . $_SERVER['HTTP_HOST']
+            . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
+            . '/';
+        header('Location: ' . $url);
+        exit(0);
+    } else if( $path == '/') {
         return 'www/index.php';
-    } else if ($path == '/get' || $path == '/get.php') {
-        return 'www/get.php';
-    } else if ($path == '/setup' || $path == '/setup.php') {
-        return 'www/setup.php';
     }
-    return $path;
+
+    if (substr($path, -4) == '.css') {
+        header('Expires: ' . date('r', time() + 86400 * 7));
+    }
+    return 'www' . $path;
 }
 
-//Phar::interceptFileFuncs();
 set_include_path(
     'phar://' . __FILE__
     . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
 );
 Phar::webPhar(null, $web, null, array(), 'rewritePath');
 
-//work around https://bugs.php.net/bug.php?id=52322
-//require 'phar://' . __FILE__ . '/' . $web;
-echo "cli\n";
+//TODO: implement CLI setup check
+echo "phancap can only be used in the browser\n";
+exit(1);
 __HALT_COMPILER();
 ?>