diff --git a/src/Composer/Command/PackageDiscoveryTrait.php b/src/Composer/Command/PackageDiscoveryTrait.php index 5e210bd7c..7b0716f55 100644 --- a/src/Composer/Command/PackageDiscoveryTrait.php +++ b/src/Composer/Command/PackageDiscoveryTrait.php @@ -97,6 +97,10 @@ trait PackageDiscoveryTrait $io = $this->getIO(); foreach ($requires as $requirement) { + if (isset($requirement['version']) && Preg::isMatch('{^\d+(\.\d+)?$}', $requirement['version'])) { + $io->writeError('The "'.$requirement['version'].'" constraint for "'.$requirement['name'].'" appears too strict and will likely not match what you want. See https://getcomposer.org/constraints'); + } + if (!isset($requirement['version'])) { // determine the best version automatically list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $platformRepo, $preferredStability, null, null, $fixed); diff --git a/src/Composer/DependencyResolver/SolverProblemsException.php b/src/Composer/DependencyResolver/SolverProblemsException.php index ea8c86af5..cd4f49075 100644 --- a/src/Composer/DependencyResolver/SolverProblemsException.php +++ b/src/Composer/DependencyResolver/SolverProblemsException.php @@ -117,9 +117,9 @@ class SolverProblemsException extends \RuntimeException return ''; } - $ignoreExtensionsArguments = implode(" ", array_map(function ($extension) { + $ignoreExtensionsArguments = implode(" ", array_map(static function ($extension) { return "--ignore-platform-req=$extension"; - }, $missingExtensions)); + }, array_unique($missingExtensions))); $text = "To enable extensions, verify that they are enabled in your .ini files:\n - "; $text .= implode("\n - ", $paths); diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index dd5e4219b..d4ae079d2 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -287,6 +287,11 @@ class Factory */ public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false, ?string $cwd = null, bool $fullLoad = true, bool $disableScripts = false) { + // if a custom composer.json path is given, we change the default cwd to be that file's directory + if (is_string($localConfig) && is_file($localConfig) && null === $cwd) { + $cwd = dirname($localConfig); + } + $cwd = $cwd ?? Platform::getCwd(true); // load Composer configuration diff --git a/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test b/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test index 9fab8e4cb..2c698a2a6 100644 --- a/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test +++ b/tests/Composer/Test/Fixtures/installer/solver-problems-with-disabled-platform.test @@ -81,7 +81,6 @@ Your requirements could not be resolved to an installable set of packages. To enable extensions, verify that they are enabled in your .ini files: __inilist__ You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode. -Alternatively, you can run Composer with `--ignore-platform-req=ext-foobar --ignore-platform-req=ext-pcre --ignore-platform-req=ext-foobar --ignore-platform-req=ext-pcre` to temporarily ignore these required extensions. +Alternatively, you can run Composer with `--ignore-platform-req=ext-foobar --ignore-platform-req=ext-pcre` to temporarily ignore these required extensions. --EXPECT-- -