protected function getPhar(&$pharName) { $finder = new Finder(); $finder->files()->in(Protocol::realPath('katana://data/lib/composer'))->in(Protocol::realPath('katana://data/lib/hoa/core'))->in(Protocol::realPath('katana://data/lib/hoa/console'))->in(Protocol::realPath('katana://data/lib/hoa/iterator'))->in(Protocol::realPath('katana://data/lib/hoa/router'))->in(Protocol::realPath('katana://data/lib/sabre/uri'))->in(Protocol::realPath('katana://data/lib/ircmaxell/password-compat'))->name('/\\.php$/')->notIn('/^\\.git$/'); $pharName = $this->helper->temporaryFile('.phar'); $phar = new CUT($pharName); $phar->buildFromIterator($finder, SABRE_KATANA_PREFIX); $phar['bootstrap.php'] = '<?php require \'vendor/autoload.php\';'; $phar['vendor/autoload.php'] = file_get_contents('katana://data/lib/autoload.php'); $phar->setStub($phar->getStubCode()); return $phar; }
/** * Open a PHAR archive. If it does not exist, attempt to create it. * * @param string $filename Filename (see original documentation). * @param int $flags Flags (see original documentation). * @param string $alias Alias (see original documentation). * @return void */ function __construct($filename, $flags = null, $alias = null) { if (null !== $alias) { parent::__construct($filename, $flags, $alias); } elseif (null !== $flags) { parent::__construct($filename, $flags); } else { parent::__construct($filename); } $this->setSignatureAlgorithm(static::SHA1); $this->setMetadata(['author' => 'fruux GmbH (https://fruux.com/)', 'license' => 'Modified BSD License (http://sabre.io/license/)', 'copyright' => 'Copyright (C) 2015 fruux GmbH (https://fruux.com/)', 'datetime' => date('c')]); }
/** * Main method. * * @return int */ function main() { $format = 0; while (false !== ($c = $this->getOption($v))) { switch ($c) { case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'z': $format = static::FORMAT_ZIP; break; case 'p': $format = static::FORMAT_PHAR; break; case 'h': case '?': default: return $this->usage(); break; } } $archiveName = null; $finder = new Finder(); $finder->files()->in(SABRE_KATANA_PREFIX)->notIn('/^\\.git$/'); if (0 === $format) { return $this->usage(); } elseif (static::FORMAT_ZIP === $format) { $pathName = 'katana.zip'; $finder->notIn('/^' . preg_quote($pathName, '/') . '$/'); $archiveName = $pharPathname = SABRE_KATANA_PREFIX . '/data/share/' . $pathName; if (true === file_exists($pharPathname)) { unlink($pharPathname); } $zip = new Zip($pharPathname); $zip->buildFromIterator($finder, SABRE_KATANA_PREFIX); } elseif (static::FORMAT_PHAR === $format) { if (false === Phar::canWrite()) { throw new Exception\Console('Cannot create the PHAR. ' . 'Retry with `php -d phar.readonly=0 ' . $_SERVER['argv'][0] . ' stub --phar'); } $pathName = 'katana.phar'; $finder->notIn('/^' . preg_quote($pathName, '/') . '$/'); $archiveName = $pharPathname = SABRE_KATANA_PREFIX . '/data/share/'; if (true === file_exists($pharPathname)) { unlink($pharPathname); } $phar = new Phar($pharPathname); $phar->buildFromIterator($finder, SABRE_KATANA_PREFIX); $phar->setStub($phar->getStubCode()); } echo $archiveName, "\n"; }
function case_metadata() { $this->given($phar = new CUT($this->helper->temporaryFile('.phar')))->when($result = $phar->getMetadata())->then->array($result)->hasKeys(['author', 'license', 'copyright', 'datetime'])->string($result['author'])->isEqualTo('fruux GmbH (https://fruux.com/)')->string($result['license'])->isEqualTo('Modified BSD License (http://sabre.io/license/)')->string($result['copyright'])->isEqualTo('Copyright (C) 2015 fruux GmbH (https://fruux.com/)')->string($result['datetime'])->isEqualTo(date('c', strtotime($result['datetime']))); }