Skip to content

Commit afe2875

Browse files
committed
Using new GlobClassExplorer::getClassMap to bypass autoloader when globbing classes
1 parent 8631421 commit afe2875

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"psr/container": "^1",
1616
"doctrine/annotations": "^1.2",
1717
"doctrine/cache": "^1.8",
18-
"thecodingmachine/class-explorer": "^1.0.2",
18+
"thecodingmachine/class-explorer": "^1.1.0",
1919
"psr/simple-cache": "^1",
2020
"phpdocumentor/reflection-docblock": "^4.3",
2121
"phpdocumentor/type-resolver": "^1.0.1",
@@ -67,5 +67,7 @@
6767
"branch-alias": {
6868
"dev-master": "4.0.x-dev"
6969
}
70-
}
70+
},
71+
"minimum-stability": "dev",
72+
"prefer-stable": true
7173
}

src/Mappers/GlobTypeMapper.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ protected function getClassList(): array
6464
if ($this->classes === null) {
6565
$this->classes = [];
6666
$explorer = new GlobClassExplorer($this->namespace, $this->cache, $this->globTtl, $this->classNameMapper, $this->recursive);
67-
$classes = $explorer->getClasses();
68-
foreach ($classes as $className) {
69-
if (! class_exists($className) && ! interface_exists($className)) {
70-
continue;
67+
$classes = $explorer->getClassMap();
68+
foreach ($classes as $className => $fileInfo) {
69+
if (! class_exists($className, false) && ! interface_exists($className, false)) {
70+
// Let's try to load the file if it was not imported yet.
71+
// We are importing the file manually to avoid triggering the autoloader.
72+
// The autoloader might trigger errors if the file does not respect PSR-4 or if the
73+
// Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216)
74+
require_once $fileInfo->getRealPath();
75+
// Does it exists now?
76+
if (! class_exists($className, false) && ! interface_exists($className, false)) {
77+
continue;
78+
}
7179
}
80+
7281
$refClass = new ReflectionClass($className);
7382
$this->classes[$className] = $refClass;
7483
}

0 commit comments

Comments
 (0)