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/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 * diff --git a/src/Schema/DirectiveLocator.php b/src/Schema/DirectiveLocator.php index c3cd01c21e..82c5bab562 100644 --- a/src/Schema/DirectiveLocator.php +++ b/src/Schema/DirectiveLocator.php @@ -2,9 +2,9 @@ namespace Nuwave\Lighthouse\Schema; +use Composer\ClassMapGenerator\ClassMapGenerator; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\Node; -use HaydenPierce\ClassFinder\ClassFinder; use Illuminate\Container\Container; use Illuminate\Contracts\Events\Dispatcher as EventsDispatcher; use Illuminate\Support\Collection; @@ -90,11 +90,21 @@ public function classes(): array { $directives = []; - foreach ($this->namespaces() as $directiveNamespace) { - /** @var array $classesInNamespace */ - $classesInNamespace = ClassFinder::getClassesInNamespace($directiveNamespace); + $basePath = base_path(); + dump($basePath); - foreach ($classesInNamespace as $class) { + foreach ($this->namespaces() as $directiveNamespace) { + dump($directiveNamespace); + $generator = new ClassMapGenerator(); + 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); if (! $reflection->isInstantiable()) { continue;