Skip to content

Commit 99122a9

Browse files
committed
Prepare removing Doctrine Cache from remaining components
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 5815a86 commit 99122a9

File tree

6 files changed

+18
-92
lines changed

6 files changed

+18
-92
lines changed

CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
namespace Symfony\Bundle\FrameworkBundle\CacheWarmer;
1313

1414
use Doctrine\Common\Annotations\AnnotationException;
15-
use Doctrine\Common\Annotations\CachedReader;
1615
use Doctrine\Common\Annotations\PsrCachedReader;
1716
use Doctrine\Common\Annotations\Reader;
18-
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
1917
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2018
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
2119

@@ -54,10 +52,7 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
5452
}
5553

5654
$annotatedClasses = include $annotatedClassPatterns;
57-
$reader = class_exists(PsrCachedReader::class)
58-
? new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug)
59-
: new CachedReader($this->annotationReader, DoctrineProvider::wrap($arrayAdapter), $this->debug)
60-
;
55+
$reader = new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug);
6156

6257
foreach ($annotatedClasses as $class) {
6358
if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) {

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,23 +1559,12 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
15591559

15601560
if ('none' === $config['cache']) {
15611561
$container->removeDefinition('annotations.cached_reader');
1562-
$container->removeDefinition('annotations.psr_cached_reader');
15631562

15641563
return;
15651564
}
15661565

15671566
$cacheService = $config['cache'];
15681567
if (\in_array($config['cache'], ['php_array', 'file'])) {
1569-
$isPsr6Service = $container->hasDefinition('annotations.psr_cached_reader');
1570-
} else {
1571-
$isPsr6Service = false;
1572-
trigger_deprecation('symfony/framework-bundle', '5.3', 'Using a custom service for "framework.annotation.cache" is deprecated, only values "none", "php_array" and "file" are valid in version 6.0.');
1573-
}
1574-
1575-
if ($isPsr6Service) {
1576-
$container->removeDefinition('annotations.cached_reader');
1577-
$container->setDefinition('annotations.cached_reader', $container->getDefinition('annotations.psr_cached_reader'));
1578-
15791568
if ('php_array' === $config['cache']) {
15801569
$cacheService = 'annotations.cache_adapter';
15811570

@@ -1596,31 +1585,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
15961585
;
15971586
}
15981587
} else {
1599-
// Legacy code for doctrine/annotations:<1.13
1600-
if (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
1601-
throw new LogicException('Annotations cannot be cached as the Doctrine Cache library is not installed. Try running "composer require doctrine/cache".');
1602-
}
1603-
1604-
if ('php_array' === $config['cache']) {
1605-
$cacheService = 'annotations.cache';
1606-
1607-
// Enable warmer only if PHP array is used for cache
1608-
$definition = $container->findDefinition('annotations.cache_warmer');
1609-
$definition->addTag('kernel.cache_warmer');
1610-
} elseif ('file' === $config['cache']) {
1611-
$cacheDir = $container->getParameterBag()->resolveValue($config['file_cache_dir']);
1612-
1613-
if (!is_dir($cacheDir) && false === @mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
1614-
throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
1615-
}
1616-
1617-
$container
1618-
->getDefinition('annotations.filesystem_cache_adapter')
1619-
->replaceArgument(2, $cacheDir)
1620-
;
1621-
1622-
$cacheService = 'annotations.filesystem_cache';
1623-
}
1588+
trigger_deprecation('symfony/framework-bundle', '5.3', 'Using a custom service for "framework.annotation.cache" is deprecated, only values "none", "php_array" and "file" are valid in version 6.0.');
16241589
}
16251590

16261591
$container

Resources/config/annotations.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\AnnotationRegistry;
16-
use Doctrine\Common\Annotations\CachedReader;
1716
use Doctrine\Common\Annotations\PsrCachedReader;
1817
use Doctrine\Common\Annotations\Reader;
1918
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
@@ -33,14 +32,10 @@
3332
->set('annotations.dummy_registry', AnnotationRegistry::class)
3433
->call('registerUniqueLoader', ['class_exists'])
3534

36-
->set('annotations.cached_reader', CachedReader::class)
35+
->set('annotations.cached_reader', PsrCachedReader::class)
3736
->args([
3837
service('annotations.reader'),
39-
inline_service(DoctrineProvider::class)
40-
->factory([DoctrineProvider::class, 'wrap'])
41-
->args([
42-
inline_service(ArrayAdapter::class),
43-
]),
38+
inline_service(ArrayAdapter::class),
4439
abstract_arg('Debug-Flag'),
4540
])
4641

@@ -56,6 +51,7 @@
5651
->args([
5752
service('annotations.filesystem_cache_adapter'),
5853
])
54+
->deprecate('symfony/framework-bundle', '5.4', '"%service_id% is deprecated"')
5955

6056
->set('annotations.cache_warmer', AnnotationsCacheWarmer::class)
6157
->args([
@@ -78,19 +74,8 @@
7874
->args([
7975
service('annotations.cache_adapter'),
8076
])
81-
->tag('container.hot_path')
77+
->deprecate('symfony/framework-bundle', '5.4', '"%service_id% is deprecated"')
8278

8379
->alias('annotation_reader', 'annotations.reader')
8480
->alias(Reader::class, 'annotation_reader');
85-
86-
if (class_exists(PsrCachedReader::class)) {
87-
$container->services()
88-
->set('annotations.psr_cached_reader', PsrCachedReader::class)
89-
->args([
90-
service('annotations.reader'),
91-
inline_service(ArrayAdapter::class),
92-
abstract_arg('Debug-Flag'),
93-
])
94-
;
95-
}
9681
};

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
44

55
use Doctrine\Common\Annotations\AnnotationReader;
6-
use Doctrine\Common\Annotations\CachedReader;
76
use Doctrine\Common\Annotations\PsrCachedReader;
87
use Doctrine\Common\Annotations\Reader;
9-
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
108
use PHPUnit\Framework\MockObject\MockObject;
119
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
1210
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@@ -44,16 +42,10 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
4442
$this->assertFileExists($cacheFile);
4543

4644
// Assert cache is valid
47-
$reader = class_exists(PsrCachedReader::class)
48-
? new PsrCachedReader(
49-
$this->getReadOnlyReader(),
50-
new PhpArrayAdapter($cacheFile, new NullAdapter())
51-
)
52-
: new CachedReader(
53-
$this->getReadOnlyReader(),
54-
DoctrineProvider::wrap(new PhpArrayAdapter($cacheFile, new NullAdapter()))
55-
)
56-
;
45+
$reader = new PsrCachedReader(
46+
$this->getReadOnlyReader(),
47+
new PhpArrayAdapter($cacheFile, new NullAdapter())
48+
);
5749
$refClass = new \ReflectionClass($this);
5850
$reader->getClassAnnotations($refClass);
5951
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));
@@ -71,18 +63,11 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
7163

7264
// Assert cache is valid
7365
$phpArrayAdapter = new PhpArrayAdapter($cacheFile, new NullAdapter());
74-
$reader = class_exists(PsrCachedReader::class)
75-
? new PsrCachedReader(
76-
$this->getReadOnlyReader(),
77-
$phpArrayAdapter,
78-
true
79-
)
80-
: new CachedReader(
81-
$this->getReadOnlyReader(),
82-
DoctrineProvider::wrap($phpArrayAdapter),
83-
true
84-
)
85-
;
66+
$reader = new PsrCachedReader(
67+
$this->getReadOnlyReader(),
68+
$phpArrayAdapter,
69+
true
70+
);
8671
$refClass = new \ReflectionClass($this);
8772
$reader->getClassAnnotations($refClass);
8873
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));

Tests/Functional/AutowiringTypesTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
15-
use Doctrine\Common\Annotations\CachedReader;
1615
use Doctrine\Common\Annotations\PsrCachedReader;
1716
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1817
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -34,11 +33,7 @@ public function testCachedAnnotationReaderAutowiring()
3433
static::bootKernel();
3534

3635
$annotationReader = self::getContainer()->get('test.autowiring_types.autowired_services')->getAnnotationReader();
37-
if (class_exists(PsrCachedReader::class)) {
38-
$this->assertInstanceOf(PsrCachedReader::class, $annotationReader);
39-
} else {
40-
$this->assertInstanceOf(CachedReader::class, $annotationReader);
41-
}
36+
$this->assertInstanceOf(PsrCachedReader::class, $annotationReader);
4237
}
4338

4439
public function testEventDispatcherAutowiring()

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"symfony/routing": "^5.3|^6.0"
3434
},
3535
"require-dev": {
36-
"doctrine/annotations": "^1.10.4",
36+
"doctrine/annotations": "^1.13.1",
3737
"doctrine/cache": "^1.11|^2.0",
3838
"doctrine/persistence": "^1.3|^2.0",
3939
"symfony/asset": "^5.3|^6.0",
@@ -70,6 +70,7 @@
7070
"symfony/phpunit-bridge": "^5.3|^6.0"
7171
},
7272
"conflict": {
73+
"doctrine/annotations": "<1.13.1",
7374
"doctrine/cache": "<1.11",
7475
"doctrine/persistence": "<1.3",
7576
"phpdocumentor/reflection-docblock": "<3.2.2",

0 commit comments

Comments
 (0)