3 * Phar stub file for phorkie. Handles startup of the .phar file.
9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2014 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://phorkie.sf.net/
14 if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
15 echo "Phar extension not avaiable\n";
19 $web = 'www/index.php';
21 $cli = 'scripts/index.php';
24 * Rewrite the HTTP request path to an internal file.
25 * Maps "" and "/" to "www/index.php".
27 * @param string $path Path from the browser, relative to the .phar
29 * @return string Internal path.
31 function rewritePath($path)
34 //we need a / to get the relative links on index.php work
35 if (!isset($_SERVER['REQUEST_SCHEME'])) {
36 $_SERVER['REQUEST_SCHEME'] = 'http';
38 $url = $_SERVER['REQUEST_SCHEME'] . '://'
39 . $_SERVER['HTTP_HOST']
40 . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
42 header('Location: ' . $url);
44 } else if ($path == '/') {
45 return 'www/index.php';
48 if (substr($path, -4) == '.css') {
49 header('Expires: ' . date('r', time() + 86400 * 7));
54 //Phar::interceptFileFuncs();
57 . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
59 Phar::webPhar(null, $web, null, array(), 'rewritePath');
61 //TODO: implement CLI script runner
62 echo "phorkie can only be used in the browser\n";