Skip to content

Instantly share code, notes, and snippets.

@chernomyrdin
Created March 16, 2015 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chernomyrdin/71188d751b3356f39e48 to your computer and use it in GitHub Desktop.
Save chernomyrdin/71188d751b3356f39e48 to your computer and use it in GitHub Desktop.
Make phar from laravel app
<?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