diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-02-25 21:11:46 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-02-25 21:11:46 +0100 |
| commit | 5274821c5d92a9267ec992ec1d6757c4765ee5e8 (patch) | |
| tree | 8a1a163aee0021ad4599e873200df331a3eead29 | |
| parent | 400a6537534c4083b39debdd9e49032daf093813 (diff) | |
| download | bdrem-5274821c5d92a9267ec992ec1d6757c4765ee5e8.tar.gz bdrem-5274821c5d92a9267ec992ec1d6757c4765ee5e8.zip | |
script to generate phar file
| -rwxr-xr-x | bin/makephar.php | 31 | ||||
| -rw-r--r-- | src/phar-stub.php | 23 |
2 files changed, 54 insertions, 0 deletions
diff --git a/bin/makephar.php b/bin/makephar.php new file mode 100755 index 0000000..6089b0c --- /dev/null +++ b/bin/makephar.php @@ -0,0 +1,31 @@ +#!/usr/bin/env php +<?php +if (ini_get('phar.readonly') == 1) { + //re-run this script with phar writing activated + passthru(PHP_BINARY . ' -dphar.readonly=0 ' . escapeshellarg($argv[0])); + exit(); +} + +$pharfile = __DIR__ . '/../dist/bdrem-0.1.0.phar'; +if (file_exists($pharfile)) { + unlink($pharfile); +} +$phar = new Phar($pharfile, 0, 'bdrem.phar'); +$phar->startBuffering(); + +// add all files in the project +$phar->buildFromDirectory( + realpath(__DIR__ . '/../'), + '#' + . '^' . preg_quote(realpath(__DIR__ . '/../'), '#') + . '/(data/bdrem.config.php.dist|src/bdrem/|www/|README\.rst)' + . '#' +); + +//remove shebang from bin/bdrem.php +$bin = file_get_contents(__DIR__ . '/../bin/bdrem.php'); +$phar->addFromString('bin/bdrem.php', substr($bin, strpos($bin, "\n") + 1)); + +$phar->setStub(file_get_contents(__DIR__ . '/../src/phar-stub.php')); +$phar->stopBuffering(); +?> diff --git a/src/phar-stub.php b/src/phar-stub.php new file mode 100644 index 0000000..3c80130 --- /dev/null +++ b/src/phar-stub.php @@ -0,0 +1,23 @@ +<?php +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/bdrem.php'; + +function rewritePath($path) +{ + if ($path == '' || $path == '/') { + return 'www/index.php'; + } + return $path; +} + +//Phar::interceptFileFuncs(); +set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path()); +Phar::webPhar(null, $web, null, array(), 'rewritePath'); +include 'phar://' . __FILE__ . '/' . $cli; +__HALT_COMPILER(); +?> |
