Skip to content

[FrameworkBundle] Deprecate doctrine/annotations integration #50888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions UPGRADE-6.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ FrameworkBundle
---------------

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

HttpFoundation
--------------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

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

6.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@
* and declared in DI bundle extensions using the addAnnotatedClassesToCache method.
*
* @author Titouan Galopin <galopintitouan@gmail.com>
*
* @deprecated since Symfony 6.4 without replacement
*/
class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer
{
private Reader $annotationReader;
private ?string $excludeRegexp;
private bool $debug;

/**
* @param string $phpArrayFile The PHP file where annotations are cached
*/
public function __construct(Reader $annotationReader, string $phpArrayFile, string $excludeRegexp = null, bool $debug = false)
{
public function __construct(
private readonly Reader $annotationReader,
string $phpArrayFile,
private readonly ?string $excludeRegexp = null,
private readonly bool $debug = false,
/* bool $triggerDeprecation = true, */
) {
if (\func_num_args() < 5 || func_get_arg(4)) {
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated without replacement.', __CLASS__);
}

parent::__construct($phpArrayFile);
$this->annotationReader = $annotationReader;
$this->excludeRegexp = $excludeRegexp;
$this->debug = $debug;
}

protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed. Try running "composer require doctrine/annotations".');
}

trigger_deprecation('symfony/framework-bundle', '6.4', 'Enabling the integration of Doctrine annotations is deprecated. Set the "framework.annotations.enabled" config option to false.');

$loader->load('annotations.php');

if ('none' === $config['cache']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
$container->services()
->set('annotations.reader', AnnotationReader::class)
->call('addGlobalIgnoredName', ['required']) // @deprecated since Symfony 6.3
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')

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

->set('annotations.filesystem_cache_adapter', FilesystemAdapter::class)
->args([
'',
0,
abstract_arg('Cache-Directory'),
])
->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.')

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

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

->alias('annotation_reader', 'annotations.reader')
->alias(Reader::class, 'annotation_reader');
->deprecate('symfony/framework-bundle', '6.4', 'The "%alias_id%" service alias is deprecated without replacement.')

->alias(Reader::class, 'annotation_reader')
->deprecate('symfony/framework-bundle', '6.4', 'The "%alias_id%" service alias is deprecated without replacement.')
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
use Doctrine\Common\Annotations\PsrCachedReader;
use Doctrine\Common\Annotations\Reader;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\NullAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Filesystem\Filesystem;

/**
* @group legacy
*/
class AnnotationsCacheWarmerTest extends TestCase
{
private $cacheDir;
use ExpectDeprecationTrait;

private string $cacheDir;

protected function setUp(): void
{
Expand All @@ -46,7 +52,10 @@ public function testAnnotationsCacheWarmerWithDebugDisabled()
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([__CLASS__], true)));
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
$reader = new AnnotationReader();

$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile);

$warmer->warmUp($this->cacheDir);
$this->assertFileExists($cacheFile);

Expand All @@ -66,7 +75,10 @@ public function testAnnotationsCacheWarmerWithDebugEnabled()
file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([__CLASS__], true)));
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
$reader = new AnnotationReader();

$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
$warmer = new AnnotationsCacheWarmer($reader, $cacheFile, null, true);

$warmer->warmUp($this->cacheDir);
$this->assertFileExists($cacheFile);

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

file_put_contents($this->cacheDir.'/annotations.map', sprintf('<?php return %s;', var_export([$annotatedClass], true)));

$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
$warmer = new AnnotationsCacheWarmer(new AnnotationReader(), tempnam($this->cacheDir, __FUNCTION__));

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

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

spl_autoload_register($classLoader = function ($class) use ($annotatedClass) {
Expand All @@ -134,6 +149,7 @@ public function testClassAutoloadExceptionWithUnrelatedException()
public function testWarmupRemoveCacheMisses()
{
$cacheFile = tempnam($this->cacheDir, __FUNCTION__);
$this->expectDeprecation('Since symfony/framework-bundle 6.4: The "Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer" class is deprecated without replacement.');
$warmer = $this->getMockBuilder(AnnotationsCacheWarmer::class)
->setConstructorArgs([new AnnotationReader(), $cacheFile])
->onlyMethods(['doWarmUp'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(static function (ContainerBuilder $container) {
$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

class CacheClearCommandTest extends TestCase
{
/** @var TestAppKernel */
private $kernel;
/** @var Filesystem */
private $fs;
private TestAppKernel $kernel;
private Filesystem $fs;

protected function setUp(): void
{
Expand Down Expand Up @@ -112,7 +110,7 @@ public function testCacheIsWarmedWhenCalledTwice()
$application->setCatchExceptions(false);
$application->doRun($input, new NullOutput());

$this->assertTrue(is_file($this->kernel->getCacheDir().'/annotations.php'));
$this->assertTrue(is_file($this->kernel->getCacheDir().'/dummy.txt'));
}

public function testCacheIsWarmedWithOldContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\Kernel;

class TestAppKernel extends Kernel
Expand All @@ -39,5 +40,22 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
protected function build(ContainerBuilder $container): void
{
$container->register('logger', NullLogger::class);
$container->register(DummyFileCacheWarmer::class)
->addTag('kernel.cache_warmer');
}
}

class DummyFileCacheWarmer implements CacheWarmerInterface
{
public function isOptional(): bool
{
return false;
}

public function warmUp(string $cacheDir): array
{
file_put_contents($cacheDir.'/dummy.txt', 'Hello');

return [];
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
framework:
annotations: false
http_method_override: false
secret: test
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'assets' => [
'version' => 'SomeVersionScheme',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'assets' => [
'enabled' => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'assets' => [
'version_strategy' => 'assets.custom_version_strategy',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'cache' => [
'pools' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'cache' => [
'app' => 'cache.adapter.redis_tag_aware',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'cache' => [
'app' => 'cache.redis_tag_aware.foo',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'csrf_protection' => true,
'session' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'csrf_protection' => [
'enabled' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

$container->loadFromExtension('framework', [
'http_method_override' => false,]);
'annotations' => false,
'http_method_override' => false,
]);
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'fragments' => [
'enabled' => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'esi' => [
'enabled' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'exceptions' => [
BadRequestHttpException::class => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'csrf_protection' => false,
'form' => [
'csrf_protection' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'session' => [
'storage_factory_id' => 'session.storage.factory.native',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'form' => [
'csrf_protection' => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'fragments' => [
'enabled' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@
'validation' => [
'enabled' => true,
],
'annotations' => [
'cache' => 'file',
'debug' => true,
'file_cache_dir' => '%kernel.cache_dir%/annotations',
],
'annotations' => false,
'serializer' => [
'enabled' => true,
'enable_annotations' => true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'html_sanitizer' => [
'sanitizers' => [
Expand Down
Loading