Skip to content

Commit 02147d3

Browse files
feature #50888 [FrameworkBundle] Deprecate doctrine/annotations integration (derrabus)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] Deprecate doctrine/annotations integration | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | N/A | License | MIT | Doc PR | TODO This PR deprecates the integration of the doctrine/annotations package in FrameworkBundle. Currently, the integration is enabled by default if `doctrine/annotations` is installed. This PR adds a runtime deprecation if the app does not explicitly disable it by setting: ```php framework: annotations: false ``` The plan is to make this the default and only valid option in Symfony 7 and remove that setting entirely in Symfony 8. This change unlocks #49358 and similar PRs that remove support for Doctrine Annotations from components. Commits ------- 2b3c954 [FrameworkBundle] Deprecate doctrine/annotations integration
2 parents 49c048f + 2b3c954 commit 02147d3

File tree

328 files changed

+527
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+527
-65
lines changed

UPGRADE-6.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ FrameworkBundle
3434
---------------
3535

3636
* Add native return type to `Translator` and to `Application::reset()`
37+
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable
38+
the integration by setting `framework.annotations` to `false`
3739

3840
HttpFoundation
3941
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add native return type to `Translator` and to `Application::reset()`
8+
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
89

910
6.3
1011
---

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@
2222
* and declared in DI bundle extensions using the addAnnotatedClassesToCache method.
2323
*
2424
* @author Titouan Galopin <galopintitouan@gmail.com>
25+
*
26+
* @deprecated since Symfony 6.4 without replacement
2527
*/
2628
class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
2729
{
28-
private Reader $annotationReader;
29-
private ?string $excludeRegexp;
30-
private bool $debug;
31-
3230
/**
3331
* @param string $phpArrayFile The PHP file where annotations are cached
3432
*/
35-
public function __construct(Reader $annotationReader, string $phpArrayFile, string $excludeRegexp = null, bool $debug = false)
36-
{
33+
public function __construct(
34+
private readonly Reader $annotationReader,
35+
string $phpArrayFile,
36+
private readonly ?string $excludeRegexp = null,
37+
private readonly bool $debug = false,
38+
/* bool $triggerDeprecation = true, */
39+
) {
40+
if (\func_num_args() < 5 || func_get_arg(4)) {
41+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated without replacement.', __CLASS__);
42+
}
43+
3744
parent::__construct($phpArrayFile);
38-
$this->annotationReader = $annotationReader;
39-
$this->excludeRegexp = $excludeRegexp;
40-
$this->debug = $debug;
4145
}
4246

4347
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
17161716
throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed. Try running "composer require doctrine/annotations".');
17171717
}
17181718

1719+
trigger_deprecation('symfony/framework-bundle', '6.4', 'Enabling the integration of Doctrine annotations is deprecated. Set the "framework.annotations.enabled" config option to false.');
1720+
17191721
$loader->load('annotations.php');
17201722

17211723
if ('none' === $config['cache']) {

src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
$container->services()
2424
->set('annotations.reader', AnnotationReader::class)
2525
->call('addGlobalIgnoredName', ['required']) // @deprecated since Symfony 6.3
26+
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')
2627

2728
->set('annotations.cached_reader', PsrCachedReader::class)
2829
->args([
@@ -32,21 +33,25 @@
3233
])
3334
->tag('annotations.cached_reader')
3435
->tag('container.do_not_inline')
36+
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')
3537

3638
->set('annotations.filesystem_cache_adapter', FilesystemAdapter::class)
3739
->args([
3840
'',
3941
0,
4042
abstract_arg('Cache-Directory'),
4143
])
44+
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')
4245

4346
->set('annotations.cache_warmer', AnnotationsCacheWarmer::class)
4447
->args([
4548
service('annotations.reader'),
4649
param('kernel.cache_dir').'/annotations.php',
4750
'#^Symfony\\\\(?:Component\\\\HttpKernel\\\\|Bundle\\\\FrameworkBundle\\\\Controller\\\\(?!.*Controller$))#',
4851
param('kernel.debug'),
52+
false,
4953
])
54+
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')
5055

5156
->set('annotations.cache_adapter', PhpArrayAdapter::class)
5257
->factory([PhpArrayAdapter::class, 'create'])
@@ -55,7 +60,12 @@
5560
service('cache.annotations'),
5661
])
5762
->tag('container.hot_path')
63+
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')
5864

5965
->alias('annotation_reader', 'annotations.reader')
60-
->alias(Reader::class, 'annotation_reader');
66+
->deprecate('symfony/framework-bundle', '6.4', 'The "%alias_id%" service alias is deprecated without replacement.')
67+
68+
->alias(Reader::class, 'annotation_reader')
69+
->deprecate('symfony/framework-bundle', '6.4', 'The "%alias_id%" service alias is deprecated without replacement.')
70+
;
6171
};

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@
1515
use Doctrine\Common\Annotations\PsrCachedReader;
1616
use Doctrine\Common\Annotations\Reader;
1717
use PHPUnit\Framework\MockObject\MockObject;
18+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1819
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
1920
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
2021
use Symfony\Component\Cache\Adapter\ArrayAdapter;
2122
use Symfony\Component\Cache\Adapter\NullAdapter;
2223
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
2324
use Symfony\Component\Filesystem\Filesystem;
2425

26+
/**
27+
* @group legacy
28+
*/
2529
class AnnotationsCacheWarmerTest extends TestCase
2630
{
27-
private $cacheDir;
31+
use ExpectDeprecationTrait;
32+
33+
private string $cacheDir;
2834

2935
protected function setUp(): void
3036
{
@@ -46,7 +52,10 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
4652
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([__CLASS__], true)));
4753
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
4854
$reader = new AnnotationReader();
55+
56+
$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
4957
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile);
58+
5059
$warmer->warmUp($this->cacheDir);
5160
$this->assertFileExists($cacheFile);
5261

@@ -66,7 +75,10 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
6675
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([__CLASS__], true)));
6776
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
6877
$reader = new AnnotationReader();
78+
79+
$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
6980
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);
81+
7082
$warmer->warmUp($this->cacheDir);
7183
$this->assertFileExists($cacheFile);
7284

@@ -92,6 +104,8 @@ public function testClassAutoloadException()
92104
$this->assertFalse(class_exists($annotatedClass = 'C\C\C', false));
93105

94106
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([$annotatedClass], true)));
107+
108+
$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
95109
$warmer = new AnnotationsCacheWarmer(new AnnotationReader(), tempnam($this->cacheDir, __FUNCTION__));
96110

97111
spl_autoload_register($classLoader = function ($class) use ($annotatedClass) {
@@ -117,6 +131,7 @@ public function testClassAutoloadExceptionWithUnrelatedException()
117131
$this->assertFalse(class_exists($annotatedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_AnnotationsCacheWarmerTest', false));
118132

119133
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([$annotatedClass], true)));
134+
$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
120135
$warmer = new AnnotationsCacheWarmer(new AnnotationReader(), tempnam($this->cacheDir, __FUNCTION__));
121136

122137
spl_autoload_register($classLoader = function ($class) use ($annotatedClass) {
@@ -134,6 +149,7 @@ public function testClassAutoloadExceptionWithUnrelatedException()
134149
public function testWarmupRemoveCacheMisses()
135150
{
136151
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
152+
$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
137153
$warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class)
138154
->setConstructorArgs([new AnnotationReader(), $cacheFile])
139155
->onlyMethods(['doWarmUp'])

src/Symfony/Bundle/FrameworkBundle/Tests/Command/AboutCommand/Fixture/TestAppKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
3434
{
3535
$loader->load(static function (ContainerBuilder $container) {
3636
$container->loadFromExtension('framework', [
37+
'annotations' => false,
3738
'http_method_override' => false,
3839
]);
3940
});

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
class CacheClearCommandTest extends TestCase
2727
{
28-
/** @var TestAppKernel */
29-
private $kernel;
30-
/** @var Filesystem */
31-
private $fs;
28+
private TestAppKernel $kernel;
29+
private Filesystem $fs;
3230

3331
protected function setUp(): void
3432
{
@@ -112,7 +110,7 @@ public function testCacheIsWarmedWhenCalledTwice()
112110
$application->setCatchExceptions(false);
113111
$application->doRun($input, new NullOutput());
114112

115-
$this->assertTrue(is_file($this->kernel->getCacheDir().'/annotations.php'));
113+
$this->assertTrue(is_file($this->kernel->getCacheDir().'/dummy.txt'));
116114
}
117115

118116
public function testCacheIsWarmedWithOldContainer()

src/Symfony/Bundle/FrameworkBundle/Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1616
use Symfony\Component\Config\Loader\LoaderInterface;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1819
use Symfony\Component\HttpKernel\Kernel;
1920

2021
class TestAppKernel extends Kernel
@@ -39,5 +40,22 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
3940
protected function build(ContainerBuilder $container): void
4041
{
4142
$container->register('logger', NullLogger::class);
43+
$container->register(DummyFileCacheWarmer::class)
44+
->addTag('kernel.cache_warmer');
45+
}
46+
}
47+
48+
class DummyFileCacheWarmer implements CacheWarmerInterface
49+
{
50+
public function isOptional(): bool
51+
{
52+
return false;
53+
}
54+
55+
public function warmUp(string $cacheDir): array
56+
{
57+
file_put_contents($cacheDir.'/dummy.txt', 'Hello');
58+
59+
return [];
4260
}
4361
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
framework:
2+
annotations: false
23
http_method_override: false
34
secret: test

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy