Skip to content

Commit

Permalink
Merge pull request #51 from boesing/qa/forward-compatibility-composer
Browse files Browse the repository at this point in the history
Forward compatibility for composer v2.3.6+
  • Loading branch information
boesing authored Jul 3, 2022
2 parents 6af4680 + a520b7d commit 9d70b71
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/PackageProvider/PackageProviderDetectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

use Composer\Composer;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Repository\CompositeRepository;
use Composer\Repository\InstalledArrayRepository;
use Composer\Repository\InstalledRepository;
use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryFactory;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositoryInterface as ComposerRepositoryInterface;
use Composer\Repository\RootPackageRepository;

use function method_exists;

/**
* @internal
*/
Expand All @@ -37,7 +41,7 @@ public static function create(Composer $composer): self
public function detect(PackageEvent $event, string $packageName): PackageProviderDetectionInterface
{
$installedRepo = new InstalledRepository($this->prepareRepositoriesForInstalledRepository());
$defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos(new NullIO()));
$defaultRepos = new CompositeRepository($this->createDefaultRepos(new NullIO()));

if (
($match = $defaultRepos->findPackage($packageName, '*'))
Expand All @@ -63,4 +67,16 @@ private function prepareRepositoriesForInstalledRepository(): array
new PlatformRepository([], $platformOverrides),
];
}

/**
* @return RepositoryInterface[]
*/
private function createDefaultRepos(IOInterface $io): array
{
if (method_exists(RepositoryFactory::class, 'defaultReposWithDefaultManager')) {
return RepositoryFactory::defaultReposWithDefaultManager($io);
}

return RepositoryFactory::defaultRepos($io);
}
}

0 comments on commit 9d70b71

Please sign in to comment.