require 'vendor/autoload.php'; use Phine\Phar\Builder, Phine\Phar\Stub; $skip_if_found = ['/.git', '/.svn', '/smarty/documentation', '/smarty/development', '/tests', '/Tests']; $source_path_strlen = strlen(__DIR__); $builder = Builder::create($phar_path); $builder->addFile(__DIR__ . '/LICENSE', 'LICENSE'); $builder->addFile(__DIR__ . '/VERSION', 'VERSION'); foreach (['bin', 'src', 'vendor'] as $dir_to_add) { /** * @var RecursiveDirectoryIterator[] $iterator */ foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/' . $dir_to_add, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) { $pathname = $item->getPathname(); $short_pathname = substr($pathname, $source_path_strlen + 1); foreach ($skip_if_found as $what) { if (strpos($pathname, $what) !== false) { continue 2; } } if ($item->isDir()) { $builder->addEmptyDir($short_pathname); } elseif ($item->isFile()) { $builder->addFile($pathname, $short_pathname); } print "Adding {$short_pathname}\n"; } } $builder->setStub(Stub::create()->mapPhar('shade.phar')->addRequire('bin/shade.php')->getStub()); print "\nRunning composer install...\n\n"; shell_exec('composer install'); die("\n" . basename($phar_path) . ' created. SHA1 checksum: ' . sha1_file($phar_path) . "\n");
<?php require 'libraries/autoload.php'; use Phine\Phar\Builder; use Phine\Phar\Stub; @unlink('manialive.phar'); $builder = Builder::create('manialive.phar'); class ManiaLiveIterator extends RecursiveFilterIterator { public function accept() { $excludeFiles = array('.git', 'config.ini'); $path = explode(DIRECTORY_SEPARATOR, $this->current()->getPath()); return !in_array('.git', $path, true) && !in_array($this->current()->getFilename(), $excludeFiles); } } $iterator = new RecursiveIteratorIterator(new ManiaLiveIterator(new RecursiveDirectoryIterator(__DIR__, RecursiveDirectoryIterator::SKIP_DOTS)), RecursiveIteratorIterator::LEAVES_ONLY); $builder->buildFromIterator($iterator, __DIR__); $builder->setStub(Stub::create()->mapPhar('manialive.phar')->addRequire('bootstrapper.php')->getStub());
<?php require './vendor/autoload.php'; use Phine\Phar\Builder; use Phine\Phar\Stub; // create a new Phar instance $builder = Builder::create('./build/GettyImagesApi.phar'); $builder->buildFromDirectory('./src'); $builder->setStub(Stub::create()->addRequire('GettyImages_Client.php')->mapPhar("GettyImagesApi.phar")->selfExtracting()->getStub());