Skip to content

Commit

Permalink
Make drupal-finder work with multiple autoloaders
Browse files Browse the repository at this point in the history
  • Loading branch information
webflo committed Jun 18, 2024
1 parent 1fa6548 commit 3403675
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/DrupalFinderComposerRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace DrupalFinder;

use Composer\InstalledVersions;
use Composer\Autoload\ClassLoader;

class DrupalFinderComposerRuntime
{
Expand All @@ -16,15 +17,20 @@ class DrupalFinderComposerRuntime
*/
public function getDrupalRoot(): ?string
{
$core = InstalledVersions::getInstallPath('drupal/core');
return $core ? realpath(dirname($core)) : null;
$core = InstalledVersions::getInstallPath('drupal/core');
return $core ? realpath(dirname($core)) : null;
}

/**
* Get the path to the Composer root directory.
*/
public function getComposerRoot(): ?string
{
foreach (InstalledVersions::getAllRawData() as $data) {
if (isset($data['versions']['drupal/core'])) {
return realpath($data['root']['install_path']);
}
}
$root = InstalledVersions::getRootPackage();
return realpath($root['install_path']);
}
Expand All @@ -34,8 +40,11 @@ public function getComposerRoot(): ?string
*/
public function getVendorDir(): ?string
{
$reflection = new \ReflectionClass(InstalledVersions::class);
return realpath(dirname(dirname($reflection->getFileName())));
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
if ($loader->findFile(\Drupal::class)) {
return realpath($vendorDir);
}
}
}

}

0 comments on commit 3403675

Please sign in to comment.