Created
March 16, 2015 13:25
-
-
Save chernomyrdin/71188d751b3356f39e48 to your computer and use it in GitHub Desktop.
Make phar from laravel app
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 | |
class UserFilter extends FilterIterator { | |
public function accept () { | |
$file = $this->getInnerIterator()->current(); | |
$path = explode("/", $file, 3); | |
if (count($path) < 2 or !in_array($path[1], array('app','bootstrap','vendor'))) return FALSE; | |
elseif ("/." == substr($file, -2)) return FALSE; | |
elseif ("/.." == substr($file, -3)) return FALSE; | |
# echo $file, PHP_EOL; | |
return TRUE; | |
} | |
} | |
if (is_file("sample.pahr")) unlink("sample.pahr"); | |
$phar = new Phar("sample.phar"); | |
$phar->setAlias("Sample"); | |
$dir = '.'; | |
$phar->buildFromIterator( | |
new UserFilter( | |
new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($dir) | |
) | |
), | |
$dir | |
); | |
$phar->setStub('<?php | |
# spl_autoload_register(function ($class) { | |
# echo "stubAutoload($class)\n"; | |
# return FALSE; | |
# }); | |
try { | |
Phar::mapPhar(); | |
} | |
catch (PharException $e) { | |
error_log("$e"); | |
exit(1); | |
} | |
__HALT_COMPILER();' | |
); | |
# command line: php -dphar.readonly=0 sample-phar.php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment