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 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(); }
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 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); }
/** * 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); }
/** * 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); }
/** * 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 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); }
/** * 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); }
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; }
/** * 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); }
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 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); }
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()]); }
/** * 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 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()]); }
/** * 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 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); }
/** * 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 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); }
/** * Initializes a new PHAR archive with the given name. * * The PHAR archive's Signature's algorithm is set to SHA1. * * @param string $pharFile * * @return \Phar */ protected function initializePharArchive($pharFile) { echo '>> Initializing new phar archive' . PHP_EOL; $phar = new \Phar($pharFile, 0, 'phpDocumentor'); $phar->setSignatureAlgorithm(\Phar::SHA1); return $phar; }
/** * 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 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); }
/** * Compiles skylab into a single phar file * * @param string $version * @param string $pharFile The full path to the file to create * @throws \RuntimeException */ public function compile($version, $pharFile = 'skylab.phar') { if (file_exists($pharFile)) { unlink($pharFile); } $this->version = $version; $date = new \DateTime(); $date->setTimezone(new \DateTimeZone('UTC')); $this->versionDate = $date->format('Y-m-d H:i:s'); $phar = new \Phar($pharFile, 0, 'skylab.phar'); $sign = \Phar::getSupportedSignatures(); if (in_array(\Phar::SHA512, $sign)) { $phar->setSignatureAlgorithm(\Phar::SHA512); } elseif (in_array(\Phar::SHA256, $sign)) { $phar->setSignatureAlgorithm(\Phar::SHA256); } elseif (in_array(\Phar::SHA1, $sign)) { $phar->setSignatureAlgorithm(\Phar::SHA1); } elseif (in_array(\Phar::MD5, $sign)) { $phar->setSignatureAlgorithm(\Phar::MD5); } $phar->startBuffering(); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.yml')->notName('Compiler.php')->in(__DIR__ . '/../..'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->name('*.pem')->exclude('Tests')->in(__DIR__ . '/../../../vendor/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.yml')->in(__DIR__ . '/../../../config/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.twig')->in(__DIR__ . '/../../../templates/'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addSkylabBin($phar); $phar->setStub($this->getStub()); $phar->stopBuffering(); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../../LICENSE'), false); 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); }
public function execute(CommandSender $sender, $commandLabel, array $args) { if (!$this->testPermission($sender)) { return false; } if (count($args) === 0) { $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); return true; } $pluginName = trim(implode(" ", $args)); if ($pluginName === "" or !($plugin = Server::getInstance()->getPluginManager()->getPlugin($pluginName)) instanceof Plugin) { $sender->sendMessage(TextFormat::RED . "プラグインが存在しません"); return true; } $description = $plugin->getDescription(); if (!$plugin->getPluginLoader() instanceof FolderPluginLoader) { $sender->sendMessage(TextFormat::RED . "プラグイン " . $description->getName() . "はフォルダではありません"); return true; } $pharPath = Server::getInstance()->getPluginPath() . DIRECTORY_SEPARATOR . "PocketMine-MO" . DIRECTORY_SEPARATOR . $description->getName() . "_v" . $description->getVersion() . ".phar"; if (file_exists($pharPath)) { $sender->sendMessage("pharファイルが既に存在しているため、上書きします"); @unlink($pharPath); } $phar = new \Phar($pharPath); $phar->setMetadata(["name" => $description->getName(), "version" => $description->getVersion(), "main" => $description->getMain(), "api" => $description->getCompatibleApis(), "geniapi" => $description->getCompatibleGeniApis(), "depend" => $description->getDepend(), "description" => $description->getDescription(), "authors" => $description->getAuthors(), "website" => $description->getWebsite(), "creator" => "PocketMine-MO MakePluginCommand", "creationDate" => time()]); if ($description->getName() === "DevTools") { $phar->setStub('<?php require("phar://". __FILE__ ."/src/DevTools/ConsoleScript.php"); __HALT_COMPILER();'); } else { $phar->setStub('<?php echo "PocketMine-MP/ plugin ' . $description->getName() . ' v' . $description->getVersion() . '\\nThis file has been generated using PocketMine-MO by Meshida 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); $reflection = new \ReflectionClass("pocketmine\\plugin\\PluginBase"); $file = $reflection->getProperty("file"); $file->setAccessible(true); $filePath = rtrim(str_replace("\\", "/", $file->getValue($plugin)), "/") . "/"; $phar->startBuffering(); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($filePath)) as $file) { $path = ltrim(str_replace(["\\", $filePath], ["/", ""], $file), "/"); if ($path[0] === "." or strpos($path, "/.") !== false) { continue; } $phar->addFile($file, $path); $sender->sendMessage($path . "を追加しています..."); } foreach ($phar as $file => $finfo) { /** @var \PharFileInfo $finfo */ if ($finfo->getSize() > 1024 * 512) { $finfo->compress(\Phar::GZ); } } if (!isset($args[1]) or isset($args[1]) and $args[1] != "nogz") { $phar->compressFiles(\Phar::GZ); } $phar->stopBuffering(); $sender->sendMessage("pharプラグイン " . $description->getName() . " v" . $description->getVersion() . " は" . $pharPath . "上に生成されました"); return true; }
protected function initializePhar($filename) { if (file_exists($filename)) { unlink($filename); } $this->phar = new \Phar($filename); $this->phar->setSignatureAlgorithm(\Phar::SHA1); $this->phar->startBuffering(); }
function makePhar(array $dt) { //retornando com erro se o array estiver vazio if (count($dt) <= 0) { return false; } //aumentando a memoria e o tempo de execução - pode ser muito significante em sistemas lentos e diretórios muito grandes ini_set('memory_limit', '30M'); ini_set('max_execution_time', 180); //Array com os dados da execução $ok = array(); //lendo e executando as conversões indicadas foreach ($dt as $k => $lote) { //checando se deve converter indice['r'] if (!isset($lote['r'])) { continue; } $dir = trim($lote['o'], ' \\/'); $stub = '<?php Phar::interceptFileFuncs(); Phar::mungServer(array(\'REQUEST_URI\', \'PHP_SELF\', \'SCRIPT_NAME\', \'SCRIPT_FILENAME\')); Phar::webPhar(\'\', \'\', \'404.php\'); __HALT_COMPILER();'; // include(\'phar://\' . __FILE__ . \'/' . $lote['i'] . '\'); if (is_dir($dir)) { //criando arquivo PHAR $phar = new Phar(trim($lote['d'], ' \\/')); //pegando o diretório (e sub-diretórios) e arquivos contidos $phar->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)), $dir); //criando o cabeçalho Stub $phar->setStub($stub); //carregando a assinatura if (file_exists(LIB . 'key.md5')) { $phar->setSignatureAlgorithm(Phar::MD5, file_get_contents(LIB . 'key.md5')); } //comprimindo os dados (exceto o Stub) $compactar = false; if (isset($lote['z'])) { $compactar = true; if (Phar::canCompress(Phar::GZ)) { $phar->compressFiles(Phar::GZ); } elseif (Phar::canCompress(Phar::BZ2)) { $phar->compressFiles(Phar::BZ2); } } //adicionando os dados de saída $ok[$k] = array('o' => $dir, 'd' => $lote['d'], 'z' => $compactar, 'i' => $lote['i']); } else { $ok[$k] = array('e' => 'O diretório "' . $dir . '" não existe!'); } } if (count($ok) == 0) { return false; } return $ok; }