Skip to content

Commit d494448

Browse files
authored
Drop doctrine/cache dependency (#373)
* Drop doctrine/cache dependency * Bump doctrine annotation * Drop unused imports * Drop annotation dir
1 parent 3753cc5 commit d494448

File tree

5 files changed

+7
-94
lines changed

5 files changed

+7
-94
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"require": {
1313
"php": ">=7.2",
1414
"ext-json": "*",
15-
"doctrine/annotations": "^1.10.4",
16-
"doctrine/cache": "^1.8",
15+
"doctrine/annotations": "^1.13",
1716
"composer/package-versions-deprecated": "^1.8",
1817
"phpdocumentor/reflection-docblock": "^4.3 || ^5.0",
1918
"phpdocumentor/type-resolver": "^1.4",

docs/other_frameworks.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ $factory->prodMode();
7979
// Enables dev-mode (this is the default mode: cache settings optimized for best developer experience).
8080
// This is a shortcut for `$schemaFactory->setGlobTtl(2)`
8181
$factory->devMode();
82-
// If APCu is not available, Doctrine annotations are stored in files.
83-
// This setter can configure the cache directory for Doctrine annotations.
84-
$factory->setAnnotationCacheDir($directory);
8582
```
8683

8784
### GraphQLite context

src/SchemaFactory.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
use Doctrine\Common\Annotations\AnnotationReader as DoctrineAnnotationReader;
88
use Doctrine\Common\Annotations\AnnotationRegistry;
9-
use Doctrine\Common\Annotations\CachedReader;
9+
use Doctrine\Common\Annotations\PsrCachedReader;
1010
use Doctrine\Common\Annotations\Reader;
11-
use Doctrine\Common\Cache\ApcuCache;
12-
use Doctrine\Common\Cache\PhpFileCache;
1311
use GraphQL\Type\SchemaConfig;
1412
use Mouf\Composer\ClassNameMapper;
1513
use MyCLabs\Enum\Enum;
1614
use PackageVersions\Versions;
15+
use Psr\Cache\CacheItemPoolInterface;
1716
use Psr\Container\ContainerInterface;
1817
use Psr\SimpleCache\CacheInterface;
1918
use Symfony\Component\Cache\Adapter\Psr16Adapter;
@@ -52,15 +51,11 @@
5251
use TheCodingMachine\GraphQLite\Utils\NamespacedCache;
5352
use TheCodingMachine\GraphQLite\Utils\Namespaces\NamespaceFactory;
5453

55-
use function apcu_enabled;
5654
use function array_map;
5755
use function array_reverse;
5856
use function class_exists;
59-
use function crc32;
60-
use function function_exists;
6157
use function md5;
6258
use function substr;
63-
use function sys_get_temp_dir;
6459

6560
/**
6661
* A class to help getting started with GraphQLite.
@@ -88,8 +83,6 @@ class SchemaFactory
8883
private $parameterMiddlewares = [];
8984
/** @var Reader */
9085
private $doctrineAnnotationReader;
91-
/** @var string */
92-
private $annotationCacheDir;
9386
/** @var AuthenticationServiceInterface|null */
9487
private $authenticationService;
9588
/** @var AuthorizationServiceInterface|null */
@@ -207,35 +200,16 @@ public function setDoctrineAnnotationReader(Reader $annotationReader): self
207200
return $this;
208201
}
209202

210-
public function setAnnotationCacheDir(string $cacheDir): self
211-
{
212-
$this->annotationCacheDir = $cacheDir;
213-
214-
return $this;
215-
}
216-
217203
/**
218204
* Returns a cached Doctrine annotation reader.
219205
* Note: we cannot get the annotation reader service in the container as we are in a compiler pass.
220206
*/
221-
private function getDoctrineAnnotationReader(): Reader
207+
private function getDoctrineAnnotationReader(CacheItemPoolInterface $cache): Reader
222208
{
223209
if ($this->doctrineAnnotationReader === null) {
224210
AnnotationRegistry::registerLoader('class_exists');
225-
$doctrineAnnotationReader = new DoctrineAnnotationReader();
226211

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);
239213
}
240214

241215
return $this->doctrineAnnotationReader;
@@ -331,15 +305,15 @@ public function setExpressionLanguage(ExpressionLanguage $expressionLanguage): s
331305

332306
public function createSchema(): Schema
333307
{
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);
335310
$authenticationService = $this->authenticationService ?: new FailAuthenticationService();
336311
$authorizationService = $this->authorizationService ?: new FailAuthorizationService();
337312
$typeResolver = new TypeResolver();
338313
$namespacedCache = new NamespacedCache($this->cache);
339314
$cachedDocBlockFactory = new CachedDocBlockFactory($namespacedCache);
340315
$namingStrategy = $this->namingStrategy ?: new NamingStrategy();
341316
$typeRegistry = new TypeRegistry();
342-
$symfonyCache = new Psr16Adapter($this->cache, $this->cacheNamespace);
343317

344318
$namespaceFactory = new NamespaceFactory($namespacedCache, $this->classNameMapper, $this->globTTL);
345319
$nsList = array_map(static function (string $namespace) use ($namespaceFactory) {

tests/Utils/PSR16DoctrineCacheAdapter.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

website/versioned_docs/version-4.1/other_frameworks.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ $factory->prodMode();
8080
// Enables dev-mode (this is the default mode: cache settings optimized for best developer experience).
8181
// This is a shortcut for `$schemaFactory->setGlobTtl(2)`
8282
$factory->devMode();
83-
// If APCu is not available, Doctrine annotations are stored in files.
84-
// This setter can configure the cache directory for Doctrine annotations.
85-
$factory->setAnnotationCacheDir($directory);
8683
```
8784

8885
### GraphQLite context

0 commit comments

Comments
 (0)