3 * Phar stub file for bdrem. 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://cweiske.de/phancap.htm
14 if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) {
15 echo "Phar extension not avaiable\n";
19 $web = 'www/index.php';
22 * Rewrite the HTTP request path to an internal file.
23 * Maps "" and "/" to "www/index.php".
25 * @param string $path Path from the browser, relative to the .phar
27 * @return string Internal path.
29 function rewritePath($path)
32 //we need a / to get the relative links on index.php work
33 if (!isset($_SERVER['REQUEST_SCHEME'])) {
34 $_SERVER['REQUEST_SCHEME'] = 'http';
36 $url = $_SERVER['REQUEST_SCHEME'] . '://'
37 . $_SERVER['HTTP_HOST']
38 . preg_replace('/[?#].*$/', '', $_SERVER['REQUEST_URI'])
40 header('Location: ' . $url);
42 } else if( $path == '/') {
43 return 'www/index.php';
50 . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/'
52 Phar::webPhar(null, $web, null, array(), 'rewritePath');
54 //TODO: implement CLI setup check
55 echo "phancap can only be used in the browser\n";