本文整理汇总了PHP中PEAR_Registry::packageExists方法的典型用法代码示例。如果您正苦于以下问题:PHP PEAR_Registry::packageExists方法的具体用法?PHP PEAR_Registry::packageExists怎么用?PHP PEAR_Registry::packageExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PEAR_Registry
的用法示例。
在下文中一共展示了PEAR_Registry::packageExists方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isInstalled
function isInstalled($dep, $oper = '==')
{
if (!$dep) {
return false;
}
if ($oper != 'ge' && $oper != 'gt' && $oper != 'has' && $oper != '==') {
return false;
}
if (is_object($dep)) {
$package = $dep->getPackage();
$channel = $dep->getChannel();
if ($dep->getURI()) {
$dep = array('uri' => $dep->getURI(), 'version' => $dep->getVersion());
} else {
$dep = array('version' => $dep->getVersion());
}
} else {
if (isset($dep['uri'])) {
$channel = '__uri';
$package = $dep['dep']['name'];
} else {
$channel = $dep['info']->getChannel();
$package = $dep['info']->getPackage();
}
}
$options = $this->_downloader->getOptions();
$test = $this->_registry->packageExists($package, $channel);
if (!$test && $channel == 'pecl.php.net') {
// do magic to allow upgrading from old pecl packages to new ones
$test = $this->_registry->packageExists($package, 'pear.php.net');
$channel = 'pear.php.net';
}
if ($test) {
if (isset($dep['uri'])) {
if ($this->_registry->packageInfo($package, 'uri', '__uri') == $dep['uri']) {
return true;
}
}
if (isset($options['upgrade'])) {
if ($oper == 'has') {
if (version_compare($this->_registry->packageInfo($package, 'version', $channel), $dep['version'], '>=')) {
return true;
} else {
return false;
}
} else {
if (version_compare($this->_registry->packageInfo($package, 'version', $channel), $dep['version'], '>=')) {
return true;
}
return false;
}
}
return true;
}
return false;
}
示例2: array
$ch_cmd =& PEAR_Command::factory('update-channels', $config);
$ch_cmd->run('update-channels', $options, array());
PEAR::staticPopErrorHandling();
// reset error handling
unset($ch_cmd);
print "\n" . 'Installing selected packages..................' . "\n";
displayHTMLProgress($progress = 45);
$install =& PEAR_Command::factory('install', $config);
foreach ($to_install as $pkg) {
$pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
if (in_array($pkg, $installer_packages)) {
$options = array('nodeps' => true);
} else {
$options = array('onlyreqdeps' => true);
}
if ($registry->packageExists($pkg) || $registry->packageExists($pkg_basename)) {
print str_pad("Package: {$pkg}", max(50, 9 + strlen($pkg) + 4), '.') . ' already installed ... ok' . "\n";
displayHTMLProgress($progress += round(50 / count($to_install)));
continue;
}
$pkg_basename = substr($pkg, 0, strpos($pkg, '-'));
if (in_array($pkg_basename, $bootstrap_pkgs)) {
print str_pad("Installing bootstrap package: {$pkg_basename}", max(50, 30 + strlen($pkg_basename) + 4), '.') . "...";
displayHTMLProgress($progress += round(25 / count($to_install)));
$install->run('install', $options, array($bootstrap_pkgs_tarballs[$pkg_basename]));
} elseif (isset($local_dir[$pkg_basename])) {
print str_pad("Installing local package: {$pkg}", max(50, 26 + strlen($pkg) + 4), '.') . "...";
displayHTMLProgress($progress += round(25 / count($to_install)));
$install->run('install', $options, array($gopear_bundle_dir . '/' . $local_dir[$pkg_basename]));
} else {
// no local copy
示例3: doInstall
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);
//.........这里部分代码省略.........
示例4: validatePackageUninstall
/**
* Verify that uninstalling packages passed in to command line is OK.
*
* @param PEAR_Installer $dl
* @return PEAR_Error|true
*/
function validatePackageUninstall(&$dl)
{
if (PEAR::isError($this->_dependencydb)) {
return $this->_dependencydb;
}
$params = array();
// construct an array of "downloaded" packages to fool the package dependency checker
// into using these to validate uninstalls of circular dependencies
$downloaded =& $dl->getUninstallPackages();
foreach ($downloaded as $i => $pf) {
if (!class_exists('PEAR_Downloader_Package')) {
require_once 'PEAR/Downloader/Package.php';
}
$dp =& new PEAR_Downloader_Package($dl);
$dp->setPackageFile($downloaded[$i]);
$params[$i] =& $dp;
}
// check cache
$memyselfandI = strtolower($this->_currentPackage['channel']) . '/' . strtolower($this->_currentPackage['package']);
if (isset($dl->___uninstall_package_cache)) {
$badpackages = $dl->___uninstall_package_cache;
if (isset($badpackages[$memyselfandI]['warnings'])) {
foreach ($badpackages[$memyselfandI]['warnings'] as $warning) {
$dl->log(0, $warning[0]);
}
}
if (isset($badpackages[$memyselfandI]['errors'])) {
foreach ($badpackages[$memyselfandI]['errors'] as $error) {
if (is_array($error)) {
$dl->log(0, $error[0]);
} else {
$dl->log(0, $error->getMessage());
}
}
if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
return $this->warning('warning: %s should not be uninstalled, other installed packages depend ' . 'on this package');
}
return $this->raiseError('%s cannot be uninstalled, other installed packages depend on this package');
}
return true;
}
// first, list the immediate parents of each package to be uninstalled
$perpackagelist = array();
$allparents = array();
foreach ($params as $i => $param) {
$a = array('channel' => strtolower($param->getChannel()), 'package' => strtolower($param->getPackage()));
$deps = $this->_dependencydb->getDependentPackages($a);
if ($deps) {
foreach ($deps as $d) {
$pardeps = $this->_dependencydb->getDependencies($d);
foreach ($pardeps as $dep) {
if (strtolower($dep['dep']['channel']) == $a['channel'] && strtolower($dep['dep']['name']) == $a['package']) {
if (!isset($perpackagelist[$a['channel'] . '/' . $a['package']])) {
$perpackagelist[$a['channel'] . '/' . $a['package']] = array();
}
$perpackagelist[$a['channel'] . '/' . $a['package']][] = array($d['channel'] . '/' . $d['package'], $dep);
if (!isset($allparents[$d['channel'] . '/' . $d['package']])) {
$allparents[$d['channel'] . '/' . $d['package']] = array();
}
if (!isset($allparents[$d['channel'] . '/' . $d['package']][$a['channel'] . '/' . $a['package']])) {
$allparents[$d['channel'] . '/' . $d['package']][$a['channel'] . '/' . $a['package']] = array();
}
$allparents[$d['channel'] . '/' . $d['package']][$a['channel'] . '/' . $a['package']][] = array($d, $dep);
}
}
}
}
}
// next, remove any packages from the parents list that are not installed
$remove = array();
foreach ($allparents as $parent => $d1) {
foreach ($d1 as $d) {
if ($this->_registry->packageExists($d[0][0]['package'], $d[0][0]['channel'])) {
continue;
}
$remove[$parent] = true;
}
}
// next remove any packages from the parents list that are not passed in for
// uninstallation
foreach ($allparents as $parent => $d1) {
foreach ($d1 as $d) {
foreach ($params as $param) {
if (strtolower($param->getChannel()) == $d[0][0]['channel'] && strtolower($param->getPackage()) == $d[0][0]['package']) {
// found it
continue 3;
}
}
$remove[$parent] = true;
}
}
// remove all packages whose dependencies fail
// save which ones failed for error reporting
$badchildren = array();
//.........这里部分代码省略.........
示例5: packageExists
/**
* (non-PHPdoc)
* @see lib/Faett/Core/Interfaces/Faett_Core_Interfaces_Service#packageExists($packageName, $alias)
*/
public function packageExists($packageName, $alias)
{
return $this->_registry->packageExists($packageName, $alias);
}
示例6: foreach
function _validatePackageDownload($dep, $required, $params, $depv1 = false)
{
$dep['package'] = $dep['name'];
if (isset($dep['uri'])) {
$dep['channel'] = '__uri';
}
$depname = $this->_registry->parsedPackageNameToString($dep, true);
$found = false;
foreach ($params as $param) {
if ($param->isEqual(array('package' => $dep['name'], 'channel' => $dep['channel']))) {
$found = true;
break;
}
if ($depv1 && $dep['channel'] == 'pear.php.net') {
if ($param->isEqual(array('package' => $dep['name'], 'channel' => 'pecl.php.net'))) {
$found = true;
break;
}
}
}
if (!$found && isset($dep['providesextension'])) {
foreach ($params as $param) {
if ($param->isExtension($dep['providesextension'])) {
$found = true;
break;
}
}
}
if ($found) {
$version = $param->getVersion();
$installed = false;
$downloaded = true;
} else {
if ($this->_registry->packageExists($dep['name'], $dep['channel'])) {
$installed = true;
$downloaded = false;
$version = $this->_registry->packageinfo($dep['name'], 'version', $dep['channel']);
} else {
if ($dep['channel'] == 'pecl.php.net' && $this->_registry->packageExists($dep['name'], 'pear.php.net')) {
$installed = true;
$downloaded = false;
$version = $this->_registry->packageinfo($dep['name'], 'version', 'pear.php.net');
} else {
$version = 'not installed or downloaded';
$installed = false;
$downloaded = false;
}
}
}
$extra = $this->_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
}
if (!isset($dep['min']) && !isset($dep['max']) && !isset($dep['recommended']) && !isset($dep['exclude'])) {
if ($installed || $downloaded) {
$installed = $installed ? 'installed' : 'downloaded';
if (isset($dep['conflicts'])) {
if ($version) {
$rest = ", {$installed} version is " . $version;
} else {
$rest = '';
}
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s conflicts with package "' . $depname . '"' . $extra . $rest);
} else {
return $this->warning('warning: %s conflicts with package "' . $depname . '"' . $extra . $rest);
}
}
return true;
} else {
if (isset($dep['conflicts'])) {
return true;
}
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires package "' . $depname . '"' . $extra);
} else {
return $this->warning('warning: %s requires package "' . $depname . '"' . $extra);
}
} else {
return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
}
}
}
if (!$installed && !$downloaded) {
if (isset($dep['conflicts'])) {
return true;
}
if ($required) {
if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
return $this->raiseError('%s requires package "' . $depname . '"' . $extra);
} else {
return $this->warning('warning: %s requires package "' . $depname . '"' . $extra);
}
} else {
return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
}
}
//.........这里部分代码省略.........
示例7: elseif
/**
* @return false|PEAR_Error|string false if loop should be broken out of,
* string if the file was downloaded,
* PEAR_Error on exception
* @access private
*/
function _downloadNonFile($pkgfile)
{
$origpkgfile = $pkgfile;
$state = null;
$pkgfile = $this->extractDownloadFileName($pkgfile, $version);
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
return $this->_downloadFile($pkgfile, $version, $origpkgfile);
}
if (!$this->validPackageName($pkgfile)) {
return $this->raiseError("Package name '{$pkgfile}' not valid");
}
// ignore packages that are installed unless we are upgrading
$curinfo = $this->_registry->packageInfo($pkgfile);
if ($this->_registry->packageExists($pkgfile) && empty($this->_options['upgrade']) && empty($this->_options['force'])) {
$this->log(0, "Package '{$curinfo['package']}' already installed, skipping");
return false;
}
if (in_array($pkgfile, $this->_toDownload)) {
return false;
}
$releases = $this->_remote->call('package.info', $pkgfile, 'releases', true);
if (!count($releases)) {
return $this->raiseError("No releases found for package '{$pkgfile}'");
}
// Want a specific version/state
if ($version !== null) {
// Passed Foo-1.2
if ($this->validPackageVersion($version)) {
if (!isset($releases[$version])) {
return $this->raiseError("No release with version '{$version}' found for '{$pkgfile}'");
}
// Passed Foo-alpha
} elseif (in_array($version, $this->getReleaseStates())) {
$state = $version;
$version = 0;
foreach ($releases as $ver => $inf) {
if ($inf['state'] == $state && version_compare("{$version}", "{$ver}") < 0) {
$version = $ver;
break;
}
}
if ($version == 0) {
return $this->raiseError("No release with state '{$state}' found for '{$pkgfile}'");
}
// invalid postfix passed
} else {
return $this->raiseError("Invalid postfix '-{$version}', be sure to pass a valid PEAR " . "version number or release state");
}
// Guess what to download
} else {
$states = $this->betterStates($this->_preferredState, true);
$possible = false;
$version = 0;
foreach ($releases as $ver => $inf) {
if (in_array($inf['state'], $states) && version_compare("{$version}", "{$ver}") < 0) {
$version = $ver;
break;
}
}
if ($version === 0 && !isset($this->_options['force'])) {
return $this->raiseError('No release with state equal to: \'' . implode(', ', $states) . "' found for '{$pkgfile}'");
} elseif ($version === 0) {
$this->log(0, "Warning: {$pkgfile} is state '{$inf['state']}' which is less stable " . "than state '{$this->_preferredState}'");
}
}
// Check if we haven't already the version
if (empty($this->_options['force']) && !is_null($curinfo)) {
if ($curinfo['version'] == $version) {
$this->log(0, "Package '{$curinfo['package']}-{$curinfo['version']}' already installed, skipping");
return false;
} elseif (version_compare("{$version}", "{$curinfo['version']}") < 0) {
$this->log(0, "Package '{$curinfo['package']}' version '{$curinfo['version']}' " . " is installed and {$curinfo['version']} is > requested '{$version}', skipping");
return false;
}
}
$this->_toDownload[] = $pkgfile;
return $this->_downloadFile($pkgfile, $version, $origpkgfile, $state);
}
示例8: install
//.........这里部分代码省略.........
if (is_string($info)) {
// pear.php.net packages are always stored as strings
if (strtolower($info) == strtolower($param->getPackage())) {
// upgrading existing package
unset($test[$file]);
}
}
}
}
if (count($test)) {
$msg = "{$channel}/{$pkgname}: conflicting files found:\n";
$longest = max(array_map("strlen", array_keys($test)));
$fmt = "%{$longest}s (%s)\n";
foreach ($test as $file => $info) {
if (!is_array($info)) {
$info = array('pear.php.net', $info);
}
$info = $info[0] . '/' . $info[1];
$msg .= sprintf($fmt, $file, $info);
}
if (!isset($options['ignore-errors'])) {
return $this->raiseError($msg);
}
if (!isset($options['soft'])) {
$this->log(0, "WARNING: {$msg}");
}
}
}
}
// }}}
$this->startFileTransaction();
$usechannel = $channel;
if ($channel == 'pecl.php.net') {
$test = $installregistry->packageExists($pkgname, $channel);
if (!$test) {
$test = $installregistry->packageExists($pkgname, 'pear.php.net');
$usechannel = 'pear.php.net';
}
} else {
$test = $installregistry->packageExists($pkgname, $channel);
}
if (empty($options['upgrade']) && empty($options['soft'])) {
// checks to do only when installing new packages
if (empty($options['force']) && $test) {
return $this->raiseError("{$channel}/{$pkgname} is already installed");
}
} else {
// Upgrade
if ($test) {
$v1 = $installregistry->packageInfo($pkgname, 'version', $usechannel);
$v2 = $pkg->getVersion();
$cmp = version_compare("{$v1}", "{$v2}", 'gt');
if (empty($options['force']) && !version_compare("{$v2}", "{$v1}", 'gt')) {
return $this->raiseError("upgrade to a newer version ({$v2} is not newer than {$v1})");
}
}
}
// Do cleanups for upgrade and install, remove old release's files first
if ($test && empty($options['register-only'])) {
// when upgrading, remove old release's files first:
if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel, true))) {
if (!isset($options['ignore-errors'])) {
return $this->raiseError($err);
}
if (!isset($options['soft'])) {
$this->log(0, 'WARNING: ' . $err->getMessage());
示例9: array
$config =& PEAR_Config::singleton($prefix . "/pear.conf", '');
} else {
$config =& PEAR_Config::singleton();
}
$config->set('preferred_state', 'stable');
foreach ($config_vars as $var) {
$config->set($var, ${$var});
}
$config->store();
$registry = new PEAR_Registry($php_dir);
PEAR_Command::setFrontendType('CLI');
$install =& PEAR_Command::factory('install', $config);
$install_options = array('nodeps' => true, 'force' => true);
foreach ($tarball as $pkg => $src) {
$options = $install_options;
if ($registry->packageExists($pkg)) {
$options['upgrade'] = true;
}
$install->run('install', $options, array($src));
displayHTMLProgress($progress += round(29 / count($tarball)));
}
displayHTMLProgress($progress = 99);
// Base installation finished
ini_restore("include_path");
if (!WEBINSTALLER) {
$sep = WINDOWS ? ';' : ':';
$include_path = explode($sep, ini_get('include_path'));
if (WINDOWS) {
$found = false;
$t = strtolower($php_dir);
foreach ($include_path as $path) {
示例10: doShellTest
function doShellTest($command, $options, $params)
{
$this->pushErrorHandling(PEAR_ERROR_RETURN);
$reg = new PEAR_Registry($this->config->get('php_dir'));
// "pear shell-test Foo"
if (sizeof($params) == 1) {
if (!$reg->packageExists($params[0])) {
exit(1);
}
// "pear shell-test Foo 1.0"
} elseif (sizeof($params) == 2) {
$v = $reg->packageInfo($params[0], 'version');
if (!$v || !version_compare("{$v}", "{$params[1]}", "ge")) {
exit(1);
}
// "pear shell-test Foo ge 1.0"
} elseif (sizeof($params) == 3) {
$v = $reg->packageInfo($params[0], 'version');
if (!$v || !version_compare("{$v}", "{$params[2]}", $params[1])) {
exit(1);
}
} else {
$this->popErrorHandling();
$this->raiseError("{$command}: expects 1 to 3 parameters");
exit(1);
}
}
示例11: packageInstalled
/**
* Check if a package is installed
*/
function packageInstalled($package_name, $version = null, $pear_user_config = null)
{
if (is_null($pear_user_config)) {
$config = new PEAR_Config();
} else {
$config = new PEAR_Config($pear_user_config);
}
$reg = new PEAR_Registry($config->get('php_dir'));
if (is_null($version)) {
return $reg->packageExists($package_name);
} else {
$installed = $reg->packageInfo($package_name);
return version_compare($version, $installed['version'], '<=');
}
}