diff --git a/core/lib/Drupal/Core/Composer/Dependencies/DevDependencyFinder.php b/core/lib/Drupal/Core/Composer/Dependencies/DevDependencyFinder.php index 7ccc470257..97df2e16df 100644 --- a/core/lib/Drupal/Core/Composer/Dependencies/DevDependencyFinder.php +++ b/core/lib/Drupal/Core/Composer/Dependencies/DevDependencyFinder.php @@ -53,13 +53,7 @@ public function buildRequirements() { $dev_requirements = $this->projectRoot->getDevRequirements(); // Make a list of installed dev requirements. - $installed_dev = []; - $installed_package_names = array_keys($installed); - foreach (array_keys($dev_requirements) as $dev_requirement_name) { - if (in_array($dev_requirement_name, $installed_package_names)) { - $installed_dev[$dev_requirement_name] = $installed[$dev_requirement_name]; - } - } + $installed_dev = array_intersect_key($installed, $dev_requirements); // If the number of dev requirements and installed dev requirements is // exactly the same, then we reason that the user probably issued a @@ -75,12 +69,12 @@ public function buildRequirements() { // for core's dev requirements. And we're unable to tell the difference // anyway. $dev_installed = FALSE; - if (!empty($installed_dev) && (count($installed_dev) === count($dev_requirements))) { + if ($installed_dev && (count($installed_dev) === count($dev_requirements))) { $dev_installed = TRUE; foreach ($dev_requirements as $package_name => $version_constraint) { // Special case for @dev packages, which can generate unparseable local // version numbers, such as [behat/mink] => 9999999-dev. - if (!strpos($version_constraint, 'dev')) { + if (strpos($version_constraint, 'dev') === FALSE) { if (!Semver::satisfies($installed_dev[$package_name], $version_constraint)) { $dev_installed = FALSE; break; diff --git a/core/lib/Drupal/Core/Composer/ProjectRoot.php b/core/lib/Drupal/Core/Composer/ProjectRoot.php index 930ad6621d..1ffd2a3cc9 100644 --- a/core/lib/Drupal/Core/Composer/ProjectRoot.php +++ b/core/lib/Drupal/Core/Composer/ProjectRoot.php @@ -40,6 +40,11 @@ public function __construct($app_root) { */ public function getProjectVendorDirectory() { if (empty($this->vendorDirectory)) { + // In order to discover the vendor directory, we require the Drupal class + // loader facade which is always in appRoot. appRoot/autoload.php + // is supposed to pass through the actual class loader, wherever it might + // be in the file system. Once we have this class loader object, we can + // use reflection to deduce the location of vendor/. $vendor_dir = $this->appRoot . '/vendor'; $autoload = require $this->appRoot . '/autoload.php'; if ($autoload instanceof \Composer\Autoload\ClassLoader) { diff --git a/core/lib/Drupal/Core/Composer/ProjectRootInterface.php b/core/lib/Drupal/Core/Composer/ProjectRootInterface.php index 0e9ec8b2e6..32dc53cb3f 100644 --- a/core/lib/Drupal/Core/Composer/ProjectRootInterface.php +++ b/core/lib/Drupal/Core/Composer/ProjectRootInterface.php @@ -4,9 +4,6 @@ /** * Provides information about the Composer project root. - * - * @todo Some of this would very well be changed in - * https://www.drupal.org/node/2494073 */ interface ProjectRootInterface { @@ -36,7 +33,7 @@ public function getInstalledPackages(); * will return a combination of the root package and the drupal/core package. * * This method only deals with core's dev requirements, and does not include - * dev requirements for contrib. It's likely that if core and contrib's dev + * dev requirements for contrib. It's likely that core and contrib's dev * requirements are similar. * * @return string[] diff --git a/core/tests/Drupal/KernelTests/Core/Composer/Dependencies/DevDependencyFinderTest.php b/core/tests/Drupal/KernelTests/Core/Composer/Dependencies/DevDependencyFinderTest.php index d1ad5b4a3c..49e67844ad 100644 --- a/core/tests/Drupal/KernelTests/Core/Composer/Dependencies/DevDependencyFinderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Composer/Dependencies/DevDependencyFinderTest.php @@ -16,6 +16,7 @@ * * @todo Make this a UnitTestBase test when the systems it tests no longer have * dependencies on install.inc. + * @see https://www.drupal.org/node/2909480 */ class DevDependencyFinderTest extends KernelTestBase {