public function compile($pharFile, $name = 'foo-app', array $files = array(), array $directories = array(), $stub_file, $base_path, $name_pattern = '*.php', $strip = TRUE) { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, $name); // The signature is automatically set unless we decide to compress. In that // case we have to manually set it. Setting to the default just in case. $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); // CLI Component files $iterator = Finder::create()->files()->name($name_pattern)->in($directories); // We need to set the adapter to use the PhpAdapter because we are working // with Phar files and the higher priority ones by default in symfony can // run into issues. //$iterator->removeAdapters(); //$iterator->addAdapter(new PhpAdapter()); $files = array_merge($files, iterator_to_array($iterator)); foreach ($files as $file) { $path = str_replace($base_path . '/', '', $file); if ($strip) { $phar->addFromString($path, php_strip_whitespace($file)); } else { $phar->addFromString($path, file_get_contents($file)); } } $phar->setStub(file_get_contents($stub_file)); $phar->stopBuffering(); // Not all systems support compressed Phars. For now disabling. // $phar->compressFiles(\Phar::GZ); chmod($pharFile, 0755); unset($phar); }
public function run() { $this->printTaskInfo('Creating {filename}', ['filename' => $this->filename]); $this->phar->setSignatureAlgorithm(\Phar::SHA1); $this->phar->startBuffering(); $this->printTaskInfo('Packing {file-count} files into phar', ['file-count' => count($this->files)]); $this->startProgressIndicator(); foreach ($this->files as $path => $content) { $this->phar->addFromString($path, $content); $this->advanceProgressIndicator(); } $this->phar->stopBuffering(); $this->advanceProgressIndicator(); if ($this->compress and in_array('GZ', \Phar::getSupportedCompression())) { if (count($this->files) > 1000) { $this->printTaskInfo('Too many files. Compression DISABLED'); } else { $this->printTaskInfo('{filename} compressed', ['filename' => $this->filename]); $this->phar = $this->phar->compressFiles(\Phar::GZ); } } $this->advanceProgressIndicator(); $this->stopProgressIndicator(); $this->printTaskSuccess('{filename} produced', ['filename' => $this->filename]); return Result::success($this, '', ['time' => $this->getExecutionTime()]); }
/** * Compresses a file or combination of files in the archive * @param array|zibo\library\filesystem\File $source File objects of the files to compress * @param zibo\library\filesystem\File $prefix The path for the files in the archive * @return null * @throws zibo\library\archive\exception\ArchiveException when no source or an invalid source has been provided * @throws zibo\library\archive\exception\ArchiveException when the archive could not be created * @throws zibo\library\archive\exception\ArchiveException when the phars could not be written due to the configuration of PHP */ public function compress($source, File $prefix = null) { if (!PhpPhar::canWrite()) { throw new ArchiveException('Phar library is not allowed to write phars. Check the PHP configuration for the phar.readonly setting.'); } if (empty($source)) { throw new ArchiveException('No files provided'); } $path = $this->file->getAbsolutePath(); $parent = $this->file->getParent(); $parent->create(); if (!is_array($source)) { $source = array($source); } try { $phar = new PhpPhar($path); } catch (UnexpectedValueException $e) { throw new ArchiveException('Could not open ' . $path); } if (!$phar->isWritable()) { throw new ArchiveException('Archive ' . $this->file->getAbsolutePath() . ' is not writable'); } $phar->startBuffering(); foreach ($source as $file) { if (!$file instanceof File) { throw new ArchiveException('Invalid source provided: ' . $file); } $this->compressFile($phar, $file, $prefix); } $phar->stopBuffering(); }
/** * Compiles composer into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'daux.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'daux.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); // Daux $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/../templates')->in(__DIR__); foreach ($finder as $file) { $this->addFile($phar, $file); } // Composer libraries $finder = new Finder(); $finder->files()->ignoreVCS(true)->exclude('Tests')->in(__DIR__ . '/../vendor/symfony/console')->in(__DIR__ . '/../vendor/symfony/polyfill-mbstring')->in(__DIR__ . '/../vendor/guzzlehttp/guzzle/src/')->in(__DIR__ . '/../vendor/guzzlehttp/ringphp/src/')->in(__DIR__ . '/../vendor/guzzlehttp/streams/src/')->in(__DIR__ . '/../vendor/league/commonmark/src/')->in(__DIR__ . '/../vendor/league/plates/src/')->in(__DIR__ . '/../vendor/react/promise/src/')->in(__DIR__ . '/../vendor/webuni/commonmark-table-extension/src/'); foreach ($finder as $file) { $this->addFile($phar, $file); } // Composer autoload $this->addComposer($phar); $this->addBinary($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../LICENSE'), false); chmod($pharFile, 0775); unset($phar); }
/** * Compiles the Cilex source code into one single Phar file. * * @param string $pharFile Name of the output Phar file */ public function compile($pharFile = 'cilex.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $process = new Process('git log --pretty="%h %ci" -n1 HEAD'); if ($process->run() > 0) { throw new \RuntimeException('The git binary cannot be found.'); } $this->version = trim($process->getOutput()); $phar = new \Phar($pharFile, 0, 'cilex.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..')->in(__DIR__ . '/../../vendor/pimple/pimple/lib')->in(__DIR__ . '/../../vendor/symfony/class-loader/Symfony/Component/ClassLoader')->in(__DIR__ . '/../../vendor/symfony/console/Symfony/Component/Console'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/ClassLoader.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_real.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_classmap.php')); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // $phar->compressFiles(\Phar::GZ); unset($phar); }
/** * Compiles composer into a single phar file * * @throws \RuntimeException * * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'swagger.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $this->version = trim(file_get_contents(dirname(__DIR__ . '/VERSION'))); $phar = new \Phar($pharFile, 0, 'swagger.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->notName('ClassLoader.php')->notPath('vendor/symfony')->notPath('tests')->in(dirname(__DIR__) . '/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(dirname(__DIR__) . '/vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo(dirname(__DIR__) . '/vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo(dirname(__DIR__) . '/vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo(dirname(__DIR__) . '/vendor/composer/ClassLoader.php')); $this->addSwaggerBin($phar); $phar->setStub($this->getStub()); $phar->stopBuffering(); $this->addFile($phar, new \SplFileInfo(dirname(__DIR__) . '/LICENSE-2.0.txt'), false); $this->addFile($phar, new \SplFileInfo(dirname(__DIR__) . '/VERSION'), false); unset($phar); }
public function compile($pharFile = 'already-extract.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'already-extract.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in(__DIR__ . '/../../vendor/symfony/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_psr4.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_real.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/ClassLoader.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/include_paths.php')); $this->addAlreadyExtractBin($phar); $phar->setStub($this->getStub()); $phar->stopBuffering(); unset($phar); }
/** * Compiles psysh into a single phar file * * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'psysh.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $this->version = Shell::VERSION; $phar = new \Phar($pharFile, 0, 'psysh.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->notName('Autoloader.php')->in(__DIR__ . '/..'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in(__DIR__ . '/../../vendor/symfony/')->in(__DIR__ . '/../../vendor/nikic/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/include_paths.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_real.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/ClassLoader.php')); $this->addPsyshBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false); unset($phar); }
/** * Compiles the Hydra source code into one single Phar file. * * @param string $pharFile Name of the output Phar file */ public function compile($pharFile = 'hydra.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'hydra.phar'); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.twig')->notName('PharCompiler.php')->exclude('Tests')->in('src')->in('views')->in('../../twig/twig/lib')->in('../../monolog/monolog/src')->in('../../symfony/http-kernel/Symfony/Component/HttpKernel/Exception')->in('../../symfony/http-foundation/Symfony/Component/HttpFoundation/File/MimeType')->in('../../symfony/http-foundation/Symfony/Component/HttpFoundation/File/Exception'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo('../../symfony/http-foundation/Symfony/Component/HttpFoundation/HeaderBag.php')); $this->addFile($phar, new \SplFileInfo('../../symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php')); $this->addFile($phar, new \SplFileInfo('../../symfony/http-foundation/Symfony/Component/HttpFoundation/ResponseHeaderBag.php')); $this->addFile($phar, new \SplFileInfo('../../symfony/http-kernel/Symfony/Component/HttpKernel/Debug/ErrorHandler.php')); $this->addFile($phar, new \SplFileInfo('../../symfony/http-kernel/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php')); $this->addFile($phar, new \SplFileInfo('../../autoload.php')); $this->addFile($phar, new \SplFileInfo('../../composer/ClassLoader.php')); $this->addFile($phar, new \SplFileInfo('../../composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo('../../composer/autoload_classmap.php')); $phar->setStub($this->getStub()); $phar->stopBuffering(); // $phar->compressFiles(\Phar::GZ); }
protected static function _build($conf) { $pathToPhar = $conf['path_to_phar']; $pharName = $conf['phar_name']; $srcPath = $conf['src_path']; $initModule = $conf['init_module']; $setup = $conf['setup']; $file = $pathToPhar . '/' . $pharName; if ($conf['delete_old_phar_onbuild'] && \file_exists($file)) { \unlink($file); } $falias = $pharName; $mapPhar = $pharName; $phar = new \Phar($file, 0, $falias); $phar->startBuffering(); $dir = $phar->buildFromDirectory($srcPath); $stub = '<?php ' . "\\Phar::mapPhar('{$falias}'); " . 'include ' . "'phar://{$falias}/{$initModule}'; " . "{$setup}" . '__HALT_COMPILER();'; $phar->setStub($stub); // // if (isset($conf['compress_pkg']) && $conf['compress_pkg'] == 'GZ') { $phar->compressFiles(\Phar::GZ); } // // $phar->stopBuffering(); }
/** * Makes a .phar packaged PocketMine plugin from a source directory. * * @param $sourcePath * @param $pharOutputLocation * @param $options * @return bool * @throws \Exception */ public static function makePlugin($sourcePath, $pharOutputLocation, $options) { /* Removes Leading '/' */ $sourcePath = rtrim(str_replace("\\", "/", realpath($sourcePath)), "/") . "/"; $description = self::getPluginDescription($sourcePath . "/plugin.yml"); if ($options & self::MAKEPLUGIN_REAL_OUTPUT_PATH) { $pharPath = $pharOutputLocation; } else { $pharPath = $pharOutputLocation . DIRECTORY_SEPARATOR . $description->getName() . "_v" . $description->getVersion() . ".phar"; } if (file_exists($pharPath)) { throw new \Exception("Phar path already exists"); } $phar = new \Phar($pharPath); $phar->setMetadata(["name" => $description->getName(), "version" => $description->getVersion(), "main" => $description->getMain(), "api" => $description->getCompatibleApis(), "depend" => $description->getDepend(), "description" => $description->getDescription(), "authors" => $description->getAuthors(), "website" => $description->getWebsite(), "creationDate" => time()]); $phar->setStub('<?php echo "PocketMine-MP plugin ' . $description->getName() . ' v' . $description->getVersion() . '\\nThis file has been generated using DevTools v' . self::getVersion() . ' at ' . date("r") . '\\n----------------\\n";if(extension_loaded("phar")){$phar = new \\Phar(__FILE__);foreach($phar->getMetadata() as $key => $value){echo ucfirst($key).": ".(is_array($value) ? implode(", ", $value):$value)."\\n";}} __HALT_COMPILER();'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourcePath)) as $file) { $path = ltrim(str_replace(["\\", $sourcePath], ["/", ""], $file), "/"); if ($path[0] === "." or strpos($path, "/.") !== false) { continue; } $phar->addFile($file, $path); } if ($options * self::MAKEPLUGIN_COMPRESS) { $phar->compressFiles(\Phar::GZ); } $phar->stopBuffering(); return true; }
public function compile() { if (file_exists('symfony.phar')) { unlink('symfony.phar'); } $phar = new \Phar('symfony.phar', 0, 'Symfony'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); // Files foreach ($this->getFiles() as $file) { $path = str_replace(__DIR__ . '/', '', $file); if (false !== strpos($file, '.php')) { $content = Kernel::stripComments(file_get_contents($file)); } else { $content = file_get_contents($file); } $phar->addFromString($path, $content); } // Stubs $phar['_cli_stub.php'] = $this->getCliStub(); $phar['_web_stub.php'] = $this->getWebStub(); $phar->setDefaultStub('_cli_stub.php', '_web_stub.php'); $phar->stopBuffering(); //$phar->compressFiles(\Phar::GZ); unset($phar); }
/** * Execute the task * * @throws Exception * @return void */ public function execute() { $target = $this->getOption('target'); $sourceDirectory = $this->getOption('sourceDirectory'); $stubFile = $this->getOption('stubFile'); if (!extension_loaded('phar')) { throw new \Exception('Phar extension not loaded'); } if (!is_dir($sourceDirectory)) { throw new \Exception('Source directory not found: ' . $sourceDirectory); } // check to see if we can create phar files $readOnly = ini_get('phar.readonly'); if ($readOnly != 1) { $phar = new \Phar($target, 0, basename($target)); $phar->startBuffering(); $phar->buildFromDirectory($sourceDirectory); $stub = $phar->createDefaultStub(); $phar->setStub($stub); $phar->stopBuffering(); //$phar->compress(Phar::GZ); } else { throw new \Exception('Cannot create phar! (read-only enabled)'); } }
/** * Compiles psysh into a single phar file. * * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'psysh.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $this->version = Shell::VERSION; $phar = new \Phar($pharFile, 0, 'psysh.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = Finder::create()->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->notName('Autoloader.php')->in(__DIR__ . '/..'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = Finder::create()->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in(__DIR__ . '/../../vendor/dnoegel/php-xdg-base-dir/src')->in(__DIR__ . '/../../vendor/jakub-onderka/php-console-color')->in(__DIR__ . '/../../vendor/jakub-onderka/php-console-highlighter')->in(__DIR__ . '/../../vendor/nikic/php-parser/lib')->in(__DIR__ . '/../../vendor/symfony/console')->in(__DIR__ . '/../../vendor/symfony/var-dumper')->in(__DIR__ . '/../../vendor/symfony/yaml'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/include_paths.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_files.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_psr4.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_real.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/ClassLoader.php')); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false); unset($phar); }
/** * Compiles phar archive. * * @param string $version */ public function compile($version) { if (file_exists($package = "behat-{$version}.phar")) { unlink($package); } // create phar $phar = new \Phar($package, 0, 'behat.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.xsd')->name('*.xml')->name('LICENSE')->notName('PharCompiler.php')->notName('PearCompiler.php')->in($this->libPath . '/src')->in($this->libPath . '/vendor'); foreach ($finder as $file) { // don't compile test suites if (!preg_match('/\\/tests\\/|\\/test\\//i', $file->getRealPath())) { $this->addFileToPhar($file, $phar); } } // license and autoloading $this->addFileToPhar(new \SplFileInfo($this->libPath . '/LICENSE'), $phar); $this->addFileToPhar(new \SplFileInfo($this->libPath . '/i18n.php'), $phar); // stub $phar->setStub($this->getStub($version)); $phar->stopBuffering(); unset($phar); }
public function run() { $this->printTaskInfo("Creating <info>{$this->filename}</info>"); $this->phar->setSignatureAlgorithm(\Phar::SHA1); $this->phar->startBuffering(); $this->printTaskInfo('Packing ' . count($this->files) . ' files into phar'); $progress = new ProgressBar($this->getOutput()); $progress->start(count($this->files)); $this->startTimer(); foreach ($this->files as $path => $content) { $this->phar->addFromString($path, $content); $progress->advance(); } $this->phar->stopBuffering(); $progress->finish(); $this->getOutput()->writeln(''); if ($this->compress and in_array('GZ', \Phar::getSupportedCompression())) { if (count($this->files) > 1000) { $this->printTaskInfo("Too many files. Compression DISABLED"); } else { $this->printTaskInfo($this->filename . " compressed"); $this->phar = $this->phar->compressFiles(\Phar::GZ); } } $this->stopTimer(); $this->printTaskSuccess("<info>{$this->filename}</info> produced"); return Result::success($this, '', ['time' => $this->getExecutionTime()]); }
public function compile($pharFile = self::PHAR_FILE, $root_dir = null) { if (is_null($root_dir)) { $this->root_dir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR; } else { $this->root_dir = rtrim($root_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, self::PHAR_NAME); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = $this->getDefaultFinder(); $finder->name('*.php'); foreach ($finder as $file) { $this->__addFile($phar, $file); } $finder = $this->getDefaultFinder(); $finder->name('*.json')->name('*.ini')->name('*.man')->name('*.md')->name('*.tpl')->name('LICENSE'); foreach ($finder as $file) { $this->__addFile($phar, $file, false); } // global binary $this->__addBin($phar); // add the __stub $phar->setStub($this->__getStub()); $phar->stopBuffering(); unset($phar); return $this->_logs; }
public function build($filename, $stub) { if (file_exists($filename)) { unlink($filename); } $phar = new \Phar($filename, 0, $this->aliasName != '' ? $this->aliasName : basename($filename)); $phar->startBuffering(); $phar->setStub($stub); if ($this->key !== NULL) { $privateKey = ''; openssl_pkey_export($this->key, $privateKey); $phar->setSignatureAlgorithm(\Phar::OPENSSL, $privateKey); $keyDetails = openssl_pkey_get_details($this->key); file_put_contents($filename . '.pubkey', $keyDetails['key']); } else { $phar->setSignatureAlgorithm($this->selectSignatureType($phar)); } $basedir = $this->basedir ? $this->basedir : $this->directories[0]; foreach ($this->directories as $directory) { $phar->buildFromIterator($this->scanner->__invoke($directory), $basedir); } if ($this->compression !== \Phar::NONE) { $phar->compressFiles($this->compression); } $phar->stopBuffering(); }
/** * Compile new composer.phar * @param string $filename */ public function compile($filename = 'codecept.phar') { if (file_exists($filename)) { unlink($filename); } $phar = new \Phar($filename, 0, 'codecept.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.tpl.dist')->name('*.html.dist')->in($this->compileDir . '/src'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.js')->name('*.css')->name('*.png')->name('*.tpl.dist')->name('*.html.dist')->exclude('Tests')->exclude('tests')->exclude('benchmark')->exclude('demo')->in($this->compileDir . '/plugins/frameworks'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.css')->name('*.png')->name('*.js')->name('*.css')->name('*.png')->name('*.tpl.dist')->name('*.html.dist')->exclude('Tests')->exclude('tests')->exclude('benchmark')->exclude('demo')->in($this->compileDir . '/vendor'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo($this->compileDir . '/autoload.php')); $this->setMainExecutable($phar); $this->setStub($phar); $phar->stopBuffering(); unset($phar); }
/** * Compiles satis into a single phar file * * @param string $pharFile The full path to the file to create * * @throws \RuntimeException */ public function compile($pharFile = 'satis.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'satis.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finders = array(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/../../'); $finders[] = $finder; $finder = new Finder(); $finder->files()->name('*')->in(__DIR__ . '/../../../views/'); $finders[] = $finder; $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('composer-schema.json')->exclude(array('phpunit', 'mikey179', 'phpdocumentor', 'sebastian', 'phpspec', 'doctrine', 'test', 'tests', 'Tests'))->in(__DIR__ . '/../../../vendor/'); $finders[] = $finder; foreach ($finders as $finder) { foreach ($finder as $file) { $this->addFile($phar, $file); } } $this->addSatisBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); $phar->compressFiles(\Phar::GZ); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../../LICENSE'), false); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../../res/satis-schema.json'), false); unset($phar); }
/** * Compiles the Silex source code into one single Phar file. * * @param string $pharFile Name of the output Phar file */ public function compile($pharFile = 'silex.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $process = new Process('git log --pretty="%h %ci" -n1 HEAD'); if ($process->run() > 0) { throw new \RuntimeException('The git binary cannot be found.'); } $this->version = trim($process->getOutput()); $phar = new \Phar($pharFile, 0, 'silex.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..')->in(__DIR__ . '/../../vendor/pimple/pimple/lib')->in(__DIR__ . '/../../vendor/symfony/class-loader/Symfony/Component/ClassLoader')->in(__DIR__ . '/../../vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher')->in(__DIR__ . '/../../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation')->in(__DIR__ . '/../../vendor/symfony/http-kernel/Symfony/Component/HttpKernel')->in(__DIR__ . '/../../vendor/symfony/routing/Symfony/Component/Routing')->in(__DIR__ . '/../../vendor/symfony/browser-kit/Symfony/Component/BrowserKit')->in(__DIR__ . '/../../vendor/symfony/css-selector/Symfony/Component/CssSelector')->in(__DIR__ . '/../../vendor/symfony/dom-crawler/Symfony/Component/DomCrawler'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php')); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // $phar->compressFiles(\Phar::GZ); unset($phar); }
/** * Compiles composer into a single phar file * * @throws \RuntimeException */ public function compile() { $pharFile = 'refactor.phar'; if (file_exists($pharFile)) { unlink($pharFile); } $process = new Process('git log --pretty="%H" -n1 HEAD', $this->directory); if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from git repository clone and that git binary is available.'); } $this->version = trim($process->getOutput()); $process = new Process('git describe --tags HEAD'); if ($process->run() == 0) { $this->version = trim($process->getOutput()); } $phar = new \Phar($pharFile, 0, 'refactor.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in($this->directory . '/src/main'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->exclude('test')->exclude('features')->in($this->directory . '/vendor/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addRefactorBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); unset($phar); }
public function compile($pharFile = 'onesky.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'onesky.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finders = array(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__); $finders[] = $finder; $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->in(dirname(__DIR__) . "/vendor"); $finders[] = $finder; foreach ($finders as $finder) { foreach ($finder as $file) { $this->addFile($phar, $file); } } $this->addBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); $phar->compressFiles(\Phar::GZ); unset($phar); }
/** * Compiles composer into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharName) { echo "Creating phar archive" . PHP_EOL; $this->pharName = $pharName; $pharFile = __DIR__ . DIRECTORY_SEPARATOR . $pharName; if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, $pharName); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); foreach ($this->directories as $folder) { $finder = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS)); foreach ($finder as $file) { if ($this->isWhitelisted($file) && !$this->isBlacklisted($file)) { $this->addFile($phar, $file); } } } $this->addFile($phar, $this->entryPoint); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); unset($phar); }
/** * Compiles composer into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'composer.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $process = new Process('git log --pretty="%h" -n1 HEAD'); if ($process->run() != 0) { throw new \RuntimeException('The git binary cannot be found.'); } $this->version = trim($process->getOutput()); $phar = new \Phar($pharFile, 0, 'composer.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/..'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->in(__DIR__ . '/../../vendor/symfony/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/ClassLoader.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/.composer/autoload_namespaces.php')); $this->addComposerBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // disabled for interoperability with systems without gzip ext // $phar->compressFiles(\Phar::GZ); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false); unset($phar); }
/** * Initialize the package creator */ function init() { try { if (file_exists($this->path)) { @unlink($this->path); } $ext = strstr(strrchr($this->path, '-'), '.'); if (!$ext) { $ext = strstr(strrchr($this->path, '/'), '.'); if (!$ext) { $ext = strstr(strrchr($this->path, '\\'), '.'); } } if (!$ext) { $ext = strstr($this->path, '.'); } $a = $this->_classname; $this->phar = new $a($this->path); if ($this->phar instanceof Phar) { $this->phar = $this->phar->convertToExecutable($this->format, $this->compression, $ext); } else { $this->phar = $this->phar->convertToData($this->format, $this->compression, $ext); } $this->phar->startBuffering(); if ($this->phar instanceof Phar) { $this->phar->setStub($this->stub); } if ($this->format == Phar::ZIP) { $this->compression = $comp; } } catch (Exception $e) { throw new \Pyrus\Developer\Creator\Exception('Cannot open Phar archive ' . $this->path, $e); } $this->_started = false; }
/** * Compile. */ public function compile() { $pharFilePath = dirname(__FILE__) . '/../../build/monitor.phar'; if (file_exists($pharFilePath)) { unlink($pharFilePath); } $this->loadVersion(); $phar = new \Phar($pharFilePath, 0, 'monitor.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $root = __DIR__ . '/../..'; $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('LICENSE')->notName('Compiler.php')->exclude('Tests')->exclude('tests')->exclude('docs')->in($root . '/src')->in($root . '/vendor/guzzlehttp')->in($root . '/vendor/rtheunissen')->in($root . '/vendor/eljam')->in($root . '/vendor/hogosha')->in($root . '/vendor/webmozart')->in($root . '/vendor/psr')->in($root . '/vendor/guzzle')->in($root . '/vendor/symfony'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo($root . '/vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_psr4.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_files.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_real.php')); if (file_exists($root . '/vendor/composer/include_paths.php')) { $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/include_paths.php')); } $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/ClassLoader.php')); $binContent = file_get_contents($root . '/bin/monitor'); $binContent = preg_replace('{^#!/usr/bin/env php\\s*}', '', $binContent); $phar->addFromString('bin/monitor', $binContent); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); unset($phar); }
/** * Compiles compify into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'compify.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'compify.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finders = array(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__ . '/../../'); $finders[] = $finder; $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('composer-schema.json')->in(__DIR__ . '/../../../vendor/'); $finders[] = $finder; foreach ($finders as $finder) { foreach ($finder as $file) { $this->addFile($phar, $file); } } $this->addSatisBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); $phar->compressFiles(\Phar::GZ); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../../LICENSE'), false); unset($phar); }
/** * Compiles shootproof-cli into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'shootproof-cli.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $phar = new \Phar($pharFile, 0, 'shootproof-cli.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../LICENSE'), false); $finder = $this->getFinder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->in(__DIR__); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = $this->getFinder(); $finder->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in(__DIR__ . '/../vendor/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../bin/config.php')); $this->addBin($phar); $phar->compressFiles(\Phar::GZ); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); unset($phar); }
/** * Compiles composer into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'composer.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $process = new Process('git log --pretty="%H" -n1 HEAD', __DIR__); if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.'); } $this->version = trim($process->getOutput()); $process = new Process('git log -n1 --pretty=%ci HEAD', __DIR__); if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.'); } $date = new \DateTime(trim($process->getOutput())); $date->setTimezone(new \DateTimeZone('UTC')); $this->versionDate = $date->format('Y-m-d H:i:s'); $process = new Process('git describe --tags HEAD'); if ($process->run() == 0) { $this->version = trim($process->getOutput()); } $phar = new \Phar($pharFile, 0, 'composer.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->notName('ClassLoader.php')->in(__DIR__ . '/..'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/Autoload/ClassLoader.php'), false); $finder = new Finder(); $finder->files()->name('*.json')->in(__DIR__ . '/../../res'); foreach ($finder as $file) { $this->addFile($phar, $file, false); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../src/Composer/IO/hiddeninput.exe'), false); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in(__DIR__ . '/../../vendor/symfony/')->in(__DIR__ . '/../../vendor/seld/jsonlint/src/')->in(__DIR__ . '/../../vendor/justinrainbow/json-schema/src/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_psr4.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/autoload_real.php')); if (file_exists(__DIR__ . '/../../vendor/composer/include_paths.php')) { $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/include_paths.php')); } $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/composer/ClassLoader.php')); $this->addComposerBin($phar); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // disabled for interoperability with systems without gzip ext // $phar->compressFiles(\Phar::GZ); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../LICENSE'), false); unset($phar); }