本文整理汇总了PHP中Composer\Repository\RepositoryInterface::getPackages方法的典型用法代码示例。如果您正苦于以下问题:PHP RepositoryInterface::getPackages方法的具体用法?PHP RepositoryInterface::getPackages怎么用?PHP RepositoryInterface::getPackages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Repository\RepositoryInterface
的用法示例。
在下文中一共展示了RepositoryInterface::getPackages方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processPackages
private function processPackages()
{
foreach ($this->repos->getPackages() as $package) {
if ($package instanceof CompletePackageInterface) {
$this->processPackageDependencies($package);
}
}
}
示例2: loadRepository
public function loadRepository(RepositoryInterface $repo)
{
foreach ($repo->getPackages() as $package) {
if ($package instanceof AliasPackage) {
continue;
}
if ('composer-plugin' === $package->getType()) {
$requiresComposer = null;
foreach ($package->getRequires() as $link) {
if ($link->getTarget() == 'composer-plugin-api') {
$requiresComposer = $link->getConstraint();
}
}
if (!$requiresComposer) {
throw new \RuntimeException("Plugin " . $package->getName() . " is missing a require statement for a version of the composer-plugin-api package.");
}
if (!$requiresComposer->matches(new VersionConstraint('==', $this->versionParser->normalize(PluginInterface::PLUGIN_API_VERSION)))) {
$this->io->writeError("<warning>The plugin " . $package->getName() . " requires a version of composer-plugin-api that does not match your composer installation. You may need to run composer update with the '--no-plugins' option.</warning>");
}
$this->registerPackage($package);
}
if ('composer-installer' === $package->getType()) {
$this->registerPackage($package);
}
}
}
示例3: setupInstalledMap
protected function setupInstalledMap()
{
$this->installedMap = array();
foreach ($this->installed->getPackages() as $package) {
$this->installedMap[$package->id] = $package;
}
}
示例4: update
/**
* Update a project
*
* @param \Packagist\WebBundle\Entity\Package $package
* @param RepositoryInterface $repository the repository instance used to update from
* @param int $flags a few of the constants of this class
* @param \DateTime $start
*/
public function update(Package $package, RepositoryInterface $repository, $flags = 0, \DateTime $start = null)
{
$blacklist = '{^symfony/symfony (2.0.[456]|dev-charset|dev-console)}i';
if (null === $start) {
$start = new \DateTime();
}
$pruneDate = clone $start;
$pruneDate->modify('-8days');
$versions = $repository->getPackages();
$em = $this->doctrine->getManager();
if ($repository->hadInvalidBranches()) {
throw new InvalidRepositoryException('Some branches contained invalid data and were discarded, it is advised to review the log and fix any issues present in branches');
}
usort($versions, function ($a, $b) {
$aVersion = $a->getVersion();
$bVersion = $b->getVersion();
if ($aVersion === '9999999-dev' || 'dev-' === substr($aVersion, 0, 4)) {
$aVersion = 'dev';
}
if ($bVersion === '9999999-dev' || 'dev-' === substr($bVersion, 0, 4)) {
$bVersion = 'dev';
}
if ($aVersion === $bVersion) {
return $a->getReleaseDate() > $b->getReleaseDate() ? 1 : -1;
}
return version_compare($a->getVersion(), $b->getVersion());
});
$versionRepository = $this->doctrine->getRepository('PackagistWebBundle:Version');
if ($flags & self::DELETE_BEFORE) {
foreach ($package->getVersions() as $version) {
$versionRepository->remove($version);
}
$em->flush();
$em->refresh($package);
}
foreach ($versions as $version) {
if ($version instanceof AliasPackage) {
continue;
}
if (preg_match($blacklist, $version->getName() . ' ' . $version->getPrettyVersion())) {
continue;
}
$this->updateInformation($package, $version, $flags);
$em->flush();
}
// remove outdated versions
foreach ($package->getVersions() as $version) {
if ($version->getUpdatedAt() < $pruneDate) {
$versionRepository->remove($version);
}
}
$package->setUpdatedAt(new \DateTime());
$package->setCrawledAt(new \DateTime());
$em->flush();
}
示例5: addRepository
/**
* Adds a repository and its packages to this package pool
*
* @param RepositoryInterface $repo A package repository
*/
public function addRepository(RepositoryInterface $repo)
{
$this->repositories[] = $repo;
foreach ($repo->getPackages() as $package) {
$package->setId(count($this->packages) + 1);
$this->packages[] = $package;
foreach ($package->getNames() as $name) {
$this->packageByName[$name][] = $package;
}
}
}
示例6: filterRequiredPackages
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
{
$requires = array_keys($package->getRequires());
$packageListNames = array_keys($bucket);
$packages = array_filter($repo->getPackages(), function ($package) use($requires, $packageListNames) {
return in_array($package->getName(), $requires) && !in_array($package->getName(), $packageListNames);
});
$bucket = $this->appendPackages($packages, $bucket);
foreach ($packages as $package) {
$bucket = $this->filterRequiredPackages($repo, $package, $bucket);
}
return $bucket;
}
示例7: output
/**
* Output suggested packages.
* Do not list the ones already installed if installed repository provided.
*
* @param RepositoryInterface $installedRepo Installed packages
* @return SuggestedPackagesReporter
*/
public function output(RepositoryInterface $installedRepo = null)
{
$suggestedPackages = $this->getPackages();
$installedPackages = array();
if (null !== $installedRepo && !empty($suggestedPackages)) {
foreach ($installedRepo->getPackages() as $package) {
$installedPackages = array_merge($installedPackages, $package->getNames());
}
}
foreach ($suggestedPackages as $suggestion) {
if (in_array($suggestion['target'], $installedPackages)) {
continue;
}
$this->io->writeError(sprintf('%s suggests installing %s (%s)', $suggestion['source'], $suggestion['target'], $suggestion['reason']));
}
return $this;
}
示例8: addRepository
public function addRepository(RepositoryInterface $repo, $rootAliases = array())
{
if ($repo instanceof CompositeRepository) {
$repos = $repo->getRepositories();
} else {
$repos = array($repo);
}
foreach ($repos as $repo) {
$this->repositories[] = $repo;
$exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface;
if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
$this->providerRepos[] = $repo;
$repo->setRootAliases($rootAliases);
$repo->resetPackageIds();
} else {
foreach ($repo->getPackages() as $package) {
$names = $package->getNames();
$stability = $package->getStability();
if ($exempt || $this->isPackageAcceptable($names, $stability)) {
$package->setId($this->id++);
$this->packages[] = $package;
$this->packageByExactName[$package->getName()][$package->id] = $package;
foreach ($names as $provided) {
$this->packageByName[$provided][] = $package;
}
$name = $package->getName();
if (isset($rootAliases[$name][$package->getVersion()])) {
$alias = $rootAliases[$name][$package->getVersion()];
if ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
$aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
$aliasPackage->setRootPackageAlias(true);
$aliasPackage->setId($this->id++);
$package->getRepository()->addPackage($aliasPackage);
$this->packages[] = $aliasPackage;
$this->packageByExactName[$aliasPackage->getName()][$aliasPackage->id] = $aliasPackage;
foreach ($aliasPackage->getNames() as $name) {
$this->packageByName[$name][] = $aliasPackage;
}
}
}
}
}
}
}
示例9: collectData
public function collectData(RepositoryInterface $repo)
{
$puzzleData = [];
foreach ($repo->getPackages() as $package) {
/** @var Package $package */
$extra = $package->getExtra();
if (!empty($extra["downsider-puzzle-di"]) && is_array($extra["downsider-puzzle-di"])) {
foreach ($extra["downsider-puzzle-di"] as $key => $config) {
if ($key == (string) (int) $key) {
continue;
}
if (!array_key_exists($key, $puzzleData)) {
$puzzleData[$key] = array();
}
$puzzleConfig = ["name" => $package->getName(), "path" => $this->installationManager->getInstallPath($package) . "/" . $config["path"]];
if (!empty($config["alias"])) {
$puzzleConfig["alias"] = $config["alias"];
}
$puzzleData[$key][] = $puzzleConfig;
}
}
}
return $puzzleData;
}
示例10: addRepository
/**
* Adds a repository and its packages to this package pool
*
* @param RepositoryInterface $repo A package repository
*/
public function addRepository(RepositoryInterface $repo)
{
if ($repo instanceof CompositeRepository) {
$repos = $repo->getRepositories();
} else {
$repos = array($repo);
}
$id = count($this->packages) + 1;
foreach ($repos as $repo) {
$this->repositories[] = $repo;
$exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface;
foreach ($repo->getPackages() as $package) {
$name = $package->getName();
$stability = $package->getStability();
if ($exempt || !isset($this->stabilityFlags[$name]) && isset($this->acceptableStabilities[$stability]) || isset($this->stabilityFlags[$name]) && BasePackage::$stabilities[$stability] <= $this->stabilityFlags[$name]) {
$package->setId($id++);
$this->packages[] = $package;
foreach ($package->getNames() as $name) {
$this->packageByName[$name][] = $package;
}
}
}
}
}
示例11: createRequest
private function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo)
{
$request = new Request($pool);
$constraint = new VersionConstraint('=', $rootPackage->getVersion());
$constraint->setPrettyString($rootPackage->getPrettyVersion());
$request->install($rootPackage->getName(), $constraint);
$fixedPackages = $platformRepo->getPackages();
if ($this->additionalInstalledRepository) {
$additionalFixedPackages = $this->additionalInstalledRepository->getPackages();
$fixedPackages = array_merge($fixedPackages, $additionalFixedPackages);
}
// fix the version of all platform packages + additionally installed packages
// to prevent the solver trying to remove or update those
$provided = $rootPackage->getProvides();
foreach ($fixedPackages as $package) {
$constraint = new VersionConstraint('=', $package->getVersion());
$constraint->setPrettyString($package->getPrettyVersion());
// skip platform packages that are provided by the root package
if ($package->getRepository() !== $platformRepo || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) {
$request->fix($package->getName(), $constraint);
}
}
return $request;
}
示例12: mapFromRepo
protected function mapFromRepo(RepositoryInterface $repo)
{
$map = array();
foreach ($repo->getPackages() as $package) {
$map[$package->getId()] = true;
}
return $map;
}
示例13: getPackage
/**
* finds a package by name and version if provided
*
* @param InputInterface $input
* @return PackageInterface
* @throws \InvalidArgumentException
*/
protected function getPackage(InputInterface $input, OutputInterface $output, RepositoryInterface $installedRepo, RepositoryInterface $repos)
{
// we have a name and a version so we can use ::findPackage
if ($input->getArgument('version')) {
return $repos->findPackage($input->getArgument('package'), $input->getArgument('version'));
}
// check if we have a local installation so we can grab the right package/version
foreach ($installedRepo->getPackages() as $package) {
if ($package->getName() === $input->getArgument('package')) {
return $package;
}
}
// we only have a name, so search for the highest version of the given package
$highestVersion = null;
foreach ($repos->findPackages($input->getArgument('package')) as $package) {
if (null === $highestVersion || version_compare($package->getVersion(), $highestVersion->getVersion(), '>=')) {
$highestVersion = $package;
}
}
return $highestVersion;
}
示例14: loadRepository
/**
* Load all plugins and installers from a repository
*
* Note that plugins in the specified repository that rely on events that
* have fired prior to loading will be missed. This means you likely want to
* call this method as early as possible.
*
* @param RepositoryInterface $repo Repository to scan for plugins to install
*
* @throws \RuntimeException
*/
private function loadRepository(RepositoryInterface $repo)
{
foreach ($repo->getPackages() as $package) {
/** @var PackageInterface $package */
if ($package instanceof AliasPackage) {
continue;
}
if ('composer-plugin' === $package->getType()) {
$this->registerPackage($package);
// Backward compatibility
} elseif ('composer-installer' === $package->getType()) {
$this->registerPackage($package);
}
}
}
示例15: createPool
private function createPool($withDevReqs, RepositoryInterface $lockedRepository = null)
{
if (!$this->update && $this->locker->isLocked()) {
$minimumStability = $this->locker->getMinimumStability();
$stabilityFlags = $this->locker->getStabilityFlags();
$requires = array();
foreach ($lockedRepository->getPackages() as $package) {
$constraint = new VersionConstraint('=', $package->getVersion());
$constraint->setPrettyString($package->getPrettyVersion());
$requires[$package->getName()] = $constraint;
}
} else {
$minimumStability = $this->package->getMinimumStability();
$stabilityFlags = $this->package->getStabilityFlags();
$requires = $this->package->getRequires();
if ($withDevReqs) {
$requires = array_merge($requires, $this->package->getDevRequires());
}
}
$rootConstraints = array();
foreach ($requires as $req => $constraint) {
if ($this->ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) {
continue;
}
if ($constraint instanceof Link) {
$rootConstraints[$req] = $constraint->getConstraint();
} else {
$rootConstraints[$req] = $constraint;
}
}
return new Pool($minimumStability, $stabilityFlags, $rootConstraints);
}