. **/ $src_root = './src'; $phar_file = 'generate.phar'; $dataloader = [ 'build' => time(), 'version' => $argv[1] ]; $phar = new Phar($phar_file); $phar->startBuffering(); $main = $phar->createDefaultStub('generate.php'); $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src_root), RecursiveIteratorIterator::SELF_FIRST); foreach ($dir as $file) { if (preg_match('/\\.php$/i', $file)) { $phar->addFromString(substr($file, strlen($src_root) + 1), php_strip_whitespace($file)); } elseif (preg_match('/config\\.json$/i', $file)) { $phar->addFromString(substr($file, strlen($src_root) + 1), json_encode($dataloader + json_decode(file_get_contents($file), true))); } } $phar->setStub("#!/usr/bin/env php\n".$main); $phar->stopBuffering();