@@ -55,24 +55,26 @@ public function __construct(
55
55
56
56
public function create (): SourceLocator
57
57
{
58
+ $ classLoaders = ClassLoader::getRegisteredLoaders ();
58
59
$ classLoaderReflection = new ReflectionClass (ClassLoader::class);
59
- if ($ classLoaderReflection ->getFileName () === false ) {
60
- throw new ShouldNotHappenException ('Unknown ClassLoader filename ' );
60
+ $ locators = [];
61
+ if ($ classLoaderReflection ->hasProperty ('vendorDir ' )) {
62
+ $ vendorDirProperty = $ classLoaderReflection ->getProperty ('vendorDir ' );
63
+ $ vendorDirProperty ->setAccessible (true );
64
+ foreach ($ classLoaders as $ classLoader ) {
65
+ $ composerProjectPath = dirname ($ vendorDirProperty ->getValue ($ classLoader ));
66
+ if (!is_file ($ composerProjectPath . '/composer.json ' )) {
67
+ throw new ShouldNotHappenException (sprintf ('composer.json not found in directory %s ' , $ composerProjectPath ));
68
+ }
69
+
70
+ $ composerSourceLocator = $ this ->composerJsonAndInstalledJsonSourceLocatorMaker ->create ($ composerProjectPath );
71
+ if ($ composerSourceLocator === null ) {
72
+ throw new ShouldNotHappenException ('Could not create composer source locator ' );
73
+ }
74
+ $ locators [] = $ composerSourceLocator ;
75
+ }
61
76
}
62
77
63
- $ composerProjectPath = dirname ($ classLoaderReflection ->getFileName (), 3 );
64
- if (!is_file ($ composerProjectPath . '/composer.json ' )) {
65
- throw new ShouldNotHappenException (sprintf ('composer.json not found in directory %s ' , $ composerProjectPath ));
66
- }
67
-
68
- $ composerSourceLocator = $ this ->composerJsonAndInstalledJsonSourceLocatorMaker ->create ($ composerProjectPath );
69
- if ($ composerSourceLocator === null ) {
70
- throw new ShouldNotHappenException ('Could not create composer source locator ' );
71
- }
72
-
73
- $ locators = [
74
- $ composerSourceLocator ,
75
- ];
76
78
$ astLocator = new Locator ($ this ->phpParser );
77
79
$ astPhp8Locator = new Locator ($ this ->php8Parser );
78
80
0 commit comments