From 86314214e900c14da3bf004ffdba981266567804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 10 Jan 2020 18:32:00 +0100 Subject: [PATCH 1/5] A class declared with a bad namespace causes a crash --- tests/Fixtures/Integration/Models/BadNamespaceClass.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/Fixtures/Integration/Models/BadNamespaceClass.php 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 @@ + Date: Sat, 11 Jan 2020 17:00:56 +0100 Subject: [PATCH 2/5] Using new GlobClassExplorer::getClassMap to bypass autoloader when globbing classes --- composer.json | 6 ++++-- src/Mappers/GlobTypeMapper.php | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 0e758543a3..9338b4b3f1 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "psr/container": "^1", "doctrine/annotations": "^1.2", "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", @@ -67,5 +67,7 @@ "branch-alias": { "dev-master": "4.0.x-dev" } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Mappers/GlobTypeMapper.php b/src/Mappers/GlobTypeMapper.php index effede5372..d2d5497ab1 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 => $fileInfo) { + 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 $fileInfo->getRealPath(); + // Does it exists now? + if (! class_exists($className, false) && ! interface_exists($className, false)) { + continue; + } } + $refClass = new ReflectionClass($className); $this->classes[$className] = $refClass; } From 1014c0b0f41d4affbb9e62645d9a6eda6326a389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Jan 2020 09:54:07 +0100 Subject: [PATCH 3/5] Adapting code to new getClassMap signature --- src/Mappers/GlobTypeMapper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mappers/GlobTypeMapper.php b/src/Mappers/GlobTypeMapper.php index d2d5497ab1..f9ee9d2411 100644 --- a/src/Mappers/GlobTypeMapper.php +++ b/src/Mappers/GlobTypeMapper.php @@ -65,13 +65,13 @@ protected function getClassList(): array $this->classes = []; $explorer = new GlobClassExplorer($this->namespace, $this->cache, $this->globTtl, $this->classNameMapper, $this->recursive); $classes = $explorer->getClassMap(); - foreach ($classes as $className => $fileInfo) { + 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 $fileInfo->getRealPath(); + require_once $phpFile; // Does it exists now? if (! class_exists($className, false) && ! interface_exists($className, false)) { continue; From 760a2eaa559d998904de8a9cd3817e80d6d4b82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Jan 2020 10:02:17 +0100 Subject: [PATCH 4/5] Upgrading Doctrine annotations to fix prefer-lowest bug with files with invalid namespaces --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9338b4b3f1..ab4b919a60 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "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.1.0", "psr/simple-cache": "^1", From 01ffe2b9ba4e1f4dd8fa224b81d21775898b834f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 13 Jan 2020 10:11:02 +0100 Subject: [PATCH 5/5] Removing dev minimum stability allowance --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index ab4b919a60..cb21a704c5 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,5 @@ "branch-alias": { "dev-master": "4.0.x-dev" } - }, - "minimum-stability": "dev", - "prefer-stable": true + } }