|
18 | 18 | use ReflectionParameter;
|
19 | 19 | use Symfony\Component\Cache\Simple\ApcuCache as SymfonyApcuCache;
|
20 | 20 | use Symfony\Component\Cache\Simple\PhpFilesCache as SymfonyPhpFilesCache;
|
| 21 | +use function filter_var; |
21 | 22 | use function function_exists;
|
22 | 23 | use GraphQL\Type\Definition\InputObjectType;
|
23 | 24 | use GraphQL\Type\Definition\ObjectType;
|
24 | 25 | use Psr\Container\ContainerInterface;
|
25 | 26 | use ReflectionClass;
|
26 | 27 | use ReflectionMethod;
|
| 28 | +use function ini_get; |
| 29 | +use function interface_exists; |
| 30 | +use function php_sapi_name; |
27 | 31 | use function str_replace;
|
28 | 32 | use function strpos;
|
29 | 33 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
@@ -252,7 +256,7 @@ public function process(ContainerBuilder $container)
|
252 | 256 | $this->mapAdderToTag('graphql.type_mapper_factory', 'addTypeMapperFactory', $container, $schemaFactory);
|
253 | 257 |
|
254 | 258 | // Configure cache
|
255 |
| - if (ApcuAdapter::isSupported()) { |
| 259 | + if (ApcuAdapter::isSupported() && (PHP_SAPI !== 'cli' || filter_var(ini_get('apc.enabled_cli')))) { |
256 | 260 | $container->setAlias('graphqlite.cache', 'graphqlite.apcucache');
|
257 | 261 | } else {
|
258 | 262 | $container->setAlias('graphqlite.cache', 'graphqlite.phpfilescache');
|
@@ -421,12 +425,21 @@ private function getCodeCache(): ClassBoundCacheContractInterface
|
421 | 425 | private function getClassList(string $namespace, int $globTtl = 2, bool $recursive = true): array
|
422 | 426 | {
|
423 | 427 | $explorer = new GlobClassExplorer($namespace, $this->getPsr16Cache(), $globTtl, ClassNameMapper::createFromComposerFile(null, null, true), $recursive);
|
424 |
| - $allClasses = $explorer->getClasses(); |
| 428 | + $allClasses = $explorer->getClassMap(); |
425 | 429 | $classes = [];
|
426 |
| - foreach ($allClasses as $className) { |
427 |
| - if (! class_exists($className)) { |
428 |
| - continue; |
| 430 | + foreach ($allClasses as $className => $phpFile) { |
| 431 | + if (! class_exists($className, false)) { |
| 432 | + // Let's try to load the file if it was not imported yet. |
| 433 | + // We are importing the file manually to avoid triggering the autoloader. |
| 434 | + // The autoloader might trigger errors if the file does not respect PSR-4 or if the |
| 435 | + // Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216) |
| 436 | + require_once $phpFile; |
| 437 | + // Does it exists now? |
| 438 | + if (! class_exists($className, false)) { |
| 439 | + continue; |
| 440 | + } |
429 | 441 | }
|
| 442 | + |
430 | 443 | $refClass = new ReflectionClass($className);
|
431 | 444 | if (! $refClass->isInstantiable()) {
|
432 | 445 | continue;
|
|
0 commit comments