本文整理汇总了PHP中Composer\Repository\RepositoryInterface::findPackages方法的典型用法代码示例。如果您正苦于以下问题:PHP RepositoryInterface::findPackages方法的具体用法?PHP RepositoryInterface::findPackages怎么用?PHP RepositoryInterface::findPackages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Repository\RepositoryInterface
的用法示例。
在下文中一共展示了RepositoryInterface::findPackages方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decorate
/**
* Decorate a package.
*
* @param string $packageName The name of the package to decorate.
*
* @return VersionedPackage
*
* @throws \InvalidArgumentException When the package could not be found.
*/
protected function decorate($packageName)
{
$results = $this->repository->findPackages($packageName);
if (!count($results)) {
throw new \InvalidArgumentException('Could not find package with specified name ' . $packageName);
}
$latest = array_slice($results, 0, 1)[0];
$versions = array_slice($results, 1);
$package = new VersionedPackage($latest, $versions);
return $this->decorateWithPackagistStats($package);
}
示例2: 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);
}
示例3: processDevPackages
/**
* @param WritableRepositoryInterface $localRepo
* @param Pool $pool
* @param PolicyInterface $policy
* @param array $repositories
* @param RepositoryInterface $installedRepo
* @param RepositoryInterface $lockedRepository
* @param string $task
* @param array|null $operations
* @return array
*/
private function processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $task, array $operations = null)
{
if ($task === 'force-updates' && null === $operations) {
throw new \InvalidArgumentException('Missing operations argument');
}
if ($task === 'force-links') {
$operations = array();
}
if ($this->update && $this->updateWhitelist) {
$currentPackages = $this->getCurrentPackages($installedRepo);
}
foreach ($localRepo->getCanonicalPackages() as $package) {
// skip non-dev packages
if (!$package->isDev()) {
continue;
}
// skip packages that will be updated/uninstalled
foreach ($operations as $operation) {
if ('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package) || 'uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package)) {
continue 2;
}
}
if ($this->update) {
// skip package if the whitelist is enabled and it is not in it
if ($this->updateWhitelist && !$this->isUpdateable($package)) {
// check if non-updateable packages are out of date compared to the lock file to ensure we don't corrupt it
foreach ($currentPackages as $curPackage) {
if ($curPackage->isDev() && $curPackage->getName() === $package->getName() && $curPackage->getVersion() === $package->getVersion()) {
if ($task === 'force-links') {
$package->setRequires($curPackage->getRequires());
$package->setConflicts($curPackage->getConflicts());
$package->setProvides($curPackage->getProvides());
$package->setReplaces($curPackage->getReplaces());
} elseif ($task === 'force-updates') {
if ($curPackage->getSourceReference() && $curPackage->getSourceReference() !== $package->getSourceReference() || $curPackage->getDistReference() && $curPackage->getDistReference() !== $package->getDistReference()) {
$operations[] = new UpdateOperation($package, $curPackage);
}
}
break;
}
}
continue;
}
// find similar packages (name/version) in all repositories
$matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()));
foreach ($matches as $index => $match) {
// skip local packages
if (!in_array($match->getRepository(), $repositories, true)) {
unset($matches[$index]);
continue;
}
// skip providers/replacers
if ($match->getName() !== $package->getName()) {
unset($matches[$index]);
continue;
}
$matches[$index] = $match->getId();
}
// select preferred package according to policy rules
if ($matches && ($matches = $policy->selectPreferredPackages($pool, array(), $matches))) {
$newPackage = $pool->literalToPackage($matches[0]);
if ($task === 'force-links' && $newPackage) {
$package->setRequires($newPackage->getRequires());
$package->setConflicts($newPackage->getConflicts());
$package->setProvides($newPackage->getProvides());
$package->setReplaces($newPackage->getReplaces());
}
if ($task === 'force-updates' && $newPackage && ($newPackage->getSourceReference() && $newPackage->getSourceReference() !== $package->getSourceReference() || $newPackage->getDistReference() && $newPackage->getDistReference() !== $package->getDistReference())) {
$operations[] = new UpdateOperation($package, $newPackage);
continue;
}
}
if ($task === 'force-updates') {
// force installed package to update to referenced version in root package if it does not match the installed version
$references = $this->package->getReferences();
if (isset($references[$package->getName()]) && $references[$package->getName()] !== $package->getSourceReference()) {
// changing the source ref to update to will be handled in the operations loop
$operations[] = new UpdateOperation($package, clone $package);
}
}
} else {
// force update to locked version if it does not match the installed version
foreach ($lockedRepository->findPackages($package->getName()) as $lockedPackage) {
if ($lockedPackage->isDev() && $lockedPackage->getVersion() === $package->getVersion()) {
if ($task === 'force-links') {
$package->setRequires($lockedPackage->getRequires());
$package->setConflicts($lockedPackage->getConflicts());
$package->setProvides($lockedPackage->getProvides());
$package->setReplaces($lockedPackage->getReplaces());
//.........这里部分代码省略.........
示例4: getPackages
/**
* Gets All or filtered Packages of a Repository.
*
* @param RepositoryInterface $repo a Repository
*
* @return PackageInterface[]
*/
private function getPackages(RepositoryInterface $repo)
{
$packages = array();
if ($this->hasFilterForPackages()) {
// apply package filter if defined
foreach ($this->packagesFilter as $filter) {
$packages += $repo->findPackages($filter);
}
} else {
// process other repos directly
$packages = $repo->getPackages();
}
return $packages;
}
示例5: findPackage
/**
* Search the repository for a package.
*
* @param string $name The pretty name of the package to search.
*
* @param RepositoryInterface $repository The repository to be searched.
*
* @return null|PackageInterface
*/
private function findPackage($name, RepositoryInterface $repository)
{
/** @var PackageInterface[] $packages */
$packages = $repository->findPackages($name);
while (!empty($packages) && $packages[0] instanceof AliasPackage) {
array_shift($packages);
}
if (empty($packages)) {
return null;
}
return $packages[0];
}
示例6: buildNotInstalledList
/**
* Build a list of not yet installed packages.
*
* @param RepositoryInterface $repository
*
* @return array
*/
public function buildNotInstalledList(RootPackageInterface $rootPackage, RepositoryInterface $localRepository)
{
$requires = $rootPackage->getRequires();
$notInstalledList = array();
/** @var Link $requiredConstraint */
foreach ($requires as $requiredName => $requiredConstraint) {
$packages = $localRepository->findPackages($requiredName);
if (empty($packages)) {
$notInstalledList[$requiredName] = $requiredConstraint;
}
}
return $notInstalledList;
}
示例7: getInstalledVersion
/**
* Retrieve the installed version of a package (if any).
*
* @param RepositoryInterface $localRepository The local repository.
*
* @param string $packageName The name of the package to search.
*
* @return null|string
*/
private function getInstalledVersion($localRepository, $packageName)
{
if (count($installed = $localRepository->findPackages($packageName))) {
/** @var PackageInterface[] $installed */
return $installed[0]->getPrettyVersion();
}
return null;
}