public function testOpenSSLSignature() { if (!extension_loaded('OpenSSL')) { $this->markTestSkipped("Need OpenSSL extension"); } // Generate a private key on the fly. $passphrase = uniqid(); $passfile = PHING_TEST_BASE . '/etc/tasks/ext/pharpackage/pass.txt'; file_put_contents($passfile, $passphrase); $pkey = openssl_pkey_new(); openssl_pkey_export_to_file($pkey, PHING_TEST_BASE . '/etc/tasks/ext/pharpackage/priv.key', $passphrase); $this->executeTarget(__FUNCTION__); // Make sure we are dealing with an OpenSSL signature. // (Phar silently falls back to an SHA1 signature // whenever it fails to add an OpenSSL signature) $dest = PHING_TEST_BASE . '/etc/tasks/ext/pharpackage/pharpackage.phar'; $this->assertFileExists($dest); $phar = new Phar($dest); $signature = $phar->getSignature(); $this->assertEquals('OpenSSL', $signature['hash_type']); unlink(PHING_TEST_BASE . '/etc/tasks/ext/pharpackage/priv.key'); unlink(PHING_TEST_BASE . '/etc/tasks/ext/pharpackage/pharpackage.phar.pubkey'); unlink(PHING_TEST_BASE . '/etc/tasks/ext/pharpackage/pass.txt'); unlink($dest); }
/** * @param \Phar $phar * @param SplFileInfo $file */ private function addFile(\Phar $phar, SplFileInfo $file) { $path = $file->getRelativePathname(); $content = file_get_contents($file); $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content); $phar->addFromString($path, $content); }
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 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(); }
private function addFile(\Phar $phar, \SplFileInfo $file) { $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath()); $content = file_get_contents($file); $content = $this->stripWhitespace($content); $phar->addFromString($path, $content); }
/** * 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); }
/** * Method to run the application routines. Most likely you will want to instantiate a controller * and execute it, or perform some sort of task directly. * * @return void * * @since 2.0 */ protected function doExecute() { if ($this->io->getOption('h') || $this->io->getOption('help')) { $this->help(); return; } $dir = $this->io->getOption('d', '../../vaseman.phar'); $file = __DIR__ . '/' . $dir; if (is_file($file)) { unlink($file); } $this->out('Start generating...'); $phar = new Phar($file); $phar->setStub(<<<PHP #!/usr/bin/env php <?php Phar::mapPhar('vaseman.phar'); require 'phar://vaseman.phar/bin/vaseman'; __HALT_COMPILER(); PHP ); $phar->buildFromDirectory(__DIR__ . '/..'); $phar->stopBuffering(); $this->out('Phar generated: ' . $file)->out(); }
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 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 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 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 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 the Slic source code into one single Phar file. * * @param string $pharFile Name of the output Phar file */ public function compile($pharFile = 'slic.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, 'slic.phar'); $phar->setSignatureAlgorithm(\Phar::SHA1); $phar->startBuffering(); $root = __DIR__ . '/../../..'; $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->notName('Compiler.php')->exclude('Tests')->in($root . '/src')->in($root . '/vendor/symfony'); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo($root . '/LICENSE'), false); $this->addFile($phar, new \SplFileInfo($root . '/vendor/autoload.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/ClassLoader.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_namespaces.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_classmap.php')); $this->addFile($phar, new \SplFileInfo($root . '/vendor/composer/autoload_real.php')); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); // $phar->compressFiles(\Phar::GZ); unset($phar); }
function buildModulePhar($name, $format = Phar::PHAR, $compression = Phar::NONE, $executable = true, $fake = false) { echo "Building {$name}...\t"; $glob = glob($name.'.*'); if (count($glob) > 0) { foreach ($glob as $file) { if (!is_dir($file)) { unlink($file); } } } $filename = $name . '.phar'; $phar = new Phar($filename); if ($fake) { $phar['Module.php'] = '<?php //no class here'; } else { $phar['Module.php'] = "<?php \n\nnamespace $name;\n\nclass Module\n{}"; } if (false === $executable) { $phar->convertToData($format, $compression); } else { $phar->setDefaultStub('Module.php', 'Module.php'); if ($format !== Phar::PHAR || $compression !== Phar::NONE) { $phar->convertToExecutable($format, $compression); } } if ($format !== Phar::PHAR || $compression !== Phar::NONE) { unlink($filename); } echo "Done!\n"; }
/** * 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); }
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 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); }
/** * 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 = '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 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); }
/** * Add a file in phar removing whitespaces from the file * * @param Phar $phar * @param string $sFile * @param null $baseDir */ function addFile($phar, $sFile, $baseDir = null) { if (null !== $baseDir) { $phar->addFromString(substr($sFile, strlen($baseDir) + 1), php_strip_whitespace($sFile)); } else { $phar->addFromString($sFile, php_strip_whitespace($sFile)); } }
/** * @param string $package path to package file */ function __construct($package, \Pyrus\Package $parent) { $package = realpath($package); if (!$package) { throw new Phar\Exception('Phar package ' . $package . ' does not exist'); } $pxml = false; $this->archive = $package; try { if (\Phar::isValidPharFilename($package, 1)) { $phar = new \Phar($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME); $pxml = 'phar://' . $package . '/' . $phar->getMetaData(); } else { $phar = new \PharData($package, \RecursiveDirectoryIterator::KEY_AS_FILENAME); if ($phar->getMetaData()) { $pxml = 'phar://' . $package . '/' . $phar->getMetaData(); } } } catch (\Exception $e) { throw new Phar\Exception('Could not open Phar archive ' . $package, $e); } $package = str_replace('\\', '/', $package); try { if ($pxml === false) { $info = pathinfo($package); $internal = $info['filename']; if (isset($phar[$internal . '/.xmlregistry'])) { if ($phar instanceof \PharData) { $iterate = new \PharData('phar://' . $package . '/' . $internal . '/.xmlregistry'); } else { $iterate = new \Phar('phar://' . $package . '/' . $internal . '/.xmlregistry'); } foreach (new \RecursiveIteratorIterator($iterate, \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { $filename = $file->getFileName(); // default to new package.xml if (preg_match('@^(.+)\\-package.xml$@', $filename)) { $pxml = $file->getPathName(); break; } } } else { foreach (array('package2.xml', $internal . '/' . 'package2.xml', 'package.xml', $internal . '/' . 'package.xml') as $checkfile) { if (isset($phar[$checkfile])) { $this->_BCpackage = true; $pxml = $phar[$checkfile]->getPathName(); break; } } } } if ($pxml === false) { throw new Phar\Exception('No package.xml in archive'); } } catch (\Exception $e) { throw new Phar\Exception('Could not extract Phar archive ' . $package, $e); } parent::__construct(new \Pyrus\PackageFile($pxml, 'Pyrus\\PackageFile\\v2'), $parent); }
protected function addFile(\Phar $phar, \splFileInfo $file, $strip = true) { $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath()); $content = file_get_contents($file); if ($strip) { $content = self::stripWhitespace($content); } $phar->addFromString($path, $content); }
/** * Extract resources to a file system path * * @param Phar $phar Phar archive. * @param string $path Output path root. */ protected function extractResources(Phar $phar, $path) { $this->deleteDirectory($path); $phar->extractTo($path); @unlink($path . '/index.php'); @unlink($path . '/build.bat'); $this->copyDirectory($path . '/resources', $path, false); $this->deleteDirectory($path . '/resources'); }
/** * @return string */ public static function Signature() { $sSignature = ''; if (\defined('MAILSO_LIBRARY_USE_PHAR')) { $oPhar = new \Phar('mailso.phar'); $sSignature = $oPhar->getSignature(); } return $sSignature; }
protected function signPhar() { $question = (new Question('Pass phrase for private key: '))->setHidden(true)->setHiddenFallback(true); $questionHelper = new QuestionHelper(); $passPhrase = $questionHelper->ask($this->input, $this->output, $question); $privateKeyResource = openssl_pkey_get_private('file://~/.openssl/surf.private.pem', $passPhrase); openssl_pkey_export($privateKeyResource, $exportedPrivateKey); $phar = new \Phar('../surf.phar'); $phar->setSignatureAlgorithm(\Phar::OPENSSL, $exportedPrivateKey); }
protected function addFile(\Phar $phar, \SplFileInfo $file, $strip = true) { $path = str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath()); $content = file_get_contents($file); if ($strip) { $content = self::stripWhitespace($content); } $content = preg_replace("/const VERSION = '.*?';/", "const VERSION = '" . $this->version . "';", $content); $phar->addFromString($path, $content); }
/** * Compiles classifier into a single phar file * * @throws \RuntimeException * @param string $pharFile The full path to the file to create */ public function compile($pharFile = 'php-lib-create.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 describe --tags HEAD'); if ($process->run() == 0) { $this->version = trim($process->getOutput()); } $phar = new \Phar($pharFile, 0, $pharFile); $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__ . '/../../../config'); foreach ($finder as $file) { $this->addFile($phar, $file); } $vendorDir = realpath(__DIR__ . '/../../../vendor'); $finder = new Finder(); $finder->files()->ignoreVCS(true)->name('*.php')->exclude('Tests')->in("{$vendorDir}/composer/composer/src/")->in("{$vendorDir}/justinrainbow/json-schema/src/")->in("{$vendorDir}/knplabs/github-api/lib/")->in("{$vendorDir}/kriswallsmith/buzz/lib/")->in("{$vendorDir}/seld/jsonlint/src/")->in("{$vendorDir}/symfony/"); foreach ($finder as $file) { $this->addFile($phar, $file); } $this->addFile($phar, new \SplFileInfo("{$vendorDir}/autoload.php")); $this->addFile($phar, new \SplFileInfo("{$vendorDir}/composer/autoload_namespaces.php")); $this->addFile($phar, new \SplFileInfo("{$vendorDir}/composer/autoload_classmap.php")); $this->addFile($phar, new \SplFileInfo("{$vendorDir}/composer/autoload_real.php")); if (file_exists("{$vendorDir}/composer/include_paths.php")) { $this->addFile($phar, new \SplFileInfo("{$vendorDir}/composer/include_paths.php")); } $this->addFile($phar, new \SplFileInfo("{$vendorDir}/composer/ClassLoader.php")); $finder = new Finder(); $finder->files()->name('*.json')->in("{$vendorDir}/composer/composer/res"); foreach ($finder as $file) { $this->addFile($phar, $file, false); } $this->addFile($phar, new \SplFileInfo("{$vendorDir}/composer/composer/src/Composer/IO/hiddeninput.exe"), false); $this->addBin($phar, 'bin/php-lib-create', __DIR__ . '/../../../bin/php-lib-create'); // Stubs $phar->setStub($this->getStub()); $phar->stopBuffering(); $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../../LICENSE'), false); unset($phar); file_put_contents('php-lib-create.phar.version', trim($this->version)); }
public function __construct($file, $flags = 0) { $this->name = $file; $this->file = __DIR__ . '/' . $file; $p = new Phar($this->file, Phar::CURRENT_AS_FILEINFO, $file); if (!$p->isWritable()) { throw new Exception("hoge"); } $p->startBuffering(); $this->driver = $p; }