diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9cbdc20..a406edf 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: strategy: matrix: install-args: [''] - php-version: ['8.1'] + php-version: ['8.2'] fail-fast: false steps: # Cancel previous runs of the same branch diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 21a29b1..1991328 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -8,10 +8,7 @@ class Configuration implements ConfigurationInterface { - /** - * @return TreeBuilder - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('graphqlite'); $rootNode = $treeBuilder->getRootNode(); diff --git a/DependencyInjection/GraphQLiteCompilerPass.php b/DependencyInjection/GraphQLiteCompilerPass.php index bee4783..a13be84 100644 --- a/DependencyInjection/GraphQLiteCompilerPass.php +++ b/DependencyInjection/GraphQLiteCompilerPass.php @@ -4,10 +4,12 @@ namespace TheCodingMachine\GraphQLite\Bundle\DependencyInjection; use Doctrine\Common\Annotations\PsrCachedReader; +use Generator; use GraphQL\Server\ServerConfig; use GraphQL\Validator\Rules\DisableIntrospection; use GraphQL\Validator\Rules\QueryComplexity; use GraphQL\Validator\Rules\QueryDepth; +use Kcs\ClassFinder\Finder\ComposerFinder; use ReflectionNamedType; use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\PhpFilesAdapter; @@ -19,7 +21,6 @@ use function class_exists; use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; -use Mouf\Composer\ClassNameMapper; use Psr\SimpleCache\CacheInterface; use ReflectionParameter; use function filter_var; @@ -40,7 +41,6 @@ use TheCodingMachine\CacheUtils\ClassBoundCacheContractInterface; use TheCodingMachine\CacheUtils\ClassBoundMemoryAdapter; use TheCodingMachine\CacheUtils\FileBoundCache; -use TheCodingMachine\ClassExplorer\Glob\GlobClassExplorer; use TheCodingMachine\GraphQLite\AggregateControllerQueryProviderFactory; use TheCodingMachine\GraphQLite\AnnotationReader; use TheCodingMachine\GraphQLite\Annotations\Autowire; @@ -479,34 +479,16 @@ private function getCodeCache(): ClassBoundCacheContractInterface * Returns the array of globbed classes. * Only instantiable classes are returned. * - * @return array> Key: fully qualified class name + * @param string $namespace + * @return Generator, void, void> */ - private function getClassList(string $namespace, int $globTtl = 2, bool $recursive = true): array + private function getClassList(string $namespace): Generator { - $explorer = new GlobClassExplorer($namespace, $this->getPsr16Cache(), $globTtl, ClassNameMapper::createFromComposerFile(null, null, true), $recursive); - $allClasses = $explorer->getClassMap(); - $classes = []; - foreach ($allClasses as $className => $phpFile) { - if (! class_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; - // @phpstan-ignore-next-line Does it exist now? - if (! class_exists($className, false)) { - continue; - } - } - - $refClass = new ReflectionClass($className); - if (! $refClass->isInstantiable()) { - continue; - } - $classes[$className] = $refClass; + $finder = new ComposerFinder(); + foreach ($finder->inNamespace($namespace) as $class) { + assert($class instanceof ReflectionClass); + yield $class->getName() => $class; } - - return $classes; } } diff --git a/DependencyInjection/GraphQLiteExtension.php b/DependencyInjection/GraphQLiteExtension.php index 8fa97ce..a6b4b10 100644 --- a/DependencyInjection/GraphQLiteExtension.php +++ b/DependencyInjection/GraphQLiteExtension.php @@ -43,7 +43,7 @@ public function load(array $configs, ContainerBuilder $container): void } $namespaceController = array_map( function($namespace): string { - return rtrim($namespace, '\\') . '\\'; + return rtrim($namespace, '\\'); }, $controllers ); @@ -57,7 +57,7 @@ function($namespace): string { } $namespaceType = array_map( function($namespace): string { - return rtrim($namespace, '\\') . '\\'; + return rtrim($namespace, '\\'); }, $types ); diff --git a/composer.json b/composer.json index 5e47330..1ec2def 100644 --- a/composer.json +++ b/composer.json @@ -16,32 +16,31 @@ } ], "require" : { - "php" : ">=8.1", + "php" : ">=8.2", "ext-json": "*", - "thecodingmachine/graphqlite" : "^6.0", - "thecodingmachine/graphqlite-symfony-validator-bridge" : "^6.0", - "symfony/framework-bundle": "^6", - "symfony/validator": "^6", - "symfony/translation": "^6", + "thecodingmachine/graphqlite" : "^7.0", + "thecodingmachine/graphqlite-symfony-validator-bridge": "^6.0 || ^7.0", + "symfony/framework-bundle": "^6.0 || ^7.0", + "symfony/validator": "^6.0 || ^7.0", + "symfony/translation": "^6.0 || ^7.0", "doctrine/annotations": "^1.13 || ^2.0.1", - "symfony/psr-http-message-bridge": "^2.0", + "symfony/psr-http-message-bridge": "^6.0 || ^7.0", "nyholm/psr7": "^1.1", - "laminas/laminas-diactoros": "^2.2.2", + "laminas/laminas-diactoros": "^2.2 || ^3.0", "overblog/graphiql-bundle": "^0.2 || ^0.3", "thecodingmachine/cache-utils": "^1", - "symfony/console": "^6" + "symfony/console": "^6.0 || ^7.0" }, "require-dev": { - "symfony/security-bundle": "^6", - "symfony/yaml": "^6", + "symfony/security-bundle": "^6.0 || ^7.0", + "symfony/yaml": "^6.0 || ^7.0", "beberlei/porpaginas": "^1.2 || ^2.0", "php-coveralls/php-coveralls": "^2.1.0", - "symfony/phpunit-bridge": "^6 || ^7", + "symfony/phpunit-bridge": "^6.0 || ^7.0", "phpstan/phpstan": "^1.8", "composer/package-versions-deprecated": "^1.8" }, "conflict": { - "mouf/classname-mapper": "<1.0.2", "symfony/event-dispatcher": "<4.3", "symfony/security-core": "<4.3", "symfony/routing": "<4.3",