本文整理汇总了PHP中Composer\Repository\RepositoryInterface::hasPackage方法的典型用法代码示例。如果您正苦于以下问题:PHP RepositoryInterface::hasPackage方法的具体用法?PHP RepositoryInterface::hasPackage怎么用?PHP RepositoryInterface::hasPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Repository\RepositoryInterface
的用法示例。
在下文中一共展示了RepositoryInterface::hasPackage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: markAliasInstalled
public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
{
$package = $operation->getPackage();
$this->installed[] = $package;
$this->trace[] = (string) $operation;
if (!$repo->hasPackage($package)) {
$repo->addPackage($package);
}
}
示例2: markAliasInstalled
/**
* Executes markAliasInstalled operation.
*
* @param RepositoryInterface $repo repository in which to check
* @param MarkAliasInstalledOperation $operation operation instance
*/
public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
{
$package = $operation->getPackage();
if (!$repo->hasPackage($package)) {
$repo->addPackage(clone $package);
}
}
示例3: printVersions
/**
* prints all available versions of this package and highlights the installed one if any
*/
protected function printVersions(InputInterface $input, OutputInterface $output, PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos)
{
if ($input->getArgument('version')) {
$output->writeln('<info>version</info> : ' . $package->getPrettyVersion());
return;
}
$versions = array();
foreach ($repos->findPackages($package->getName()) as $version) {
$versions[$version->getPrettyVersion()] = $version->getVersion();
}
uasort($versions, 'version_compare');
$versions = implode(', ', array_keys(array_reverse($versions)));
// highlight installed version
if ($installedRepo->hasPackage($package)) {
$versions = str_replace($package->getPrettyVersion(), '<info>* ' . $package->getPrettyVersion() . '</info>', $versions);
}
$output->writeln('<info>versions</info> : ' . $versions);
}
示例4: getPackage
protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
{
$name = strtolower($name);
$constraint = null;
if ($version) {
$constraint = $this->versionParser->parseConstraints($version);
}
$policy = new DefaultPolicy();
$pool = new Pool('dev');
$pool->addRepository($repos);
$matchedPackage = null;
$versions = array();
$matches = $pool->whatProvides($name, $constraint);
foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
// select an exact match if it is in the installed repo and no specific version was required
if (null === $version && $installedRepo->hasPackage($package)) {
$matchedPackage = $package;
}
$versions[$package->getPrettyVersion()] = $package->getVersion();
$matches[$index] = $package->getId();
}
// select prefered package according to policy rules
if (!$matchedPackage && $matches && ($prefered = $policy->selectPreferedPackages($pool, array(), $matches))) {
$matchedPackage = $pool->literalToPackage($prefered[0]);
}
return array($matchedPackage, $versions);
}
示例5: printVersions
/**
* prints all available versions of this package and highlights the installed one if any
*/
protected function printVersions(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
{
uasort($versions, 'version_compare');
$versions = array_keys(array_reverse($versions));
// highlight installed version
if ($installedRepo->hasPackage($package)) {
$installedVersion = $package->getPrettyVersion();
$key = array_search($installedVersion, $versions);
if (false !== $key) {
$versions[$key] = '<info>* ' . $installedVersion . '</info>';
}
}
$versions = implode(', ', $versions);
$output->writeln('<info>versions</info> : ' . $versions);
}
示例6: getPackage
/**
* Finds a package by name and version if provided.
*
* @param RepositoryInterface $installedRepo
* @param RepositoryInterface $repos
* @param string $name
* @param string|null $version
*
* @throws \InvalidArgumentException
*
* @return array [CompletePackageInterface, array of versions]
*/
protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
{
$name = strtolower($name);
$constraint = null;
if ($version !== null) {
$constraint = $this->versionParser->parseConstraints($version);
}
$policy = new DefaultPolicy();
$pool = new Pool('dev');
$pool->addRepository($repos);
$matchedPackage = null;
$versions = [];
$matches = $pool->whatProvides($name, $constraint);
foreach ($matches as $index => $package) {
// Skip providers/replacers.
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
// Select an exact match if it is in the installed repo and no specific version was required.
if ($version === null && $installedRepo->hasPackage($package)) {
$matchedPackage = $package;
}
$versions[$package->getPrettyVersion()] = $package->getVersion();
$matches[$index] = $package->getId();
}
// Select prefered package according to policy rules.
if (!$matchedPackage && !empty($matches) && ($prefered = $policy->selectPreferredPackages($pool, [], $matches))) {
$matchedPackage = $pool->literalToPackage($prefered[0]);
}
// If we have package result, return them.
if ($matchedPackage) {
return [$matchedPackage->getName() => ['package' => $matchedPackage, 'versions' => $versions]];
}
return null;
}