From 01ff51c39629443534026a26cd08de56b9ac18cd Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 27 Mar 2014 21:50:19 +0100 Subject: [PATCH] first work on .phar generation --- .gitignore | 4 ++- build.xml | 77 ++++++++++++++++++++++++++++++++++++++++++++++- src/phar-stub.php | 53 ++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/phar-stub.php diff --git a/.gitignore b/.gitignore index a09bfc2..c1892ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ data/config.php www/test.htm -lib/simplepie/* +lib/* +/dist/ +/bin/phar-stapibas.php diff --git a/build.xml b/build.xml index 5b7513c..472e1ed 100644 --- a/build.xml +++ b/build.xml @@ -1,5 +1,80 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/phar-stub.php b/src/phar-stub.php new file mode 100644 index 0000000..b1da1cf --- /dev/null +++ b/src/phar-stub.php @@ -0,0 +1,53 @@ + + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/bdrem.htm + */ +if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) { + echo "Phar extension not avaiable\n"; + exit(255); +} + +$web = 'www/index.php'; +$cli = 'bin/phar-stapibas.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'; + } + 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 +if (php_sapi_name() == 'cgi-fcgi') { + echo "Your PHP has a bug handling phar files :/\n"; + exit(10); +} + +require 'phar://' . __FILE__ . '/' . $cli; +__HALT_COMPILER(); +?> -- 2.30.2