Skip to content

Instantly share code, notes, and snippets.

@spekkionu
Created April 5, 2017 22:47
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 spekkionu/692aae67292fbd4a8138a66b5c1bb3c7 to your computer and use it in GitHub Desktop.
Save spekkionu/692aae67292fbd4a8138a66b5c1bb3c7 to your computer and use it in GitHub Desktop.
plates phar
<?php
$srcRoot = realpath(__DIR__."/vendor");
$buildRoot = realpath(__DIR__);
class MyRecursiveFilterIterator extends RecursiveFilterIterator {
public function accept() {
if(!$this->current()->isFile()){
return true;
}
if(!in_array($this->current()->getExtension(), ['php'])){
return false;
}
$root = realpath(__DIR__."/vendor");
$path = $this->current()->getRealPath();
$path = preg_replace('/^'.preg_quote($root . DIRECTORY_SEPARATOR, '/').'/', '', $path);
if(preg_match('/^autoload\\.php/', $path)){
return true;
}
if(preg_match('/^composer/', $path)){
return true;
}
if(preg_match("/^league\\/plates\\/src/", $path)){
return true;
}
return false;
}
}
$dirItr = new RecursiveDirectoryIterator($srcRoot, FilesystemIterator::SKIP_DOTS);
$filterItr = new MyRecursiveFilterIterator($dirItr);
$iterator = new RecursiveIteratorIterator($filterItr, RecursiveIteratorIterator::LEAVES_ONLY);
echo "Build phar\n";
$phar = new Phar($buildRoot.'/plates.phar', 0, 'plates.phar');
$phar->buildFromIterator($iterator, $srcRoot);
$phar->setStub($phar->createDefaultStub("autoload.php"));
exit("Build complete\n");
{
"require": {
"league/plates": "@stable"
},
"config": {
"preferred-install": "dist"
},
"prefer-stable": true,
"scripts": {
"post-update-cmd": "php build.php",
"post-install-cmd": "php build.php"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment