Skip to content

Commit

Permalink
Move our Symfony class overrides into a location that we dynamically …
Browse files Browse the repository at this point in the history
…load.
  • Loading branch information
greg-1-anderson committed Apr 1, 2022
1 parent dc51857 commit 55c7acf
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ public function loadSiteAutoloader(): ClassLoader
return $this->environment()->loadSiteAutoloader($this->drupalFinder()->getDrupalRoot());
}

public function loadSymfonyCompatabilityAutoloader(): ClassLoader
{
$symfonyMajorVersion = \Symfony\Component\HttpKernel\Kernel::MAJOR_VERSION;
$compatibilityMap = [
3 => false, // Drupal 8
4 => 'v4', // Drupal 9
5 => 'v4', // Early Drupal 10 (Symfony 5 works with Symfony 4 classes, so we don't keep an extra copy)
6 => 'v4', // Drupal 10 (We'll change this to v6 in just a sec)
];

if (empty($compatibilityMap[$symfonyMajorVersion])) {
throw new RuntimeException("Fatal error: Drush does not work with Symfony $symfonyMajorVersion. (In theory, Composer should not allow you to get this far.)");
}

$compatibilityBaseDir = dirname(__DIR__, 2) . '/src-symfony-compatibility';
$compatibilityDir = $compatibilityBaseDir . '/' . $compatibilityMap[$symfonyMajorVersion];

// Next we will make a dynamic autoloader equivalent to an
// entry in the autoload.php file similar to:
//
// "psr-4": {
// "Drush\\": $compatibilityDir
// }
$loader = new \Composer\Autoload\ClassLoader();
// register classes with namespaces
$loader->addPsr4('Drush\\', $compatibilityDir);
// activate the autoloader
$loader->register();

return $loader;
}

public function config(): DrushConfig
{
return $this->configLocator->config();
Expand Down
3 changes: 3 additions & 0 deletions src/Runtime/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ protected function doRun($argv, $output)
// Require the Composer autoloader for Drupal (if different)
$loader = $this->preflight->loadSiteAutoloader();

// Load the Symfony compatability layer autoloader
$this->preflight->loadSymfonyCompatabilityAutoloader();

// Create the Symfony Application et. al.
$input = $this->preflight->createInput();
$application = new Application('Drush Commandline Tool', Drush::getVersion());
Expand Down

0 comments on commit 55c7acf

Please sign in to comment.