From: Christian Weiske Date: Wed, 9 Apr 2014 20:10:42 +0000 (+0200) Subject: first work on phar version. redirection does not work yet X-Git-Tag: v0.1.0~21 X-Git-Url: https://git.cweiske.de/phancap.git/commitdiff_plain/984db1d7a451dadd76afc0e19438e56e73c7b732 first work on phar version. redirection does not work yet --- diff --git a/.gitignore b/.gitignore index d2f14ac..6396bc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /www/imgcache /data/phancap.config.php /README.html +/lib/ +/dist/ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..2bf0ce1 --- /dev/null +++ b/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/phar-stub.php b/src/phar-stub.php new file mode 100644 index 0000000..04aa111 --- /dev/null +++ b/src/phar-stub.php @@ -0,0 +1,52 @@ + + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/phancap.htm + */ +if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) { + echo "Phar extension not avaiable\n"; + exit(255); +} + +$web = 'www/index.php'; + +/** + * Rewrite the HTTP request path to an internal file. + * Maps "" and "/" to "www/index.php". + * + * @param string $path Path from the browser, relative to the .phar + * + * @return string Internal path. + */ +function rewritePath($path) +{ + if ($path == '' || $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; +} + +//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"; +__HALT_COMPILER(); +?> diff --git a/www/get.php b/www/get.php index 739aaf8..4cd2b3a 100644 --- a/www/get.php +++ b/www/get.php @@ -50,6 +50,7 @@ try { } } catch (\Exception $e) { //FIXME: handle 404s and so properly + //FIXME: send out error image if images are preferred header('HTTP/1.0 500 Internal Server error'); header('Content-type: text/plain'); echo $e->getMessage() . "\n";