Skip to content

Commit f2b7c03

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: Fix deprecations from Doctrine Annotations+Cache
2 parents af65296 + 0e9b5ce commit f2b7c03

File tree

8 files changed

+64
-24
lines changed

8 files changed

+64
-24
lines changed

CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationException;
1515
use Doctrine\Common\Annotations\CachedReader;
16+
use Doctrine\Common\Annotations\PsrCachedReader;
1617
use Doctrine\Common\Annotations\Reader;
1718
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1819
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
@@ -53,7 +54,10 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter)
5354
}
5455

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

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

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ class UnusedTagsPass implements CompilerPassInterface
7272
'routing.expression_language_provider',
7373
'routing.loader',
7474
'routing.route_loader',
75+
'security.authenticator.login_linker',
7576
'security.expression_language_provider',
7677
'security.remember_me_aware',
77-
'security.authenticator.login_linker',
7878
'security.voter',
7979
'serializer.encoder',
8080
'serializer.normalizer',
@@ -88,6 +88,7 @@ class UnusedTagsPass implements CompilerPassInterface
8888
'validator.auto_mapper',
8989
'validator.constraint_validator',
9090
'validator.initializer',
91+
'workflow.definition',
9192
];
9293

9394
public function process(ContainerBuilder $container)

DependencyInjection/FrameworkExtension.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\AnnotationRegistry;
15+
use Doctrine\Common\Annotations\PsrCachedReader;
1516
use Doctrine\Common\Annotations\Reader;
1617
use Http\Client\HttpClient;
1718
use Psr\Cache\CacheItemPoolInterface;
@@ -1426,14 +1427,20 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14261427
}
14271428

14281429
if ('none' !== $config['cache']) {
1429-
if (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
1430+
if (class_exists(PsrCachedReader::class)) {
1431+
$container
1432+
->getDefinition('annotations.cached_reader')
1433+
->setClass(PsrCachedReader::class)
1434+
->replaceArgument(1, new Definition(ArrayAdapter::class))
1435+
;
1436+
} elseif (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
14301437
throw new LogicException('Annotations cannot be enabled as the Doctrine Cache library is not installed.');
14311438
}
14321439

14331440
$cacheService = $config['cache'];
14341441

14351442
if ('php_array' === $config['cache']) {
1436-
$cacheService = 'annotations.cache';
1443+
$cacheService = class_exists(PsrCachedReader::class) ? 'annotations.cache_adapter' : 'annotations.cache';
14371444

14381445
// Enable warmer only if PHP array is used for cache
14391446
$definition = $container->findDefinition('annotations.cache_warmer');
@@ -1450,7 +1457,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14501457
->replaceArgument(2, $cacheDir)
14511458
;
14521459

1453-
$cacheService = 'annotations.filesystem_cache';
1460+
$cacheService = class_exists(PsrCachedReader::class) ? 'annotations.filesystem_cache_adapter' : 'annotations.filesystem_cache';
14541461
}
14551462

14561463
$container

Resources/config/annotations.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@
6161
param('kernel.debug'),
6262
])
6363

64+
->set('annotations.cache_adapter', PhpArrayAdapter::class)
65+
->factory([PhpArrayAdapter::class, 'create'])
66+
->args([
67+
param('kernel.cache_dir').'/annotations.php',
68+
service('cache.annotations'),
69+
])
70+
6471
->set('annotations.cache', DoctrineProvider::class)
6572
->args([
66-
inline_service(PhpArrayAdapter::class)
67-
->factory([PhpArrayAdapter::class, 'create'])
68-
->args([
69-
param('kernel.cache_dir').'/annotations.php',
70-
service('cache.annotations'),
71-
]),
73+
service('annotations.cache_adapter')
7274
])
7375
->tag('container.hot_path')
7476

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\Common\Annotations\AnnotationReader;
66
use Doctrine\Common\Annotations\CachedReader;
7+
use Doctrine\Common\Annotations\PsrCachedReader;
78
use Doctrine\Common\Annotations\Reader;
89
use PHPUnit\Framework\MockObject\MockObject;
910
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
@@ -43,10 +44,16 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
4344
$this->assertFileExists($cacheFile);
4445

4546
// Assert cache is valid
46-
$reader = new CachedReader(
47-
$this->getReadOnlyReader(),
48-
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter()))
49-
);
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+
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter()))
55+
)
56+
;
5057
$refClass = new \ReflectionClass($this);
5158
$reader->getClassAnnotations($refClass);
5259
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));
@@ -61,12 +68,21 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
6168
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);
6269
$warmer->warmUp($this->cacheDir);
6370
$this->assertFileExists($cacheFile);
71+
6472
// Assert cache is valid
65-
$reader = new CachedReader(
66-
$this->getReadOnlyReader(),
67-
new DoctrineProvider(new PhpArrayAdapter($cacheFile, new NullAdapter())),
68-
true
69-
);
73+
$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+
new DoctrineProvider($phpArrayAdapter),
83+
true
84+
)
85+
;
7086
$refClass = new \ReflectionClass($this);
7187
$reader->getClassAnnotations($refClass);
7288
$reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__));

Tests/DependencyInjection/FrameworkExtensionTest.php

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

1414
use Doctrine\Common\Annotations\Annotation;
15+
use Doctrine\Common\Annotations\PsrCachedReader;
1516
use Psr\Cache\CacheItemPoolInterface;
1617
use Psr\Log\LoggerAwareInterface;
1718
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
@@ -930,7 +931,11 @@ public function testAnnotations()
930931
$container->compile();
931932

932933
$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache_adapter')->getArgument(2));
933-
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1));
934+
if (class_exists(PsrCachedReader::class)) {
935+
$this->assertSame('annotations.filesystem_cache_adapter', (string) $container->getDefinition('annotation_reader')->getArgument(1));
936+
} else {
937+
$this->assertSame('annotations.filesystem_cache', (string) $container->getDefinition('annotation_reader')->getArgument(1));
938+
}
934939
}
935940

936941
public function testFileLinkFormat()

Tests/Functional/AutowiringTypesTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\CachedReader;
16+
use Doctrine\Common\Annotations\PsrCachedReader;
1617
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1718
use Symfony\Component\EventDispatcher\EventDispatcher;
1819
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
@@ -33,7 +34,11 @@ public function testCachedAnnotationReaderAutowiring()
3334
static::bootKernel();
3435

3536
$annotationReader = static::$container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
36-
$this->assertInstanceOf(CachedReader::class, $annotationReader);
37+
if (class_exists(PsrCachedReader::class)) {
38+
$this->assertInstanceOf(PsrCachedReader::class, $annotationReader);
39+
} else {
40+
$this->assertInstanceOf(CachedReader::class, $annotationReader);
41+
}
3742
}
3843

3944
public function testEventDispatcherAutowiring()

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=7.2.5",
2020
"ext-xml": "*",
2121
"symfony/cache": "^5.2",
22-
"symfony/config": "^5.0",
22+
"symfony/config": "~5.0.11|^5.1.3",
2323
"symfony/dependency-injection": "^5.2",
2424
"symfony/deprecation-contracts": "^2.1",
2525
"symfony/event-dispatcher": "^5.1",
@@ -34,7 +34,7 @@
3434
},
3535
"require-dev": {
3636
"doctrine/annotations": "^1.10.4",
37-
"doctrine/cache": "~1.0",
37+
"doctrine/cache": "^1.0|^2.0",
3838
"doctrine/persistence": "^1.3|^2.0",
3939
"symfony/asset": "^5.1",
4040
"symfony/browser-kit": "^4.4|^5.0",

0 commit comments

Comments
 (0)