From cb96273d9e57cf57eaab4015b46a4e0b43cc1c55 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 21 May 2014 07:48:02 +0200 Subject: [PATCH] first work on .phar --- .gitignore | 12 +++++---- build.xml | 47 +++++++++++++++++++++++++++++++--- src/stub-phar.php | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/stub-phar.php diff --git a/.gitignore b/.gitignore index 8010ba3..53196ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -README.html -repos -data/config.php -build.properties -dist +/README.html +/repos +/data/config.php +/build.properties +/dist /lib/ +/www/*.phar +/www/*.phar.bz2 diff --git a/build.xml b/build.xml index bb7b1a0..a7682e3 100644 --- a/build.xml +++ b/build.xml @@ -8,8 +8,8 @@ --> - - + + + @@ -57,14 +58,54 @@ Version 0.3.0 - 2012-09-27 + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + diff --git a/src/stub-phar.php b/src/stub-phar.php new file mode 100644 index 0000000..72e367d --- /dev/null +++ b/src/stub-phar.php @@ -0,0 +1,65 @@ + + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://phorkie.sf.net/ + */ +if (!in_array('phar', stream_get_wrappers()) || !class_exists('Phar', false)) { + echo "Phar extension not avaiable\n"; + exit(255); +} + +$web = 'www/index.php'; +//FIXME +$cli = 'scripts/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 == '') { + //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'; + } + + if (substr($path, -4) == '.css') { + header('Expires: ' . date('r', time() + 86400 * 7)); + } + return $path; +} + +//Phar::interceptFileFuncs(); +set_include_path( + 'phar://' . __FILE__ + . PATH_SEPARATOR . 'phar://' . __FILE__ . '/lib/' +); +Phar::webPhar(null, $web, null, array(), 'rewritePath'); + +//TODO: implement CLI script runner +echo "phorkie can only be used in the browser\n"; +exit(1); +__HALT_COMPILER(); +?> -- 2.30.2