Created
January 24, 2019 13:17
-
-
Save stefpe/cbc4db73e018354214a67aea2f3587c1 to your computer and use it in GitHub Desktop.
phar build file
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
| <?php | |
| $dir = dirname(__FILE__); | |
| $exclude = [ | |
| 'bin', | |
| 'build', | |
| 'data', | |
| 'docs', | |
| 'docs-api', | |
| 'tests', | |
| '.gitattributes', | |
| '.gitignore', | |
| '.travis.yml', | |
| 'composer.json', | |
| 'composer.json.dev', | |
| 'composer.lock', | |
| 'composer.phar', | |
| 'phpcs.xml', | |
| 'phpdoc.xml', | |
| 'phpunit.xml.dist', | |
| 'README.md', | |
| '.git', | |
| '.idea', | |
| 'build.php' | |
| ]; | |
| $filter = function ($file, $key, $iterator) use ($exclude) { | |
| if ($iterator->hasChildren() && !in_array($file->getFilename(), $exclude)) { | |
| return true; | |
| } | |
| return $file->isFile() && !in_array($file->getFilename(), $exclude); | |
| }; | |
| $iterator = new RecursiveIteratorIterator( | |
| new RecursiveCallbackFilterIterator( | |
| new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), | |
| $filter | |
| ) | |
| ); | |
| $phar = new Phar("runner.phar"); | |
| $phar->setSignatureAlgorithm(\Phar::SHA1); | |
| $phar->startBuffering(); | |
| $phar->buildFromIterator($iterator, $dir); | |
| //default executable | |
| $phar->setStub( | |
| "#!/usr/bin/php \n" . $phar->createDefaultStub('init.php') | |
| ); | |
| $phar->stopBuffering(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment