function makePackage(\Pyrus\PackageFile\v2 $pf) { foreach ($pf->files as $name => $blah) { file_put_contents($this->__DIR__ . '/' . $name, 'hi'); } file_put_contents($this->__DIR__ . '/package.xml', $pf); $package1 = new \Pyrus\Package(false); $xmlcontainer = new \Pyrus\PackageFile($pf); $xml = new \Pyrus\Package\Xml($this->__DIR__ . '/package.xml', $package1, $xmlcontainer); $package1->setInternalPackage($xml); $package1->archivefile = $this->__DIR__ . '/package.xml'; $this->scs->saveRelease($package1, 'cellog'); foreach ($pf->files as $name => $blah) { unlink($this->__DIR__ . '/' . $name); } unlink($this->__DIR__ . '/package.xml'); }
/** @todo Consider simply injecting the Package object as appropriate */ function package($frontend, $args, $options) { $path = getcwd() . DIRECTORY_SEPARATOR; $package = new \Pyrus\Package(null); if (!isset($args['packagexml']) && !file_exists($path . 'package.xml') && !file_exists($path . 'package2.xml')) { throw new \Pyrus\PackageFile\Exception("No package.xml or package2.xml found in " . $path); } if (isset($args['packagexml'])) { $package = new \Pyrus\Package($args['packagexml']); } else { // first try ./package.xml if (file_exists($path . 'package.xml')) { try { $package = new \Pyrus\Package($path . 'package.xml'); } catch (\Pyrus\PackageFile\Exception $e) { if ($e->getCode() != -3) { throw $e; } if (!file_exists($path . 'package2.xml')) { throw $e; } $package = new \Pyrus\Package($path . 'package2.xml'); // now the creator knows to do the magic of package2.xml/package.xml $package->thisIsOldAndCrustyCompatible(); } } // Alternatively; there's only a package2.xml if (file_exists($path . 'package2.xml') && !file_exists($path . 'package.xml')) { $package = new \Pyrus\Package($path . 'package2.xml'); } } if ($package->isNewPackage()) { if (!$options['phar'] && !$options['zip'] && !$options['tar'] && !$options['tgz']) { // try tgz first if (extension_loaded('zlib')) { $options['tgz'] = true; } else { $options['tar'] = true; } } if ($options['phar'] && ini_get('phar.readonly')) { throw new \Pyrus\Developer\Creator\Exception("Cannot create phar archive, pass -dphar.readonly=0"); } } else { if ($options['zip'] || $options['phar']) { echo "Zip and Phar archives can only be created for PEAR2 packages, ignoring\n"; } if (extension_loaded('zlib')) { $options['tgz'] = true; } else { $options['tar'] = true; } } // get openssl cert if set, and password if (\Pyrus\Config::current()->openssl_cert) { if ('yes' == $frontend->ask('Sign package?', array('yes', 'no'), 'yes')) { $cert = \Pyrus\Config::current()->openssl_cert; if (!file_exists($cert)) { throw new \Pyrus\Developer\Creator\Exception('OpenSSL certificate ' . $cert . ' does not exist'); } $releaser = \Pyrus\Config::current()->handle; $maintainers = array(); foreach ($package->maintainer as $maintainer) { $maintainers[] = $maintainer->user; } if (!strlen($releaser)) { throw new \Pyrus\Developer\Creator\Exception('handle configuration variable must be from ' . 'package.xml (one of ' . implode(', ', $maintainers) . ')'); } if (!in_array($releaser, $maintainers)) { throw new \Pyrus\Developer\Creator\Exception('handle configuration variable must be from ' . 'package.xml (one of ' . implode(', ', $maintainers) . ')'); } $passphrase = $frontend->ask('passphrase for OpenSSL PKCS#12 certificate?'); if (!$passphrase) { $passphrase = ''; } } else { $releaser = $cert = null; $passphrase = ''; } } else { $releaser = $cert = null; $passphrase = ''; } $sourcepath = \Pyrus\Main::getSourcePath(); if (0 !== strpos($sourcepath, 'phar://')) { // running from svn, assume we're in a standard package layout with a vendor dir // TODO: Improve this to automatically find latest releases from pear2.php.net $exceptionpath = $autoloadpath = $multierrorspath = realpath($sourcepath . '/../vendor/php') . '/PEAR2'; if (!file_exists($exceptionpath . '/Exception.php')) { throw new \Pyrus\Developer\Creator\Exception('Cannot locate PEAR2/Exception in a local vendor/ dir. ' . 'It is best to install the latest versions of these locally.'); } } else { $exceptionpath = $autoloadpath = $multierrorspath = dirname($sourcepath) . '/PEAR2'; } $extras = array(); $stub = false; if ($options['tgz'] && extension_loaded('zlib')) { $mainfile = $package->name . '-' . $package->version['release'] . '.tgz'; $mainformat = \Phar::TAR; $maincompress = \Phar::GZ; } elseif ($options['tgz']) { $options['tar'] = true; } if ($options['tar']) { if (isset($mainfile)) { $extras[] = array('tar', \Phar::TAR, \Phar::NONE); } else { $mainfile = $package->name . '-' . $package->version['release'] . '.tar'; $mainformat = \Phar::TAR; $maincompress = \Phar::NONE; } } if ($options['phar']) { if (isset($mainfile)) { $extras[] = array('phar', \Phar::PHAR, \Phar::GZ); } else { $mainfile = $package->name . '-' . $package->version['release'] . '.phar'; $mainformat = \Phar::PHAR; $maincompress = \Phar::NONE; } if (!$options['stub'] && file_exists(dirname($package->archivefile) . '/stub.php')) { $stub = file_get_contents(dirname($package->archivefile) . '/stub.php'); } elseif ($options['stub'] && file_exists($options['stub'])) { $stub = file_get_contents($options['stub']); } $stub = str_replace('@PACKAGE_VERSION' . '@', $package->version['release'], $stub); } if ($options['zip']) { if (isset($mainfile)) { $extras[] = array('zip', \Phar::ZIP, \Phar::NONE); } else { $mainfile = $package->name . '-' . $package->version['release'] . '.zip'; $mainformat = \Phar::ZIP; $maincompress = \Phar::NONE; } } if (isset($options['outputfile'])) { $mainfile = $options['outputfile']; } echo "Creating ", $mainfile, "\n"; if (null == $cert) { $cloner = new \Pyrus\Package\Cloner($mainfile); $clone = $extras; $extras = array(); } else { foreach ($extras as $stuff) { echo "Creating ", $package->name, '-', $package->version['release'], '.', $stuff[0], "\n"; } $clone = array(); } $creator = new \Pyrus\Package\Creator(array(new \Pyrus\Developer\Creator\Phar($mainfile, $stub, $mainformat, $maincompress, $extras, $releaser, $package, $cert, $passphrase)), $exceptionpath, $autoloadpath, $multierrorspath); if (!$options['extrasetup'] && file_exists(dirname($package->archivefile) . '/extrasetup.php')) { $options['extrasetup'] = 'extrasetup.php'; } if ($options['extrasetup']) { // encapsulate the extrafiles inside a closure so there is no access to the variables in this function $getinfo = function () use($options, $package) { $file = $options['extrasetup']; if (!file_exists(dirname($package->archivefile) . '/' . $file)) { throw new \Pyrus\Developer\Creator\Exception('extrasetup file must be in the same directory as package.xml'); } include dirname($package->archivefile) . '/' . $file; if (!isset($extrafiles)) { throw new \Pyrus\Developer\Creator\Exception('extrasetup file must set $extrafiles variable to an array of files'); } if (!is_array($extrafiles)) { throw new \Pyrus\Developer\Creator\Exception('extrasetup file must set $extrafiles variable to an array of files'); } foreach ($extrafiles as $path => $file) { if (is_object($file)) { if ($file instanceof \Pyrus\PackageInterface || $file instanceof \Pyrus\PackageFileInterface) { continue; } throw new \Pyrus\Developer\Creator\Exception('extrasetup file object must implement \\Pyrus\\PackageInterface or \\Pyrus\\PackageFileInterface'); } if (!file_exists($file)) { throw new \Pyrus\Developer\Creator\Exception('extrasetup file ' . $file . ' does not exist'); } if (!is_string($path)) { throw new \Pyrus\Developer\Creator\Exception('extrasetup file ' . $file . ' index should be the path to save in the' . ' release'); } } return $extrafiles; }; $extrafiles = $getinfo(); } else { $extrafiles = array(); } $creator->render($package, $extrafiles); if (count($clone)) { foreach ($clone as $extra) { echo "Creating ", $package->name, '-', $package->version['release'], '.', $extra[0], "\n"; $cloner->{'to' . $extra[0]}(); } } echo "done\n"; }
$scs->saveRelease($package2, 'cellog'); $package2 = new \Pyrus\Package(false); $xmlcontainer = new \Pyrus\PackageFile($p2_3); $xml = new \Pyrus\Package\Xml(__DIR__ . '/package.xml', $package2, $xmlcontainer); $package2->setInternalPackage($xml); file_put_contents(__DIR__ . '/package.xml', $p2_3); $package2->archivefile = __DIR__ . '/package.xml'; $scs->saveRelease($package2, 'cellog'); $package2 = new \Pyrus\Package(false); $xmlcontainer = new \Pyrus\PackageFile($p2_4); $xml = new \Pyrus\Package\Xml(__DIR__ . '/package.xml', $package2, $xmlcontainer); $package2->setInternalPackage($xml); file_put_contents(__DIR__ . '/package.xml', $p2_4); $package2->archivefile = __DIR__ . '/package.xml'; $scs->saveRelease($package2, 'cellog'); $package3 = new \Pyrus\Package(false); $xmlcontainer = new \Pyrus\PackageFile($p3); $xml = new \Pyrus\Package\Xml(__DIR__ . '/package.xml', $package3, $xmlcontainer); $package3->setInternalPackage($xml); file_put_contents(__DIR__ . '/package.xml', $p3); $package3->archivefile = __DIR__ . '/package.xml'; $scs->saveRelease($package3, 'cellog'); // clean up unlink(dirname(__DIR__) . '/pearconfig.xml'); unlink(dirname(__DIR__) . '/.config'); for ($i = 1; $i <= 6; $i++) { unlink(__DIR__ . "/glooby{$i}"); } unlink(__DIR__ . '/package.xml'); $dir = dirname(__DIR__) . '/.configsnapshots'; include __DIR__ . '/../../../clean.php.inc';
protected function fromUrl($param, $saveparam = '') { $this->type = 'url'; $dir = Config::current()->download_dir; try { $response = \Pyrus\Main::downloadWithProgress($param); if ($response->code != '200') { throw new Exception('Download failed, received ' . $response->code); } $info = parse_url($param); $name = urldecode(basename($info['path'])); if (isset($response->headers['content-disposition'])) { if (preg_match('/filename="(.+)"/', $response->headers['content-disposition'], $match)) { $name = $match[1]; } } if (!@file_exists($dir)) { mkdir($dir, 0755, true); } if (false === file_put_contents($dir . DIRECTORY_SEPARATOR . $name, $response->body)) { throw new Exception('Unable to save package ' . $name . ' to downloads directory, ' . $dir . '. Do we have permission to write there?'); } // whew, download worked! $a = new \Pyrus\Package($dir . DIRECTORY_SEPARATOR . $name); return $a->getInternalPackage(); } catch (\Pyrus\HTTPException $e) { throw $e; // pass it along } catch (\Exception $e) { if (!empty($saveparam)) { $saveparam = ", cannot download \"{$saveparam}\""; } throw new Exception('Could not download from "' . $param . '"' . $saveparam, $e); } }
function info($args, $options) { if (!$options['forceremote']) { if (file_exists($args['package'])) { $package = new \Pyrus\Package($args['package']); $installed = false; } elseif (isset(\Pyrus\Config::current()->registry->package[$args['package']])) { $package = \Pyrus\Config::current()->registry->package[$args['package']]; $installed = true; } } if (!isset($package)) { $installed = false; $package = new \Pyrus\Package($args['package'], $options['forceremote']); } echo $this->wrap($package->name . ' (' . $package->channel . ' Channel)'), "\n"; echo str_repeat('-', 80), "\n"; // this next line ensures we get an accurate reading on a remote abstract package if (!$installed && $package->isRemote()) { $package->grabEntirePackagexml(); } if (!isset($args['field'])) { echo 'Package type: '; switch ($package->type) { case 'php': echo "PHP package\n"; break; case 'extsrc': echo "Extension source package\n"; break; case 'zendextsrc': echo "Zend Extension source package\n"; break; case 'extbin': echo "Extension binary package\n"; break; case 'zendextbin': echo "Zend Extension binary package\n"; break; case 'bundle': echo "Package Bundle\n"; break; } echo 'Version: ', $package->version['release'], ' (API ', $package->version['api'], "), "; echo 'Stability: ', $package->stability['release'], ' (API ', $package->stability['api'], ")\n"; echo 'Release Date: ', $package->date; if ($package->time) { echo ' ', $package->time; } echo "\n"; echo "Package Summary: ", $this->columnWrap($package->summary, strlen("Package Summary: ")), "\n"; echo "Package Description Excerpt:\n ", $this->columnWrap(substr(rtrim($package->description), 0, 171) . '...', 3), "\n"; echo '(`php pyrus.phar info ' . $args['package'] . " description` for full description)\n"; echo "Release Notes Excerpt:\n ", $this->columnWrap(substr(rtrim($package->notes), 0, 171) . '...', 3), "\n"; echo '(`php pyrus.phar info ' . $args['package'] . " notes` for full release notes)\n"; if ($installed) { // check for upgrades try { $tester = new \Pyrus\Package($package->channel . '/' . $package->name, true); $upgrades = $tester->getAllUpgrades($package->version['release']); if (count($upgrades)) { echo "Upgrades available:\n"; foreach ($upgrades as $info) { echo ' Version ', $info['v'], ' (', $info['s'], ")\n"; } } } catch (\Exception $e) { // ignore problems here, no need to freak out if checking for upgrades fails if ($this->verbose > 3) { echo $e; } } } } elseif ($args['field'] == 'description') { echo "Package Description:\n ", $this->columnWrap(trim($package->description), 3), "\n"; } elseif ($args['field'] == 'notes') { echo "Release Notes:\n ", $this->columnWrap($package->notes, 3), "\n"; } elseif ($args['field'] == 'files') { if ($installed) { echo "Package Files (installed):\n"; foreach (\Pyrus\Config::current()->registry->info($package->name, $package->channel, 'installedfiles') as $file => $info) { echo $file, ' (', $info['role'], ")\n"; } } else { if ($package->isRemote()) { echo "Package Files:\n"; foreach ($package->contents as $file) { echo $file->name, ' (', $file->role, ")\n"; } } else { echo "Package Files (as would be installed):\n"; foreach ($package->installcontents as $file) { echo $file->name, ' (', $file->role, ")\n"; } } } } else { echo "Unknown sub-field ", $args['field'], " must be one of description, notes, or files\n"; } }
public function info($package, $channel, $field) { if (!$this->exists($package, $channel)) { throw new Exception('Unknown package ' . $channel . '/' . $package); } $packagefile = glob($this->_namePath($channel, $package) . DIRECTORY_SEPARATOR . '*.xml'); if (!$packagefile || !isset($packagefile[0])) { throw new Exception('Cannot find registry for package ' . $channel . '/' . $package); } $packageobject = new \Pyrus\Package($packagefile[0]); if ($field === null) { return $packageobject->getInternalPackage()->getPackageFile()->getPackageFileObject(); } if ($field == 'version') { $field = 'release-version'; } elseif ($field == 'installedfiles') { $ret = array(); try { $config = new \Pyrus\Config\Snapshot($packageobject->date . ' ' . $packageobject->time); } catch (\Exception $e) { throw new Exception('Cannot retrieve files, config ' . 'snapshot could not be processed', $e); } $roles = array(); foreach (Role::getValidRoles($packageobject->getPackageType()) as $role) { // set up a list of file role => configuration variable // for storing in the registry $roles[$role] = Role::factory($packageobject->getPackageType(), $role); } $ret = array(); foreach ($packageobject->installcontents as $file) { $relativepath = $roles[$file->role]->getRelativeLocation($packageobject, $file); if (!$relativepath) { continue; } $filepath = $config->{$roles[$file->role]->getLocationConfig()} . DIRECTORY_SEPARATOR . $relativepath; $attrs = $file->getArrayCopy(); $ret[$filepath] = $attrs['attribs']; $ret[$filepath]['installed_as'] = $filepath; $ret[$filepath]['relativepath'] = $relativepath; $ret[$filepath]['configpath'] = $config->{$roles[$file->role]->getLocationConfig()}; } return $ret; } elseif ($field == 'dirtree') { $files = $this->info($package, $channel, 'installedfiles'); foreach ($files as $file => $unused) { do { $file = dirname($file); if (strlen($file) > strlen($this->_path)) { $ret[$file] = 1; } } while (strlen($file) > strlen($this->_path)); } $ret = array_keys($ret); usort($ret, 'strnatcasecmp'); return array_reverse($ret); } return $packageobject->{$field}; }
<?php $pyrus = new \Pyrus\Package(__DIR__ . '/../Pyrus/package.xml'); $pyrus->setPackagingFilter('Pyrus\\PackageFile\\v2Iterator\\MinimalPackageFilter'); $extrafiles = array(new \Pyrus\Package(__DIR__ . '/../PEAR2_HTTP_Request/package.xml'), $pyrus, new \Pyrus\Package(__DIR__ . '/../Pyrus_Developer/package.xml'), new \Pyrus\Package(__DIR__ . '/../PEAR2_Exception/package.xml'), new \Pyrus\Package(__DIR__ . '/../PEAR2_MultiErrors/package.xml'));
$pf = new \Pyrus\PackageFile\v2(); for ($i = 1; $i <= 1; $i++) { file_put_contents(__DIR__ . "/glooby{$i}", 'hi'); } $pf->name = 'P1'; $pf->channel = 'pear2.php.net'; $pf->summary = 'testing'; $pf->version['release'] = '1.0.0'; $pf->stability['release'] = 'stable'; $pf->description = 'hi description'; $pf->notes = 'my notes'; $pf->maintainer['cellog']->role('lead')->email('*****@*****.**')->active('yes')->name('Greg Beaver'); $pf->files['glooby1'] = array('role' => 'php'); $pf->setPackagefile(__DIR__ . '/package.xml'); file_put_contents(__DIR__ . '/package.xml', $pf); $package1 = new \Pyrus\Package(false); $xmlcontainer = new \Pyrus\PackageFile($pf); $xml = new \Pyrus\Package\Xml(__DIR__ . '/package.xml', $package1, $xmlcontainer); $package1->setInternalPackage($xml); $package1->archivefile = __DIR__ . '/package.xml'; $scs->saveRelease($package1, 'cellog', $cert[0], $cert[1]); // clean up unlink(dirname(__DIR__) . '/pearconfig.xml'); unlink(dirname(__DIR__) . '/.config'); for ($i = 1; $i <= 1; $i++) { unlink(__DIR__ . "/glooby{$i}"); } unlink(__DIR__ . '/package.xml'); $dir = dirname(__DIR__) . '/.configsnapshots'; include __DIR__ . '/../../../clean.php.inc'; rmdir(dirname(__DIR__) . '/PEAR2/temp');
function validate() { $package = new \Pyrus\Package(false); $xmlcontainer = new \Pyrus\PackageFile($this->pxml); $xml = new \Pyrus\Package\Xml($this->path . '/package.xml', $package, $xmlcontainer); $package->setInternalPackage($xml); $this->pxml->getValidator()->validate($package); }