diff --git a/src/Config/Environment.php b/src/Config/Environment.php index b8f06e2309..68d201b8da 100644 --- a/src/Config/Environment.php +++ b/src/Config/Environment.php @@ -48,14 +48,24 @@ public function loadSiteAutoloader($root) return false; } - if (!$this->siteLoader) { - $this->siteLoader = require $autloadFilePath; - if ($this->siteLoader === true) { - // The autoloader was already required. Assume that Drush and Drupal share an autoloader per - // "Point autoload.php to the proper vendor directory" - https://www.drupal.org/node/2404989 - $this->siteLoader = $this->loader; - } + if ($this->siteLoader) { + return $this->siteLoader; + } + + $this->siteLoader = require $autloadFilePath; + if ($this->siteLoader === true) { + // The autoloader was already required. Assume that Drush and Drupal share an autoloader per + // "Point autoload.php to the proper vendor directory" - https://www.drupal.org/node/2404989 + $this->siteLoader = $this->loader; } + + // Ensure that the site's autoloader has highest priority. Usually, + // the first classloader registered gets the first shot at loading classes. + // We want Drupal's classloader to be used first when a class is loaded, + // and have Drush's classloader only be called as a fallback measure. + $this->siteLoader->unregister(); + $this->siteLoader->register(true); + return $this->siteLoader; } diff --git a/src/Preflight/Preflight.php b/src/Preflight/Preflight.php index c2762f39af..289f3b06da 100644 --- a/src/Preflight/Preflight.php +++ b/src/Preflight/Preflight.php @@ -189,10 +189,9 @@ protected function doRun($argv) $runner = new \Robo\Runner(); $runner->registerCommandClasses($application, $commandClasses); - // TODO: Consider alternatives for injecting '$root' into the bootstrap manager. - // Also, maybe we should inject the DrupalFinder from this class instead. + // TODO: Consider alternatives for injecting DrupalFinder into the bootstrap manager. $bootstrapManager = $container->get('bootstrap.manager'); - $bootstrapManager->locateRoot($root); + $bootstrapManager->setDrupalFinder($this->drupalFinder); // Run the Symfony Application // Predispatch: call a remote Drush command if applicable (via a 'pre-init' hook)