|
6 | 6 |
|
7 | 7 | use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader; |
8 | 8 | use Doctrine\Common\Annotations\AnnotationRegistry; |
9 | | -use Doctrine\Common\Annotations\CachedReader; |
| 9 | +use Doctrine\Common\Annotations\PsrCachedReader; |
10 | 10 | use Doctrine\Common\Annotations\Reader; |
11 | | -use Doctrine\Common\Cache\ApcuCache; |
12 | | -use Doctrine\Common\Cache\PhpFileCache; |
13 | 11 | use GraphQL\Type\SchemaConfig; |
14 | 12 | use Mouf\Composer\ClassNameMapper; |
15 | 13 | use MyCLabs\Enum\Enum; |
16 | 14 | use PackageVersions\Versions; |
| 15 | +use Psr\Cache\CacheItemPoolInterface; |
17 | 16 | use Psr\Container\ContainerInterface; |
18 | 17 | use Psr\SimpleCache\CacheInterface; |
19 | 18 | use Symfony\Component\Cache\Adapter\Psr16Adapter; |
|
52 | 51 | use TheCodingMachine\GraphQLite\Utils\NamespacedCache; |
53 | 52 | use TheCodingMachine\GraphQLite\Utils\Namespaces\NamespaceFactory; |
54 | 53 |
|
55 | | -use function apcu_enabled; |
56 | 54 | use function array_map; |
57 | 55 | use function array_reverse; |
58 | 56 | use function class_exists; |
59 | | -use function crc32; |
60 | | -use function function_exists; |
61 | 57 | use function md5; |
62 | 58 | use function substr; |
63 | | -use function sys_get_temp_dir; |
64 | 59 |
|
65 | 60 | /** |
66 | 61 | * A class to help getting started with GraphQLite. |
@@ -88,8 +83,6 @@ class SchemaFactory |
88 | 83 | private $parameterMiddlewares = []; |
89 | 84 | /** @var Reader */ |
90 | 85 | private $doctrineAnnotationReader; |
91 | | - /** @var string */ |
92 | | - private $annotationCacheDir; |
93 | 86 | /** @var AuthenticationServiceInterface|null */ |
94 | 87 | private $authenticationService; |
95 | 88 | /** @var AuthorizationServiceInterface|null */ |
@@ -207,35 +200,16 @@ public function setDoctrineAnnotationReader(Reader $annotationReader): self |
207 | 200 | return $this; |
208 | 201 | } |
209 | 202 |
|
210 | | - public function setAnnotationCacheDir(string $cacheDir): self |
211 | | - { |
212 | | - $this->annotationCacheDir = $cacheDir; |
213 | | - |
214 | | - return $this; |
215 | | - } |
216 | | - |
217 | 203 | /** |
218 | 204 | * Returns a cached Doctrine annotation reader. |
219 | 205 | * Note: we cannot get the annotation reader service in the container as we are in a compiler pass. |
220 | 206 | */ |
221 | | - private function getDoctrineAnnotationReader(): Reader |
| 207 | + private function getDoctrineAnnotationReader(CacheItemPoolInterface $cache): Reader |
222 | 208 | { |
223 | 209 | if ($this->doctrineAnnotationReader === null) { |
224 | 210 | AnnotationRegistry::registerLoader('class_exists'); |
225 | | - $doctrineAnnotationReader = new DoctrineAnnotationReader(); |
226 | 211 |
|
227 | | - if (function_exists('apcu_enabled') && apcu_enabled()) { |
228 | | - $cache = new ApcuCache(); |
229 | | - } else { |
230 | | - $cacheDir = $this->annotationCacheDir ?? sys_get_temp_dir(); |
231 | | - $cache = new PhpFileCache($cacheDir . '/graphqlite.' . crc32(__DIR__)); |
232 | | - } |
233 | | - |
234 | | - $cache->setNamespace($this->cacheNamespace); |
235 | | - |
236 | | - $doctrineAnnotationReader = new CachedReader($doctrineAnnotationReader, $cache, true); |
237 | | - |
238 | | - return $doctrineAnnotationReader; |
| 212 | + return new PsrCachedReader(new DoctrineAnnotationReader(), $cache, true); |
239 | 213 | } |
240 | 214 |
|
241 | 215 | return $this->doctrineAnnotationReader; |
@@ -331,15 +305,15 @@ public function setExpressionLanguage(ExpressionLanguage $expressionLanguage): s |
331 | 305 |
|
332 | 306 | public function createSchema(): Schema |
333 | 307 | { |
334 | | - $annotationReader = new AnnotationReader($this->getDoctrineAnnotationReader(), AnnotationReader::LAX_MODE); |
| 308 | + $symfonyCache = new Psr16Adapter($this->cache, $this->cacheNamespace); |
| 309 | + $annotationReader = new AnnotationReader($this->getDoctrineAnnotationReader($symfonyCache), AnnotationReader::LAX_MODE); |
335 | 310 | $authenticationService = $this->authenticationService ?: new FailAuthenticationService(); |
336 | 311 | $authorizationService = $this->authorizationService ?: new FailAuthorizationService(); |
337 | 312 | $typeResolver = new TypeResolver(); |
338 | 313 | $namespacedCache = new NamespacedCache($this->cache); |
339 | 314 | $cachedDocBlockFactory = new CachedDocBlockFactory($namespacedCache); |
340 | 315 | $namingStrategy = $this->namingStrategy ?: new NamingStrategy(); |
341 | 316 | $typeRegistry = new TypeRegistry(); |
342 | | - $symfonyCache = new Psr16Adapter($this->cache, $this->cacheNamespace); |
343 | 317 |
|
344 | 318 | $namespaceFactory = new NamespaceFactory($namespacedCache, $this->classNameMapper, $this->globTTL); |
345 | 319 | $nsList = array_map(static function (string $namespace) use ($namespaceFactory) { |
|
0 commit comments