This method is able to extract information about a package from a .tgz
archive or from a XML package definition file.
public fromAnyFile ( string $info, integer $state ) : PEAR_PackageFile_v1 | PEAR_PackageFile_v2 | ||
$info | string | file name |
$state | integer | package state (one of PEAR_VALIDATE_* constants) |
return | PEAR_PackageFile_v1 | PEAR_PackageFile_v2 |
public function checkDownloads() { $pear = new Varien_Pear(); $pkg = new PEAR_PackageFile($pear->getConfig(), false); $result = true; foreach ($this->getPackages() as $package) { $obj = $pkg->fromAnyFile($package, PEAR_VALIDATE_NORMAL); if (PEAR::isError($obj)) { $uinfo = $obj->getUserInfo(); if (is_array($uinfo)) { foreach ($uinfo as $message) { if (is_array($message)) { $message = $message['message']; } Mage::getSingleton('Mage_Install_Model_Session')->addError($message); } } else { print_r($obj->getUserInfo()); #Mage::getSingleton('Mage_Install_Model_Session')->addError($message); } $result = false; } } return $result; }
/** * @return bool */ public function checkDownloads() { $pear = new \Magento\Framework\Pear(); $pkg = new PEAR_PackageFile($pear->getConfig(), false); $result = true; foreach ($this->getPackages() as $package) { $obj = $pkg->fromAnyFile($package, PEAR_VALIDATE_NORMAL); if (PEAR::isError($obj)) { $uinfo = $obj->getUserInfo(); if (is_array($uinfo)) { foreach ($uinfo as $message) { if (is_array($message)) { $message = $message['message']; } $this->messageManager->addError($message); } } else { print_r($obj->getUserInfo()); } $result = false; } } return $result; }
function doInstall($command, $options, $params) { if (!class_exists('PEAR_PackageFile')) { require_once 'PEAR/PackageFile.php'; } if (empty($this->installer)) { $this->installer =& $this->getInstaller($this->ui); } if ($command == 'upgrade' || $command == 'upgrade-all') { $options['upgrade'] = true; } else { $packages = $params; } if (isset($options['installroot']) && isset($options['packagingroot'])) { return $this->raiseError('ERROR: cannot use both --installroot and --packagingroot'); } $reg =& $this->config->getRegistry(); $instreg =& $reg; // instreg used to check if package is installed if (isset($options['packagingroot']) && !isset($options['upgrade'])) { $packrootphp_dir = $this->installer->_prependPath($this->config->get('php_dir', null, 'pear.php.net'), $options['packagingroot']); $instreg = new PEAR_Registry($packrootphp_dir); // other instreg! if ($this->config->get('verbose') > 2) { $this->ui->outputData('using package root: ' . $options['packagingroot']); } } $abstractpackages = array(); $otherpackages = array(); // parse params PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); foreach ($params as $param) { if (strpos($param, 'http://') === 0) { $otherpackages[] = $param; continue; } if (strpos($param, 'channel://') === false && @file_exists($param)) { if (isset($options['force'])) { $otherpackages[] = $param; continue; } $pkg = new PEAR_PackageFile($this->config); $pf = $pkg->fromAnyFile($param, PEAR_VALIDATE_DOWNLOADING); if (PEAR::isError($pf)) { $otherpackages[] = $param; continue; } if ($reg->packageExists($pf->getPackage(), $pf->getChannel()) && version_compare($pf->getVersion(), $reg->packageInfo($pf->getPackage(), 'version', $pf->getChannel()), '<=')) { if ($this->config->get('verbose')) { $this->ui->outputData('Ignoring installed package ' . $reg->parsedPackageNameToString(array('package' => $pf->getPackage(), 'channel' => $pf->getChannel()), true)); } continue; } $otherpackages[] = $param; continue; } $e = $reg->parsePackageName($param, $this->config->get('default_channel')); if (PEAR::isError($e)) { $otherpackages[] = $param; } else { $abstractpackages[] = $e; } } PEAR::staticPopErrorHandling(); // if there are any local package .tgz or remote static url, we can't // filter. The filter only works for abstract packages if (count($abstractpackages) && !isset($options['force'])) { // when not being forced, only do necessary upgrades/installs if (isset($options['upgrade'])) { $abstractpackages = $this->_filterUptodatePackages($abstractpackages, $command); } else { foreach ($abstractpackages as $i => $package) { if (isset($package['group'])) { // do not filter out install groups continue; } if ($instreg->packageExists($package['package'], $package['channel'])) { if ($this->config->get('verbose')) { $this->ui->outputData('Ignoring installed package ' . $reg->parsedPackageNameToString($package, true)); } unset($abstractpackages[$i]); } } } $abstractpackages = array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages); } elseif (count($abstractpackages)) { $abstractpackages = array_map(array($reg, 'parsedPackageNameToString'), $abstractpackages); } $packages = array_merge($abstractpackages, $otherpackages); if (!count($packages)) { $this->ui->outputData('Nothing to ' . $command); return true; } $this->downloader =& $this->getDownloader($this->ui, $options, $this->config); $errors = array(); $binaries = array(); $downloaded = array(); $downloaded =& $this->downloader->download($packages); if (PEAR::isError($downloaded)) { return $this->raiseError($downloaded); } $errors = $this->downloader->getErrorMsgs(); if (count($errors)) { $err = array(); $err['data'] = array(); foreach ($errors as $error) { $err['data'][] = array($error); } $err['headline'] = 'Install Errors'; $this->ui->outputData($err); if (!count($downloaded)) { return $this->raiseError("{$command} failed"); } } $data = array('headline' => 'Packages that would be Installed'); if (isset($options['pretend'])) { foreach ($downloaded as $package) { $data['data'][] = array($reg->parsedPackageNameToString($package->getParsedPackage())); } $this->ui->outputData($data, 'pretend'); return true; } $this->installer->setOptions($options); $this->installer->sortPackagesForInstall($downloaded); if (PEAR::isError($err = $this->installer->setDownloadedPackages($downloaded))) { $this->raiseError($err->getMessage()); return true; } $extrainfo = array(); $binaries = array(); foreach ($downloaded as $param) { PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $info = $this->installer->install($param, $options); PEAR::staticPopErrorHandling(); if (PEAR::isError($info)) { $oldinfo = $info; $pkg =& $param->getPackageFile(); if ($info->getCode() != PEAR_INSTALLER_NOBINARY) { if (!($info = $pkg->installBinary($this->installer))) { $this->ui->outputData('ERROR: ' . $oldinfo->getMessage()); continue; } // we just installed a different package than requested, // let's change the param and info so that the rest of this works $param = $info[0]; $info = $info[1]; } } if (is_array($info)) { if ($param->getPackageType() == 'extsrc' || $param->getPackageType() == 'extbin' || $param->getPackageType() == 'zendextsrc' || $param->getPackageType() == 'zendextbin') { $pkg =& $param->getPackageFile(); if ($instbin = $pkg->getInstalledBinary()) { $instpkg =& $instreg->getPackage($instbin, $pkg->getChannel()); } else { $instpkg =& $instreg->getPackage($pkg->getPackage(), $pkg->getChannel()); } foreach ($instpkg->getFilelist() as $name => $atts) { $pinfo = pathinfo($atts['installed_as']); if (!isset($pinfo['extension']) || in_array($pinfo['extension'], array('c', 'h'))) { continue; // make sure we don't match php_blah.h } if (strpos($pinfo['basename'], 'php_') === 0 && $pinfo['extension'] == 'dll' || $pinfo['extension'] == 'so' || $pinfo['extension'] == 'sl') { $binaries[] = array($atts['installed_as'], $pinfo); break; } } if (count($binaries)) { foreach ($binaries as $pinfo) { PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $ret = $this->enableExtension(array($pinfo[0]), $param->getPackageType()); PEAR::staticPopErrorHandling(); if (PEAR::isError($ret)) { $extrainfo[] = $ret->getMessage(); if ($param->getPackageType() == 'extsrc' || $param->getPackageType() == 'extbin') { $exttype = 'extension'; } else { ob_start(); phpinfo(INFO_GENERAL); $info = ob_get_contents(); ob_end_clean(); $debug = function_exists('leak') ? '_debug' : ''; $ts = preg_match('Thread Safety.+enabled', $info) ? '_ts' : ''; $exttype = 'zend_extension' . $debug . $ts; } $extrainfo[] = 'You should add "' . $exttype . '=' . $pinfo[1]['basename'] . '" to php.ini'; } else { $extrainfo[] = 'Extension ' . $instpkg->getProvidesExtension() . ' enabled in php.ini'; } } } } if ($this->config->get('verbose') > 0) { $channel = $param->getChannel(); $label = $reg->parsedPackageNameToString(array('channel' => $channel, 'package' => $param->getPackage(), 'version' => $param->getVersion())); $out = array('data' => "{$command} ok: {$label}"); if (isset($info['release_warnings'])) { $out['release_warnings'] = $info['release_warnings']; } $this->ui->outputData($out, $command); if (!isset($options['register-only']) && !isset($options['offline'])) { if ($this->config->isDefinedLayer('ftp')) { PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $info = $this->installer->ftpInstall($param); PEAR::staticPopErrorHandling(); if (PEAR::isError($info)) { $this->ui->outputData($info->getMessage()); $this->ui->outputData("remote install failed: {$label}"); } else { $this->ui->outputData("remote install ok: {$label}"); } } } } $deps = $param->getDeps(); if ($deps) { if (isset($deps['group'])) { $groups = $deps['group']; if (!isset($groups[0])) { $groups = array($groups); } foreach ($groups as $group) { if ($group['attribs']['name'] == 'default') { // default group is always installed, unless the user // explicitly chooses to install another group continue; } $extrainfo[] = $param->getPackage() . ': Optional feature ' . $group['attribs']['name'] . ' available (' . $group['attribs']['hint'] . ')'; } $extrainfo[] = $param->getPackage() . ': To install optional features use "pear install ' . $reg->parsedPackageNameToString(array('package' => $param->getPackage(), 'channel' => $param->getChannel()), true) . '#featurename"'; } } $pkg =& $instreg->getPackage($param->getPackage(), $param->getChannel()); // $pkg may be NULL if install is a 'fake' install via --packagingroot if (is_object($pkg)) { $pkg->setConfig($this->config); if ($list = $pkg->listPostinstallScripts()) { $pn = $reg->parsedPackageNameToString(array('channel' => $param->getChannel(), 'package' => $param->getPackage()), true); $extrainfo[] = $pn . ' has post-install scripts:'; foreach ($list as $file) { $extrainfo[] = $file; } $extrainfo[] = $param->getPackage() . ': Use "pear run-scripts ' . $pn . '" to finish setup.'; $extrainfo[] = 'DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES'; } } } else { return $this->raiseError("{$command} failed"); } } if (count($extrainfo)) { foreach ($extrainfo as $info) { $this->ui->outputData($info); } } return true; }
function _parsePackageXml(&$descfile, &$tmpdir) { if (substr($descfile, -4) == '.xml') { $tmpdir = false; } else { // {{{ Decompress pack in tmp dir ------------------------------------- // To allow relative package file names $descfile = realpath($descfile); if (PEAR::isError($tmpdir = System::mktemp('-d'))) { return $tmpdir; } $this->log(3, '+ tmp dir created at ' . $tmpdir); // }}} } // Parse xml file ----------------------------------------------- $pkg = new PEAR_PackageFile($this->config, $this->debug, $tmpdir); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $p =& $pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING); PEAR::staticPopErrorHandling(); if (PEAR::isError($p)) { if (is_array($p->getUserInfo())) { foreach ($p->getUserInfo() as $err) { $loglevel = $err['level'] == 'error' ? 0 : 1; if (!isset($this->_options['soft'])) { $this->log($loglevel, ucfirst($err['level']) . ': ' . $err['message']); } } } return $this->raiseError('Installation failed: invalid package file'); } else { $descfile = $p->getPackageFile(); } return $p; }
function _analyzeBundledPackages() { if (!$this->_isValid) { return false; } if (!$this->_pf->getPackageType() == 'bundle') { return false; } if (!isset($this->_pf->_packageFile)) { return false; } $dir_prefix = dirname($this->_pf->_packageFile); $common = new PEAR_Common(); $log = isset($this->_pf->_logger) ? array(&$this->_pf->_logger, 'log') : array($common, 'log'); $info = $this->_pf->getContents(); $info = $info['bundledpackage']; if (!is_array($info)) { $info = array($info); } $pkg = new PEAR_PackageFile($this->_pf->_config); foreach ($info as $package) { if (!file_exists($dir_prefix . DIRECTORY_SEPARATOR . $package)) { $this->_fileNotFound($dir_prefix . DIRECTORY_SEPARATOR . $package); $this->_isValid = 0; continue; } call_user_func_array($log, array(1, "Analyzing bundled package {$package}")); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $ret = $pkg->fromAnyFile($dir_prefix . DIRECTORY_SEPARATOR . $package, PEAR_VALIDATE_NORMAL); PEAR::popErrorHandling(); if (PEAR::isError($ret)) { call_user_func_array($log, array(0, "ERROR: package {$package} is not a valid " . 'package')); $inf = $ret->getUserInfo(); if (is_array($inf)) { foreach ($inf as $err) { call_user_func_array($log, array(1, $err['message'])); } } return false; } } return true; }
/** * Validate XML package definition file. * * @param string $info Filename of the package archive or of the * package definition file * @param array $errors Array that will contain the errors * @param array $warnings Array that will contain the warnings * @param string $dir_prefix (optional) directory where source files * may be found, or empty if they are not available * @access public * @return boolean * @deprecated use the validation of PEAR_PackageFile objects */ function validatePackageInfo($info, &$errors, &$warnings, $dir_prefix = '') { $config =& PEAR_Config::singleton(); $packagefile = new PEAR_PackageFile($config); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); if (strpos($info, '<?xml') !== false) { $pf =& $packagefile->fromXmlString($info, PEAR_VALIDATE_NORMAL, ''); } else { $pf =& $packagefile->fromAnyFile($info, PEAR_VALIDATE_NORMAL); } PEAR::staticPopErrorHandling(); if (PEAR::isError($pf)) { $errs = $pf->getUserinfo(); if (is_array($errs)) { foreach ($errs as $error) { if ($error['level'] == 'error') { $errors[] = $error['message']; } else { $warnings[] = $error['message']; } } } return false; } return true; }
function _parsePackageXml(&$descfile) { // Parse xml file $pkg = new PEAR_PackageFile($this->config, $this->debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $p =& $pkg->fromAnyFile($descfile, PEAR_VALIDATE_INSTALLING); PEAR::staticPopErrorHandling(); if (PEAR::isError($p)) { if (is_array($p->getUserInfo())) { foreach ($p->getUserInfo() as $err) { $loglevel = $err['level'] == 'error' ? 0 : 1; if (!isset($this->_options['soft'])) { $this->log($loglevel, ucfirst($err['level']) . ': ' . $err['message']); } } } return $this->raiseError('Installation failed: invalid package file'); } $descfile = $p->getPackageFile(); return $p; }
$options['upgrade'] = true; $install_root = getenv('INSTALL_ROOT'); if (!empty($install_root)) { $options['packagingroot'] = $install_root; $reg =& new PEAR_Registry($options['packagingroot'], false, false, $metadata_dir); } else { $reg = $config->getRegistry('default'); } $ui = PEAR_Frontend::singleton('PEAR_Frontend_CLI'); if (PEAR::isError($ui)) { die($ui->getMessage()); } $installer = new PEAR_Installer($ui); $pkg = new PEAR_PackageFile($config, $debug); foreach ($install_files as $package => $instfile) { $info = $pkg->fromAnyFile($instfile, PEAR_VALIDATE_INSTALLING); if (PEAR::isError($info)) { if (is_array($info->getUserInfo())) { foreach ($info->getUserInfo() as $err) { $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err['message'])); } } $ui->outputData(sprintf("[PEAR] %s: %s", $package, $info->getMessage())); continue; } $new_ver = $info->getVersion(); $downloaderpackage = new PEAR_Downloader_Package($installer); $err = $downloaderpackage->initialize($instfile); if (PEAR::isError($err)) { $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage())); continue;
<?php # $NetBSD: pear_plist.php,v 1.9 2015/12/11 16:16:48 taca Exp $ # Parses package XML file and outputs appropriate PLIST include_once "PEAR/Registry.php"; include_once "PEAR/PackageFile.php"; $PREFIX = getenv('PREFIX'); $PEAR_LIB = getenv('PEAR_LIB'); $WRKSRC = getenv('WRKSRC'); if (!($DESTDIR = getenv('DESTDIR'))) { $DESTDIR = ''; } $config = PEAR_Config::singleton(); $package = new PEAR_PackageFile($config); $info = $package->fromAnyFile("{$WRKSRC}/package.xml", PEAR_VALIDATE_INSTALLING); $pkg = $info->getName(); $channel = $info->getChannel(); $registry = new PEAR_Registry($DESTDIR . $PREFIX . "/" . $PEAR_LIB); $flist = $registry->packageInfo($pkg, 'filelist', $channel); $regfile = $PEAR_LIB . '/.registry/.channel.' . $channel . '/' . strtolower($pkg) . '.reg'; if (!file_exists($DESTDIR . $PREFIX . '/' . $regfile)) { $regfile = $PEAR_LIB . '/.registry/' . strtolower($pkg) . '.reg'; } echo "{$regfile}\n"; # output list of package files, in same order as specified in package foreach ($flist as $f) { echo str_replace($PREFIX . '/', '', $f['installed_as']) . "\n"; }
$pear_rest->savePackageMaintainerREST($package); echo "...done\n"; $releases = package::info($package, 'releases'); if ($releases) { echo " Processing All Releases..."; $pear_rest->saveAllReleasesREST($package); echo "done\n"; foreach ($releases as $version => $blah) { $sql = 'SELECT fullpath FROM files WHERE `release` = ?'; $fileinfo = $dbh->getOne($sql, array($blah['id'])); $tar =& new Archive_Tar($fileinfo); if ($pxml = $tar->extractInString('package2.xml')) { } elseif ($pxml = $tar->extractInString('package.xml')) { } PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $pf = $pkg->fromAnyFile($fileinfo, PEAR_VALIDATE_NORMAL); PEAR::popErrorHandling(); if (!PEAR::isError($pf)) { echo " Version {$version}..."; $pear_rest->saveReleaseREST($fileinfo, $pxml, $pf, $blah['doneby'], $blah['id']); echo "done\n"; } else { echo " Skipping INVALID Version {$version}\n"; } } echo "\n"; } else { echo " done\n"; } } echo "Generating Category Package REST...\n";
function doInfo($command, $options, $params) { if (count($params) !== 1) { return $this->raiseError('pear info expects 1 parameter'); } $info = $fp = false; $reg =& $this->config->getRegistry(); if (is_file($params[0]) && !is_dir($params[0]) && (file_exists($params[0]) || ($fp = @fopen($params[0], 'r')))) { if ($fp) { fclose($fp); } if (!class_exists('PEAR_PackageFile')) { require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/PEAR/PackageFile.php'; } $pkg = new PEAR_PackageFile($this->config, $this->_debug); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $obj =& $pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL); PEAR::staticPopErrorHandling(); if (PEAR::isError($obj)) { $uinfo = $obj->getUserInfo(); if (is_array($uinfo)) { foreach ($uinfo as $message) { if (is_array($message)) { $message = $message['message']; } $this->ui->outputData($message); } } return $this->raiseError($obj); } if ($obj->getPackagexmlVersion() != '1.0') { return $this->_doInfo2($command, $options, $params, $obj, false); } $info = $obj->toArray(); } else { $parsed = $reg->parsePackageName($params[0], $this->config->get('default_channel')); if (PEAR::isError($parsed)) { return $this->raiseError($parsed); } $package = $parsed['package']; $channel = $parsed['channel']; $info = $reg->packageInfo($package, null, $channel); if (isset($info['old'])) { $obj = $reg->getPackage($package, $channel); return $this->_doInfo2($command, $options, $params, $obj, true); } } if (PEAR::isError($info)) { return $info; } if (empty($info)) { $this->raiseError("No information found for `{$params['0']}'"); return; } unset($info['filelist']); unset($info['dirtree']); unset($info['changelog']); if (isset($info['xsdversion'])) { $info['package.xml version'] = $info['xsdversion']; unset($info['xsdversion']); } if (isset($info['packagerversion'])) { $info['packaged with PEAR version'] = $info['packagerversion']; unset($info['packagerversion']); } $keys = array_keys($info); $longtext = array('description', 'summary'); foreach ($keys as $key) { if (is_array($info[$key])) { switch ($key) { case 'maintainers': $i = 0; $mstr = ''; foreach ($info[$key] as $m) { if ($i++ > 0) { $mstr .= "\n"; } $mstr .= $m['name'] . " <"; if (isset($m['email'])) { $mstr .= $m['email']; } else { $mstr .= $m['handle'] . '@php.net'; } $mstr .= "> ({$m['role']})"; } $info[$key] = $mstr; break; case 'release_deps': $i = 0; $dstr = ''; foreach ($info[$key] as $d) { if (isset($this->_deps_rel_trans[$d['rel']])) { $rel = $this->_deps_rel_trans[$d['rel']]; } else { $rel = $d['rel']; } if (isset($this->_deps_type_trans[$d['type']])) { $type = ucfirst($this->_deps_type_trans[$d['type']]); } else { $type = $d['type']; } if (isset($d['name'])) { $name = $d['name'] . ' '; } else { $name = ''; } if (isset($d['version'])) { $version = $d['version'] . ' '; } else { $version = ''; } if (isset($d['optional']) && $d['optional'] == 'yes') { $optional = ' (optional)'; } else { $optional = ''; } $dstr .= "{$type} {$name}{$rel} {$version}{$optional}\n"; } $info[$key] = $dstr; break; case 'provides': $debug = $this->config->get('verbose'); if ($debug < 2) { $pstr = 'Classes: '; } else { $pstr = ''; } $i = 0; foreach ($info[$key] as $p) { if ($debug < 2 && $p['type'] != "class") { continue; } // Only print classes when verbosity mode is < 2 if ($debug < 2) { if ($i++ > 0) { $pstr .= ", "; } $pstr .= $p['name']; } else { if ($i++ > 0) { $pstr .= "\n"; } $pstr .= ucfirst($p['type']) . " " . $p['name']; if (isset($p['explicit']) && $p['explicit'] == 1) { $pstr .= " (explicit)"; } } } $info[$key] = $pstr; break; case 'configure_options': foreach ($info[$key] as $i => $p) { $info[$key][$i] = array_map(null, array_keys($p), array_values($p)); $info[$key][$i] = array_map(create_function('$a', 'return join(" = ",$a);'), $info[$key][$i]); $info[$key][$i] = implode(', ', $info[$key][$i]); } $info[$key] = implode("\n", $info[$key]); break; default: $info[$key] = implode(", ", $info[$key]); break; } } if ($key == '_lastmodified') { $hdate = date('Y-m-d', $info[$key]); unset($info[$key]); $info['Last Modified'] = $hdate; } elseif ($key == '_lastversion') { $info['Previous Installed Version'] = $info[$key] ? $info[$key] : '- None -'; unset($info[$key]); } else { $info[$key] = trim($info[$key]); if (in_array($key, $longtext)) { $info[$key] = preg_replace('/ +/', ' ', $info[$key]); } } } $caption = 'About ' . $info['package'] . '-' . $info['version']; $data = array('caption' => $caption, 'border' => true); foreach ($info as $key => $value) { $key = ucwords(trim(str_replace('_', ' ', $key))); $data['data'][] = array($key, $value); } $data['raw'] = $info; $this->ui->outputData($data, 'package-info'); }