Created
September 7, 2017 01:09
-
-
Save liuxd/a16953dfeb25485bf0b574c009b7837d to your computer and use it in GitHub Desktop.
phar-packer.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| // php.ini : `phar.readonly = Off` | |
| $longopts = array( | |
| 'name::', | |
| 'path::', | |
| 'init:' | |
| ); | |
| $opts = getopt('', $longopts); | |
| $name = (isset($opts['name'])) ? $opts['name'] . '.phar' : ''; | |
| $path = (isset($opts['path'])) ? $opts['path'] : ''; | |
| $init = (isset($opts['init'])) ? $opts['init'] : 'index.php'; | |
| if (empty($name) && empty($path)) { | |
| echo <<<HELP | |
| phar packer 1.0 | |
| eg : php phar-packer.php --name=test --path=/project/to/ --init=index.php | |
| --name the name of the .phar file. | |
| --path the path of the project. | |
| --init the init file. | |
| HELP; | |
| echo PHP_EOL; | |
| return; | |
| } | |
| if (empty($name) || empty($path)) { | |
| echo 'Options invalid!' . PHP_EOL; | |
| return; | |
| } | |
| $phar = new Phar($name, 0); | |
| $phar->buildFromDirectory($path); | |
| $stub = <<< EOF | |
| <?php | |
| Phar::mapPhar('{$name}'); | |
| require 'phar://{$name}/{$init}'; | |
| __HALT_COMPILER(); | |
| EOF; | |
| $phar->setStub($stub); | |
| $phar->compressFiles(Phar::GZ); | |
| $phar->stopBuffering(); | |
| # end of this file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment