Skip to content

Commit

Permalink
Merge pull request #217 from moufmouf/errors_on_bad_namespace
Browse files Browse the repository at this point in the history
A class declared with a bad namespace causes a crash
  • Loading branch information
moufmouf authored Jan 13, 2020
2 parents 0526242 + 01ffe2b commit 528ceb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 13 additions & 4 deletions src/Mappers/GlobTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Fixtures/Integration/Models/BadNamespaceClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* This class has a bad namespace. It should not trigger errors when using GlobTypeMapper.
*/
class BadNamespaceClass
{

}

0 comments on commit 528ceb1

Please sign in to comment.