Adjust all usages of VersionSelector to the new API
parent
419567ba6d
commit
8a2dd1baef
|
@ -28,6 +28,7 @@
|
||||||
- there is a top level `"dev"` key which stores whether dev requirements were installed or not
|
- there is a top level `"dev"` key which stores whether dev requirements were installed or not
|
||||||
- `PreFileDownloadEvent` now receives an `HttpDownloader` instance instead of `RemoteFilesystem`, and that instance can not be overridden by listeners anymore
|
- `PreFileDownloadEvent` now receives an `HttpDownloader` instance instead of `RemoteFilesystem`, and that instance can not be overridden by listeners anymore
|
||||||
- `VersionSelector::findBestCandidate`'s third argument (phpVersion) was removed in favor of passing in a complete PlatformRepository instance into the constructor
|
- `VersionSelector::findBestCandidate`'s third argument (phpVersion) was removed in favor of passing in a complete PlatformRepository instance into the constructor
|
||||||
|
- `InitCommand::determineRequirements`'s fourth argument (phpVersion) should now receive a complete PlatformRepository instance or null if platform requirements are to be ignored
|
||||||
- `IOInterface` now extends PSR-3's `LoggerInterface`, and has new `writeRaw` + `writeErrorRaw` methods
|
- `IOInterface` now extends PSR-3's `LoggerInterface`, and has new `writeRaw` + `writeErrorRaw` methods
|
||||||
- `RepositoryInterface` changes:
|
- `RepositoryInterface` changes:
|
||||||
- A new `loadPackages(array $packageNameMap, array $acceptableStabilities, array $stabilityFlags)` function was added for use during pool building
|
- A new `loadPackages(array $packageNameMap, array $acceptableStabilities, array $stabilityFlags)` function was added for use during pool building
|
||||||
|
|
|
@ -336,25 +336,20 @@ EOT
|
||||||
$repositorySet = new RepositorySet($stability);
|
$repositorySet = new RepositorySet($stability);
|
||||||
$repositorySet->addRepository($sourceRepo);
|
$repositorySet->addRepository($sourceRepo);
|
||||||
|
|
||||||
$phpVersion = null;
|
$platformRepo = null;
|
||||||
$prettyPhpVersion = null;
|
|
||||||
if (!$ignorePlatformReqs) {
|
if (!$ignorePlatformReqs) {
|
||||||
$platformOverrides = $config->get('platform') ?: array();
|
$platformOverrides = $config->get('platform') ?: array();
|
||||||
// initialize $this->repos as it is used by the parent InitCommand
|
$platformRepo = new PlatformRepository(array(), $platformOverrides);
|
||||||
$platform = new PlatformRepository(array(), $platformOverrides);
|
|
||||||
$phpPackage = $platform->findPackage('php', '*');
|
|
||||||
$phpVersion = $phpPackage->getVersion();
|
|
||||||
$prettyPhpVersion = $phpPackage->getPrettyVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the latest version if there are multiple
|
// find the latest version if there are multiple
|
||||||
$versionSelector = new VersionSelector($repositorySet);
|
$versionSelector = new VersionSelector($repositorySet, $platformRepo);
|
||||||
$package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability);
|
$package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability);
|
||||||
|
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
$errorMessage = "Could not find package $name with " . ($packageVersion ? "version $packageVersion" : "stability $stability");
|
$errorMessage = "Could not find package $name with " . ($packageVersion ? "version $packageVersion" : "stability $stability");
|
||||||
if ($phpVersion && $versionSelector->findBestCandidate($name, $packageVersion, null, $stability)) {
|
if ($platformRepo && $versionSelector->findBestCandidate($name, $packageVersion, $stability, true)) {
|
||||||
throw new \InvalidArgumentException($errorMessage .' in a version installable using your PHP version '.$prettyPhpVersion.'.');
|
throw new \InvalidArgumentException($errorMessage .' in a version installable using your PHP version, PHP extensions and Composer version.');
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException($errorMessage .'.');
|
throw new \InvalidArgumentException($errorMessage .'.');
|
||||||
|
|
|
@ -345,13 +345,21 @@ EOT
|
||||||
// prepare to resolve dependencies
|
// prepare to resolve dependencies
|
||||||
$repos = $this->getRepos();
|
$repos = $this->getRepos();
|
||||||
$preferredStability = $minimumStability ?: 'stable';
|
$preferredStability = $minimumStability ?: 'stable';
|
||||||
$phpVersion = $repos->findPackage('php', '*')->getPrettyVersion();
|
$platformRepo = null;
|
||||||
|
if ($repos instanceof CompositeRepository) {
|
||||||
|
foreach ($repos->getRepositories() as $candidateRepo) {
|
||||||
|
if ($candidateRepo instanceof PlatformRepository) {
|
||||||
|
$platformRepo = $candidateRepo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$question = 'Would you like to define your dependencies (require) interactively [<comment>yes</comment>]? ';
|
$question = 'Would you like to define your dependencies (require) interactively [<comment>yes</comment>]? ';
|
||||||
$require = $input->getOption('require');
|
$require = $input->getOption('require');
|
||||||
$requirements = array();
|
$requirements = array();
|
||||||
if ($require || $io->askConfirmation($question, true)) {
|
if ($require || $io->askConfirmation($question, true)) {
|
||||||
$requirements = $this->determineRequirements($input, $output, $require, $phpVersion, $preferredStability);
|
$requirements = $this->determineRequirements($input, $output, $require, $platformRepo, $preferredStability);
|
||||||
}
|
}
|
||||||
$input->setOption('require', $requirements);
|
$input->setOption('require', $requirements);
|
||||||
|
|
||||||
|
@ -359,7 +367,7 @@ EOT
|
||||||
$requireDev = $input->getOption('require-dev');
|
$requireDev = $input->getOption('require-dev');
|
||||||
$devRequirements = array();
|
$devRequirements = array();
|
||||||
if ($requireDev || $io->askConfirmation($question, true)) {
|
if ($requireDev || $io->askConfirmation($question, true)) {
|
||||||
$devRequirements = $this->determineRequirements($input, $output, $requireDev, $phpVersion, $preferredStability);
|
$devRequirements = $this->determineRequirements($input, $output, $requireDev, $platformRepo, $preferredStability);
|
||||||
}
|
}
|
||||||
$input->setOption('require-dev', $devRequirements);
|
$input->setOption('require-dev', $devRequirements);
|
||||||
}
|
}
|
||||||
|
@ -403,7 +411,7 @@ EOT
|
||||||
return $this->repos;
|
return $this->repos;
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), $phpVersion = null, $preferredStability = 'stable', $checkProvidedVersions = true, $fixed = false)
|
final protected function determineRequirements(InputInterface $input, OutputInterface $output, $requires = array(), PlatformRepository $platformRepo = null, $preferredStability = 'stable', $checkProvidedVersions = true, $fixed = false)
|
||||||
{
|
{
|
||||||
if ($requires) {
|
if ($requires) {
|
||||||
$requires = $this->normalizeRequirements($requires);
|
$requires = $this->normalizeRequirements($requires);
|
||||||
|
@ -413,7 +421,7 @@ EOT
|
||||||
foreach ($requires as $requirement) {
|
foreach ($requires as $requirement) {
|
||||||
if (!isset($requirement['version'])) {
|
if (!isset($requirement['version'])) {
|
||||||
// determine the best version automatically
|
// determine the best version automatically
|
||||||
list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $phpVersion, $preferredStability, null, null, $fixed);
|
list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $platformRepo, $preferredStability, null, null, $fixed);
|
||||||
$requirement['version'] = $version;
|
$requirement['version'] = $version;
|
||||||
|
|
||||||
// replace package name from packagist.org
|
// replace package name from packagist.org
|
||||||
|
@ -426,7 +434,7 @@ EOT
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// check that the specified version/constraint exists before we proceed
|
// check that the specified version/constraint exists before we proceed
|
||||||
list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $phpVersion, $preferredStability, $checkProvidedVersions ? $requirement['version'] : null, 'dev', $fixed);
|
list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $platformRepo, $preferredStability, $checkProvidedVersions ? $requirement['version'] : null, 'dev', $fixed);
|
||||||
|
|
||||||
// replace package name from packagist.org
|
// replace package name from packagist.org
|
||||||
$requirement['name'] = $name;
|
$requirement['name'] = $name;
|
||||||
|
@ -550,7 +558,7 @@ EOT
|
||||||
);
|
);
|
||||||
|
|
||||||
if (false === $constraint) {
|
if (false === $constraint) {
|
||||||
list($name, $constraint) = $this->findBestVersionAndNameForPackage($input, $package, $phpVersion, $preferredStability);
|
list($name, $constraint) = $this->findBestVersionAndNameForPackage($input, $package, $platformRepo, $preferredStability);
|
||||||
|
|
||||||
$io->writeError(sprintf(
|
$io->writeError(sprintf(
|
||||||
'Using version <info>%s</info> for <info>%s</info>',
|
'Using version <info>%s</info> for <info>%s</info>',
|
||||||
|
@ -723,7 +731,7 @@ EOT
|
||||||
*
|
*
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string|null $phpVersion
|
* @param PlatformRepository|null $platformRepo
|
||||||
* @param string $preferredStability
|
* @param string $preferredStability
|
||||||
* @param string|null $requiredVersion
|
* @param string|null $requiredVersion
|
||||||
* @param string $minimumStability
|
* @param string $minimumStability
|
||||||
|
@ -731,18 +739,18 @@ EOT
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
* @return array name version
|
* @return array name version
|
||||||
*/
|
*/
|
||||||
private function findBestVersionAndNameForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null, $fixed = null)
|
private function findBestVersionAndNameForPackage(InputInterface $input, $name, PlatformRepository $platformRepo = null, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null, $fixed = null)
|
||||||
{
|
{
|
||||||
// find the latest version allowed in this repo set
|
// ignore platform repo if platform requirements are ignored
|
||||||
$versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability));
|
|
||||||
$ignorePlatformReqs = $input->hasOption('ignore-platform-reqs') && $input->getOption('ignore-platform-reqs');
|
$ignorePlatformReqs = $input->hasOption('ignore-platform-reqs') && $input->getOption('ignore-platform-reqs');
|
||||||
|
|
||||||
// ignore phpVersion if platform requirements are ignored
|
|
||||||
if ($ignorePlatformReqs) {
|
if ($ignorePlatformReqs) {
|
||||||
$phpVersion = null;
|
$platformRepo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$package = $versionSelector->findBestCandidate($name, $requiredVersion, $phpVersion, $preferredStability);
|
// find the latest version allowed in this repo set
|
||||||
|
$versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability), $platformRepo);
|
||||||
|
|
||||||
|
$package = $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability);
|
||||||
|
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
// platform packages can not be found in the pool in versions other than the local platform's has
|
// platform packages can not be found in the pool in versions other than the local platform's has
|
||||||
|
@ -752,28 +760,26 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the PHP version was the problem
|
// Check whether the PHP version was the problem
|
||||||
if ($phpVersion && $versionSelector->findBestCandidate($name, $requiredVersion, null, $preferredStability)) {
|
if ($platformRepo && $versionSelector->findBestCandidate($name, $requiredVersion, $preferredStability, true)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Package %s at version %s has a PHP requirement incompatible with your PHP version (%s)',
|
'Package %s at version %s has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version',
|
||||||
$name,
|
$name,
|
||||||
$requiredVersion,
|
$requiredVersion
|
||||||
$phpVersion
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Check whether the required version was the problem
|
// Check whether the required version was the problem
|
||||||
if ($requiredVersion && $versionSelector->findBestCandidate($name, null, $phpVersion, $preferredStability)) {
|
if ($requiredVersion && $versionSelector->findBestCandidate($name, null, $preferredStability)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Could not find package %s in a version matching %s',
|
'Could not find package %s in a version matching %s',
|
||||||
$name,
|
$name,
|
||||||
$requiredVersion
|
$requiredVersion
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Check whether the PHP version was the problem
|
// Check whether the PHP version was the problem for all versions
|
||||||
if ($phpVersion && $versionSelector->findBestCandidate($name)) {
|
if ($platformRepo && $versionSelector->findBestCandidate($name, null, $preferredStability, true)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Could not find package %s in any version matching your PHP version (%s)',
|
'Could not find package %s in any version matching your PHP version, PHP extensions and Composer version',
|
||||||
$name,
|
$name
|
||||||
$phpVersion
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ EOT
|
||||||
$platformOverrides = $composer->getConfig()->get('platform') ?: array();
|
$platformOverrides = $composer->getConfig()->get('platform') ?: array();
|
||||||
// initialize $this->repos as it is used by the parent InitCommand
|
// initialize $this->repos as it is used by the parent InitCommand
|
||||||
$this->repos = new CompositeRepository(array_merge(
|
$this->repos = new CompositeRepository(array_merge(
|
||||||
array(new PlatformRepository(array(), $platformOverrides)),
|
array($platformRepo = new PlatformRepository(array(), $platformOverrides)),
|
||||||
$repos
|
$repos
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -176,9 +176,16 @@ EOT
|
||||||
$preferredStability = $composer->getPackage()->getMinimumStability();
|
$preferredStability = $composer->getPackage()->getMinimumStability();
|
||||||
}
|
}
|
||||||
|
|
||||||
$phpVersion = $this->repos->findPackage('php', '*')->getPrettyVersion();
|
|
||||||
try {
|
try {
|
||||||
$requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'), $phpVersion, $preferredStability, !$input->getOption('no-update'), $input->getOption('fixed'));
|
$requirements = $this->determineRequirements(
|
||||||
|
$input,
|
||||||
|
$output,
|
||||||
|
$input->getArgument('packages'),
|
||||||
|
$input->getOption('ignore-platform-reqs') ? null : $platformRepo,
|
||||||
|
$preferredStability,
|
||||||
|
!$input->getOption('no-update'),
|
||||||
|
$input->getOption('fixed')
|
||||||
|
);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($this->newlyCreated) {
|
if ($this->newlyCreated) {
|
||||||
throw new \RuntimeException('No composer.json present in the current directory, this may be the cause of the following exception.', 0, $e);
|
throw new \RuntimeException('No composer.json present in the current directory, this may be the cause of the following exception.', 0, $e);
|
||||||
|
|
|
@ -151,7 +151,6 @@ EOT
|
||||||
}
|
}
|
||||||
$platformRepo = new PlatformRepository(array(), $platformOverrides);
|
$platformRepo = new PlatformRepository(array(), $platformOverrides);
|
||||||
$lockedRepo = null;
|
$lockedRepo = null;
|
||||||
$phpVersion = $platformRepo->findPackage('php', '*')->getVersion();
|
|
||||||
|
|
||||||
if ($input->getOption('self')) {
|
if ($input->getOption('self')) {
|
||||||
$package = $this->getComposer()->getPackage();
|
$package = $this->getComposer()->getPackage();
|
||||||
|
@ -249,7 +248,7 @@ EOT
|
||||||
} else {
|
} else {
|
||||||
$latestPackage = null;
|
$latestPackage = null;
|
||||||
if ($input->getOption('latest')) {
|
if ($input->getOption('latest')) {
|
||||||
$latestPackage = $this->findLatestPackage($package, $composer, $phpVersion);
|
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo);
|
||||||
}
|
}
|
||||||
if ($input->getOption('outdated') && $input->getOption('strict') && $latestPackage && $latestPackage->getFullPrettyVersion() !== $package->getFullPrettyVersion() && !$latestPackage->isAbandoned()) {
|
if ($input->getOption('outdated') && $input->getOption('strict') && $latestPackage && $latestPackage->getFullPrettyVersion() !== $package->getFullPrettyVersion() && !$latestPackage->isAbandoned()) {
|
||||||
$exitCode = 1;
|
$exitCode = 1;
|
||||||
|
@ -382,7 +381,7 @@ EOT
|
||||||
if ($showLatest && $showVersion) {
|
if ($showLatest && $showVersion) {
|
||||||
foreach ($packages[$type] as $package) {
|
foreach ($packages[$type] as $package) {
|
||||||
if (is_object($package)) {
|
if (is_object($package)) {
|
||||||
$latestPackage = $this->findLatestPackage($package, $composer, $phpVersion, $showMinorOnly);
|
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly);
|
||||||
if ($latestPackage === false) {
|
if ($latestPackage === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1182,16 +1181,16 @@ EOT
|
||||||
*
|
*
|
||||||
* @param PackageInterface $package
|
* @param PackageInterface $package
|
||||||
* @param Composer $composer
|
* @param Composer $composer
|
||||||
* @param string $phpVersion
|
* @param PlatformRepository $platformRepo
|
||||||
* @param bool $minorOnly
|
* @param bool $minorOnly
|
||||||
*
|
*
|
||||||
* @return PackageInterface|false
|
* @return PackageInterface|false
|
||||||
*/
|
*/
|
||||||
private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false)
|
private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, $minorOnly = false)
|
||||||
{
|
{
|
||||||
// find the latest version allowed in this repo set
|
// find the latest version allowed in this repo set
|
||||||
$name = $package->getName();
|
$name = $package->getName();
|
||||||
$versionSelector = new VersionSelector($this->getRepositorySet($composer));
|
$versionSelector = new VersionSelector($this->getRepositorySet($composer), $platformRepo);
|
||||||
$stability = $composer->getPackage()->getMinimumStability();
|
$stability = $composer->getPackage()->getMinimumStability();
|
||||||
$flags = $composer->getPackage()->getStabilityFlags();
|
$flags = $composer->getPackage()->getStabilityFlags();
|
||||||
if (isset($flags[$name])) {
|
if (isset($flags[$name])) {
|
||||||
|
@ -1212,7 +1211,7 @@ EOT
|
||||||
$targetVersion = '^' . $package->getVersion();
|
$targetVersion = '^' . $package->getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability);
|
return $versionSelector->findBestCandidate($name, $targetVersion, $bestStability);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRepositorySet(Composer $composer)
|
private function getRepositorySet(Composer $composer)
|
||||||
|
|
Loading…
Reference in New Issue