From cfa41943ee2dce20947996573fb9223edfe7e23e Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 9 Feb 2022 15:18:22 +0100 Subject: [PATCH 1/6] Use composer/composer to find directive classes https://github.com/BenSampo/laravel-enum/commit/e36641cf52dec61e9838cd76934d822ca183d232 --- src/Schema/DirectiveLocator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Schema/DirectiveLocator.php b/src/Schema/DirectiveLocator.php index 26025192c0..27bba2f4ad 100644 --- a/src/Schema/DirectiveLocator.php +++ b/src/Schema/DirectiveLocator.php @@ -2,6 +2,7 @@ namespace Nuwave\Lighthouse\Schema; +use Composer\Autoload\ClassMapGenerator; use Exception; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\Node; @@ -91,8 +92,7 @@ public function classes(): array $directives = []; foreach ($this->namespaces() as $directiveNamespace) { - /** @var array $classesInNamespace */ - $classesInNamespace = ClassFinder::getClassesInNamespace($directiveNamespace); + $classesInNamespace = ClassMapGenerator::createMap('?', null, $directiveNamespace); foreach ($classesInNamespace as $class) { $reflection = new \ReflectionClass($class); From 088a0c36ae7afde923b32c6c0f6aac6b76e9b5ec Mon Sep 17 00:00:00 2001 From: spawnia Date: Wed, 9 Feb 2022 14:19:21 +0000 Subject: [PATCH 2/6] Apply php-cs-fixer changes --- src/Schema/DirectiveLocator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Schema/DirectiveLocator.php b/src/Schema/DirectiveLocator.php index 27bba2f4ad..8fd1b46e34 100644 --- a/src/Schema/DirectiveLocator.php +++ b/src/Schema/DirectiveLocator.php @@ -6,7 +6,6 @@ use Exception; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\Node; -use HaydenPierce\ClassFinder\ClassFinder; use Illuminate\Contracts\Events\Dispatcher as EventsDispatcher; use Illuminate\Support\Collection; use Illuminate\Support\Str; From 631ff9cb99b63ed10091fa98faa279bcdafdc80b Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Wed, 30 Nov 2022 14:35:01 +0100 Subject: [PATCH 3/6] Update deps, implement with new API --- composer.json | 2 +- src/Schema/DirectiveLocator.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0c5f9525aa..bbe1d6ac5c 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require": { "php": ">= 7.2", "ext-json": "*", - "haydenpierce/class-finder": "^0.4", + "composer/class-map-generator": "^1", "illuminate/auth": "5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8 || ^9", "illuminate/bus": "5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8 || ^9", "illuminate/contracts": "5.6.* || 5.7.* || 5.8.* || ^6 || ^7 || ^8 || ^9", diff --git a/src/Schema/DirectiveLocator.php b/src/Schema/DirectiveLocator.php index 31a7c6d972..06ca92e135 100644 --- a/src/Schema/DirectiveLocator.php +++ b/src/Schema/DirectiveLocator.php @@ -2,7 +2,7 @@ namespace Nuwave\Lighthouse\Schema; -use Composer\Autoload\ClassMapGenerator; +use Composer\ClassMapGenerator\ClassMapGenerator; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\Node; use Illuminate\Contracts\Events\Dispatcher as EventsDispatcher; @@ -91,9 +91,11 @@ public function classes(): array $directives = []; foreach ($this->namespaces() as $directiveNamespace) { - $classesInNamespace = ClassMapGenerator::createMap('?', null, $directiveNamespace); + $generator = new ClassMapGenerator(); + $generator->scanPaths(base_path(), null, 'psr-4', $directiveNamespace); + $classesInNamespace = $generator->getClassMap()->getMap(); - foreach ($classesInNamespace as $class) { + foreach ($classesInNamespace as $class => $_) { $reflection = new \ReflectionClass($class); if (! $reflection->isInstantiable()) { continue; From 8068772ffa4d95fc1cd8c9dac632b6bc9c5c0f0d Mon Sep 17 00:00:00 2001 From: spawnia Date: Wed, 30 Nov 2022 13:36:11 +0000 Subject: [PATCH 4/6] Apply php-cs-fixer changes --- src/Schema/DirectiveLocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/DirectiveLocator.php b/src/Schema/DirectiveLocator.php index 06ca92e135..cb4fa9d196 100644 --- a/src/Schema/DirectiveLocator.php +++ b/src/Schema/DirectiveLocator.php @@ -5,8 +5,8 @@ use Composer\ClassMapGenerator\ClassMapGenerator; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\Node; -use Illuminate\Contracts\Events\Dispatcher as EventsDispatcher; use Illuminate\Container\Container; +use Illuminate\Contracts\Events\Dispatcher as EventsDispatcher; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Nuwave\Lighthouse\Events\RegisterDirectiveNamespaces; From c8e645afe9bbc17a1d6e99f70a7df1ada316ea26 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 1 Dec 2022 12:00:34 +0100 Subject: [PATCH 5/6] simplify --- src/Console/IdeHelperCommand.php | 46 +------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/src/Console/IdeHelperCommand.php b/src/Console/IdeHelperCommand.php index 7f0d8b44b6..8036186dd0 100644 --- a/src/Console/IdeHelperCommand.php +++ b/src/Console/IdeHelperCommand.php @@ -6,14 +6,12 @@ use GraphQL\Language\Parser; use GraphQL\Type\Definition\Type; use GraphQL\Utils\SchemaPrinter; -use HaydenPierce\ClassFinder\ClassFinder; use Illuminate\Console\Command; use Nuwave\Lighthouse\Schema\AST\ASTCache; use Nuwave\Lighthouse\Schema\AST\ASTHelper; use Nuwave\Lighthouse\Schema\DirectiveLocator; use Nuwave\Lighthouse\Schema\SchemaBuilder; use Nuwave\Lighthouse\Schema\Source\SchemaSourceProvider; -use Nuwave\Lighthouse\Support\Contracts\Directive; class IdeHelperCommand extends Command { @@ -56,11 +54,7 @@ public function schemaDirectiveDefinitions(DirectiveLocator $directiveLocator): GRAPHQL; - $directiveClasses = $this->scanForDirectives( - $directiveLocator->namespaces() - ); - - foreach ($directiveClasses as $directiveClass) { + foreach ($directiveLocator->classes() as $directiveClass) { $definition = $this->define($directiveClass); $schema .= /** @lang GraphQL */ <<info("Wrote schema directive definitions to {$filePath}."); } - /** - * Scan the given namespaces for directive classes. - * - * @param array $directiveNamespaces - * - * @return array> - */ - protected function scanForDirectives(array $directiveNamespaces): array - { - $directives = []; - - foreach ($directiveNamespaces as $directiveNamespace) { - /** @var array $classesInNamespace */ - $classesInNamespace = ClassFinder::getClassesInNamespace($directiveNamespace); - - foreach ($classesInNamespace as $class) { - $reflection = new \ReflectionClass($class); - if (! $reflection->isInstantiable()) { - continue; - } - - if (! is_a($class, Directive::class, true)) { - continue; - } - $name = DirectiveLocator::directiveName($class); - - // The directive was already found, so we do not add it twice - if (isset($directives[$name])) { - continue; - } - - $directives[$name] = $class; - } - } - - return $directives; - } - /** * @param class-string<\Nuwave\Lighthouse\Support\Contracts\Directive> $directiveClass * From d5f00569b4755fee09cb8a89eb8cb45071df7588 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 1 Dec 2022 12:00:42 +0100 Subject: [PATCH 6/6] debug --- src/Schema/DirectiveLocator.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Schema/DirectiveLocator.php b/src/Schema/DirectiveLocator.php index cb4fa9d196..82c5bab562 100644 --- a/src/Schema/DirectiveLocator.php +++ b/src/Schema/DirectiveLocator.php @@ -90,10 +90,19 @@ public function classes(): array { $directives = []; + $basePath = base_path(); + dump($basePath); + foreach ($this->namespaces() as $directiveNamespace) { + dump($directiveNamespace); $generator = new ClassMapGenerator(); - $generator->scanPaths(base_path(), null, 'psr-4', $directiveNamespace); + dump('generator'); + // TODO any of those hang indefinitely +// $generator->scanPaths($basePath, null, 'psr-4', ''); + $generator->scanPaths($basePath); + dump('scanPaths'); $classesInNamespace = $generator->getClassMap()->getMap(); + dump($classesInNamespace); foreach ($classesInNamespace as $class => $_) { $reflection = new \ReflectionClass($class);