Skip to content

Commit

Permalink
Ensure that the Drupal autoloader has highest priority.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson committed Aug 10, 2017
1 parent ae99863 commit 5836287
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
24 changes: 17 additions & 7 deletions src/Config/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5836287

Please sign in to comment.