File tree 3 files changed +21
-5
lines changed
3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 13
13
<argument >%kernel.project_dir%</argument >
14
14
</service >
15
15
16
- <service id =" maker.autoloader_finder" class =" Symfony\Bundle\MakerBundle\Util\ComposerAutoloaderFinder" />
16
+ <service id =" maker.autoloader_finder" class =" Symfony\Bundle\MakerBundle\Util\ComposerAutoloaderFinder" >
17
+ <argument >%maker.root_namespace%</argument >
18
+ </service >
17
19
18
20
<service id =" maker.autoloader_util" class =" Symfony\Bundle\MakerBundle\Util\AutoloaderUtil" >
19
21
<argument type =" service" id =" maker.autoloader_finder" />
Original file line number Diff line number Diff line change 19
19
*/
20
20
class ComposerAutoloaderFinder
21
21
{
22
+ /**
23
+ * @var string
24
+ */
25
+ private $ rootNamespace ;
26
+
22
27
/**
23
28
* @var ClassLoader|null
24
29
*/
25
30
private $ classLoader = null ;
26
31
32
+ public function __construct (string $ rootNamespace = 'App \\' )
33
+ {
34
+ $ this ->rootNamespace = rtrim ($ rootNamespace , '\\' ).'\\' ;
35
+ }
36
+
27
37
public function getClassLoader (): ClassLoader
28
38
{
29
39
if (null === $ this ->classLoader ) {
@@ -46,13 +56,15 @@ private function findComposerClassLoader()
46
56
47
57
foreach ($ autoloadFunctions as $ autoloader ) {
48
58
if (\is_array ($ autoloader ) && isset ($ autoloader [0 ]) && \is_object ($ autoloader [0 ])) {
49
- if ($ autoloader [0 ] instanceof ClassLoader) {
59
+ if ($ autoloader [0 ] instanceof ClassLoader
60
+ && isset ($ autoloader [0 ]->getPrefixesPsr4 ()[$ this ->rootNamespace ])) {
50
61
return $ autoloader [0 ];
51
62
}
52
63
53
64
if ($ autoloader [0 ] instanceof DebugClassLoader
54
65
&& \is_array ($ autoloader [0 ]->getClassLoader ())
55
- && $ autoloader [0 ]->getClassLoader ()[0 ] instanceof ClassLoader) {
66
+ && $ autoloader [0 ]->getClassLoader ()[0 ] instanceof ClassLoader
67
+ && isset ($ autoloader [0 ]->getClassLoader ()[0 ]->getPrefixesPsr4 ()[$ this ->rootNamespace ])) {
56
68
return $ autoloader [0 ]->getClassLoader ()[0 ];
57
69
}
58
70
}
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ class ComposerAutoloaderFinderTest extends TestCase
10
10
{
11
11
public static $ getSplAutoloadFunctions = 'spl_autoload_functions ' ;
12
12
13
+ private static $ rootNamespace = 'Symfony \\Bundle \\MakerBundle \\' ;
14
+
13
15
/**
14
16
* @after
15
17
*/
@@ -20,7 +22,7 @@ public function resetAutoloadFunction()
20
22
21
23
public function testGetClassLoader ()
22
24
{
23
- $ loader = (new ComposerAutoloaderFinder ())->getClassLoader ();
25
+ $ loader = (new ComposerAutoloaderFinder (static :: $ rootNamespace ))->getClassLoader ();
24
26
25
27
$ this ->assertInstanceOf (ClassLoader::class, $ loader , 'Wrong ClassLoader found ' );
26
28
}
@@ -35,7 +37,7 @@ public function testGetClassLoaderWhenItIsEmpty()
35
37
};
36
38
37
39
// throws \Exception
38
- (new ComposerAutoloaderFinder ())->getClassLoader ();
40
+ (new ComposerAutoloaderFinder (static :: $ rootNamespace ))->getClassLoader ();
39
41
}
40
42
}
41
43
You can’t perform that action at this time.
0 commit comments