diff --git a/composer.json b/composer.json index 0e758543a3..cb21a704c5 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "php": ">=7.2", "webonyx/graphql-php": "^0.13.4", "psr/container": "^1", - "doctrine/annotations": "^1.2", + "doctrine/annotations": "^1.7.0", "doctrine/cache": "^1.8", - "thecodingmachine/class-explorer": "^1.0.2", + "thecodingmachine/class-explorer": "^1.1.0", "psr/simple-cache": "^1", "phpdocumentor/reflection-docblock": "^4.3", "phpdocumentor/type-resolver": "^1.0.1", diff --git a/src/Mappers/GlobTypeMapper.php b/src/Mappers/GlobTypeMapper.php index effede5372..f9ee9d2411 100644 --- a/src/Mappers/GlobTypeMapper.php +++ b/src/Mappers/GlobTypeMapper.php @@ -64,11 +64,20 @@ protected function getClassList(): array if ($this->classes === null) { $this->classes = []; $explorer = new GlobClassExplorer($this->namespace, $this->cache, $this->globTtl, $this->classNameMapper, $this->recursive); - $classes = $explorer->getClasses(); - foreach ($classes as $className) { - if (! class_exists($className) && ! interface_exists($className)) { - continue; + $classes = $explorer->getClassMap(); + foreach ($classes as $className => $phpFile) { + if (! class_exists($className, false) && ! interface_exists($className, false)) { + // Let's try to load the file if it was not imported yet. + // We are importing the file manually to avoid triggering the autoloader. + // The autoloader might trigger errors if the file does not respect PSR-4 or if the + // Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216) + require_once $phpFile; + // Does it exists now? + if (! class_exists($className, false) && ! interface_exists($className, false)) { + continue; + } } + $refClass = new ReflectionClass($className); $this->classes[$className] = $refClass; } diff --git a/tests/Fixtures/Integration/Models/BadNamespaceClass.php b/tests/Fixtures/Integration/Models/BadNamespaceClass.php new file mode 100644 index 0000000000..6ff471a75b --- /dev/null +++ b/tests/Fixtures/Integration/Models/BadNamespaceClass.php @@ -0,0 +1,9 @@ +