Last active
June 15, 2018 08:09
This file contains 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 | |
shell_exec('rm -rf folder'); | |
unlink('iterator.phar'); | |
unlink('addfile.phar'); | |
mkdir('folder', 0755); | |
mkdir('folder/sub', 0755); | |
file_put_contents('folder/sub/a.txt', 'a'); | |
file_put_contents('folder/sub/b.txt', 'b'); | |
file_put_contents('folder/sub/c.txt', 'c'); | |
file_put_contents('test', <<<'PHP' | |
<?php | |
print_r(__DIR__); | |
var_dump(scandir(__DIR__.'/folder/sub')); | |
?> | |
PHP | |
); | |
// create with buildFromIterator | |
$phar = new Phar('iterator.phar', 0, 'iterator.phar'); | |
$phar->addFile('test', 'test'); | |
$phar->buildFromIterator( | |
new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator(__DIR__.'/folder')), __DIR__); | |
$stub = <<<'PHP' | |
<?php | |
Phar::mapPhar(); | |
include 'phar://iterator.phar/test'; | |
__HALT_COMPILER(); | |
PHP; | |
$phar->setStub($stub); | |
print "Built ".filesize('iterator.phar')."o in iterator.phar\n"; | |
// create with buildFromIterator | |
$phar = new Phar('addfile.phar', 0, 'addfile.phar'); | |
$phar->addFile('test', 'test'); | |
foreach( new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__.'/folder')) as $file => $c) { | |
if (basename($file) === '.') {continue; } | |
if (basename($file) === '..') {continue; } | |
$phar->addFile($file, str_replace(__DIR__, '', $file)); | |
} | |
$stub = <<<'PHP' | |
<?php | |
Phar::mapPhar(); | |
include 'phar://addfile.phar/test'; | |
__HALT_COMPILER(); | |
PHP; | |
$phar->setStub($stub); | |
print "Built ".filesize('addfile.phar')."o in addfile.phar\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run :
mkdir issuephar
cd issuephar
php test.php // (this gist).
php iterator.phar (errors)
php addfile.phar (displays folder content)