diff --git a/UPGRADE-7.0.md b/UPGRADE-7.0.md index 29dc9f3eeb603..03e377567e012 100644 --- a/UPGRADE-7.0.md +++ b/UPGRADE-7.0.md @@ -121,6 +121,8 @@ FrameworkBundle $this->render(..., ['form' => $form]); ``` + * Remove the integration of Doctrine annotations, use native attributes instead + HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index fb6e47029a9c1..bf516bbe8033f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG `Symfony\Component\Serializer\Normalizer\PropertyNormalizer` autowiring aliases, type-hint against `Symfony\Component\Serializer\Normalizer\NormalizerInterface` or implement `NormalizerAwareInterface` instead * Remove the `Http\Client\HttpClient` service, use `Psr\Http\Client\ClientInterface` instead + * Remove the integration of Doctrine annotations, use native attributes instead 6.4 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php deleted file mode 100644 index 279dc4ec9e702..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php +++ /dev/null @@ -1,114 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\CacheWarmer; - -use Doctrine\Common\Annotations\AnnotationException; -use Doctrine\Common\Annotations\PsrCachedReader; -use Doctrine\Common\Annotations\Reader; -use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\PhpArrayAdapter; - -/** - * Warms up annotation caches for classes found in composer's autoload class map - * and declared in DI bundle extensions using the addAnnotatedClassesToCache method. - * - * @author Titouan Galopin - * - * @deprecated since Symfony 6.4 without replacement - */ -class AnnotationsCacheWarmer extends AbstractPhpFileCacheWarmer -{ - /** - * @param string $phpArrayFile The PHP file where annotations are cached - */ - 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); - } - - protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool - { - $annotatedClassPatterns = $cacheDir.'/annotations.map'; - - if (!is_file($annotatedClassPatterns)) { - return true; - } - - $annotatedClasses = include $annotatedClassPatterns; - $reader = new PsrCachedReader($this->annotationReader, $arrayAdapter, $this->debug); - - foreach ($annotatedClasses as $class) { - if (null !== $this->excludeRegexp && preg_match($this->excludeRegexp, $class)) { - continue; - } - try { - $this->readAllComponents($reader, $class); - } catch (\Exception $e) { - $this->ignoreAutoloadException($class, $e); - } - } - - return true; - } - - /** - * @return string[] A list of classes to preload on PHP 7.4+ - */ - protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values): array - { - // make sure we don't cache null values - $values = array_filter($values, fn ($val) => null !== $val); - - return parent::warmUpPhpArrayAdapter($phpArrayAdapter, $values); - } - - private function readAllComponents(Reader $reader, string $class): void - { - $reflectionClass = new \ReflectionClass($class); - - try { - $reader->getClassAnnotations($reflectionClass); - } catch (AnnotationException) { - /* - * Ignore any AnnotationException to not break the cache warming process if an Annotation is badly - * configured or could not be found / read / etc. - * - * In particular cases, an Annotation in your code can be used and defined only for a specific - * environment but is always added to the annotations.map file by some Symfony default behaviors, - * and you always end up with a not found Annotation. - */ - } - - foreach ($reflectionClass->getMethods() as $reflectionMethod) { - try { - $reader->getMethodAnnotations($reflectionMethod); - } catch (AnnotationException) { - } - } - - foreach ($reflectionClass->getProperties() as $reflectionProperty) { - try { - $reader->getPropertyAnnotations($reflectionProperty); - } catch (AnnotationException) { - } - } - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php index ae5daac8eee15..c21b7369d894b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php @@ -23,9 +23,9 @@ class UnusedTagsPass implements CompilerPassInterface { private const KNOWN_TAGS = [ 'annotations.cached_reader', - 'assets.package', 'asset_mapper.compiler', 'asset_mapper.importmap.resolver', + 'assets.package', 'auto_alias', 'cache.pool', 'cache.pool.clearer', @@ -33,7 +33,6 @@ class UnusedTagsPass implements CompilerPassInterface 'chatter.transport_factory', 'config_cache.resource_checker', 'console.command', - 'container.do_not_inline', 'container.env_var_loader', 'container.env_var_processor', 'container.excluded', diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 8ca6a54c06803..29048942b8176 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -11,7 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; -use Doctrine\Common\Annotations\Annotation; use Doctrine\DBAL\Connection; use Psr\Log\LogLevel; use Symfony\Bundle\FullStack; @@ -155,7 +154,7 @@ public function getConfigTreeBuilder(): TreeBuilder $this->addAssetMapperSection($rootNode, $enableIfStandalone); $this->addTranslatorSection($rootNode, $enableIfStandalone); $this->addValidationSection($rootNode, $enableIfStandalone); - $this->addAnnotationsSection($rootNode, $willBeAvailable); + $this->addAnnotationsSection($rootNode); $this->addSerializerSection($rootNode, $enableIfStandalone); $this->addPropertyAccessSection($rootNode, $willBeAvailable); $this->addPropertyInfoSection($rootNode, $enableIfStandalone); @@ -1057,21 +1056,15 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e ; } - private function addAnnotationsSection(ArrayNodeDefinition $rootNode, callable $willBeAvailable): void + private function addAnnotationsSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() ->arrayNode('annotations') - ->info('annotation configuration') - ->{$willBeAvailable('doctrine/annotations', Annotation::class) ? 'canBeDisabled' : 'canBeEnabled'}() - ->children() - ->enumNode('cache') - ->values(['none', 'php_array', 'file']) - ->defaultValue('php_array') - ->end() - ->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end() - ->booleanNode('debug')->defaultValue($this->debug)->end() - ->end() + ->canBeEnabled() + ->validate() + ->ifTrue(static fn (array $v) => $v['enabled']) + ->thenInvalid('Enabling the doctrine/annotations integration is not supported anymore.') ->end() ->end() ; diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index e266ab1f0404d..d4b16662ac1a7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; use Composer\InstalledVersions; -use Doctrine\Common\Annotations\Reader; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; use phpDocumentor\Reflection\DocBlockFactoryInterface; @@ -54,7 +53,6 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -255,7 +253,6 @@ public function load(array $configs, ContainerBuilder $container): void $config = $this->processConfiguration($configuration, $configs); // warmup config enabled - $this->readConfigEnabled('annotations', $container, $config['annotations']); $this->readConfigEnabled('translator', $container, $config['translator']); $this->readConfigEnabled('property_access', $container, $config['property_access']); $this->readConfigEnabled('profiler', $container, $config['profiler']); @@ -363,7 +360,6 @@ public function load(array $configs, ContainerBuilder $container): void $this->registerWorkflowConfiguration($config['workflows'], $container, $loader); $this->registerDebugConfiguration($config['php_errors'], $container, $loader); $this->registerRouterConfiguration($config['router'], $container, $loader, $config['enabled_locales']); - $this->registerAnnotationsConfiguration($config['annotations'], $container, $loader); $this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader); $this->registerSecretsConfiguration($config['secrets'], $container, $loader); @@ -1600,10 +1596,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder $definition->replaceArgument(0, $config['email_validation_mode']); if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) { - $validatorBuilder->addMethodCall('enableAnnotationMapping', [true]); - if ($this->isInitializedConfigEnabled('annotations')) { - $validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]); - } + $validatorBuilder->addMethodCall('enableAnnotationMapping'); } if (\array_key_exists('static_method', $config) && $config['static_method']) { @@ -1698,58 +1691,6 @@ private function registerMappingFilesFromConfig(ContainerBuilder $container, arr } } - private function registerAnnotationsConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader): void - { - if (!$this->isInitializedConfigEnabled('annotations')) { - return; - } - - if (!class_exists(\Doctrine\Common\Annotations\Annotation::class)) { - 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']) { - $container->removeDefinition('annotations.cached_reader'); - - return; - } - - if ('php_array' === $config['cache']) { - $cacheService = 'annotations.cache_adapter'; - - // Enable warmer only if PHP array is used for cache - $definition = $container->findDefinition('annotations.cache_warmer'); - $definition->addTag('kernel.cache_warmer'); - } else { - $cacheService = 'annotations.filesystem_cache_adapter'; - $cacheDir = $container->getParameterBag()->resolveValue($config['file_cache_dir']); - - if (!is_dir($cacheDir) && false === @mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) { - throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir)); - } - - $container - ->getDefinition('annotations.filesystem_cache_adapter') - ->replaceArgument(2, $cacheDir) - ; - } - - $container - ->getDefinition('annotations.cached_reader') - ->replaceArgument(2, $config['debug']) - // reference the cache provider without using it until AddAnnotationsCachedReaderPass runs - ->addArgument(new ServiceClosureArgument(new Reference($cacheService))) - ; - - $container->setAlias('annotation_reader', 'annotations.cached_reader'); - $container->setAlias(Reader::class, new Alias('annotations.cached_reader', false)); - $container->removeDefinition('annotations.psr_cached_reader'); - } - private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void { if (!$this->readConfigEnabled('property_access', $container, $config)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php deleted file mode 100644 index ddf65175bb928..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php +++ /dev/null @@ -1,71 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Loader\Configurator; - -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Annotations\PsrCachedReader; -use Doctrine\Common\Annotations\Reader; -use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer; -use Symfony\Component\Cache\Adapter\ArrayAdapter; -use Symfony\Component\Cache\Adapter\FilesystemAdapter; -use Symfony\Component\Cache\Adapter\PhpArrayAdapter; - -return static function (ContainerConfigurator $container) { - $container->services() - ->set('annotations.reader', AnnotationReader::class) - ->call('addGlobalIgnoredName', ['required']) - ->deprecate('symfony/framework-bundle', '6.4', 'The "%service_id%" service is deprecated without replacement.') - - ->set('annotations.cached_reader', PsrCachedReader::class) - ->args([ - service('annotations.reader'), - inline_service(ArrayAdapter::class), - abstract_arg('Debug-Flag'), - ]) - ->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']) - ->args([ - param('kernel.cache_dir').'/annotations.php', - 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') - ->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.') - ; -}; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php deleted file mode 100644 index 6ff003b47d105..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php +++ /dev/null @@ -1,191 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer; - -use Doctrine\Common\Annotations\AnnotationReader; -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 -{ - use ExpectDeprecationTrait; - - private string $cacheDir; - - protected function setUp(): void - { - $this->cacheDir = sys_get_temp_dir().'/'.uniqid(); - $fs = new Filesystem(); - $fs->mkdir($this->cacheDir); - parent::setUp(); - } - - protected function tearDown(): void - { - $fs = new Filesystem(); - $fs->remove($this->cacheDir); - parent::tearDown(); - } - - public function testAnnotationsCacheWarmerWithDebugDisabled() - { - file_put_contents($this->cacheDir.'/annotations.map', sprintf('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); - - // Assert cache is valid - $reader = new PsrCachedReader( - $this->getReadOnlyReader(), - new PhpArrayAdapter($cacheFile, new NullAdapter()) - ); - $refClass = new \ReflectionClass($this); - $reader->getClassAnnotations($refClass); - $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); - $reader->getPropertyAnnotations($refClass->getProperty('cacheDir')); - } - - public function testAnnotationsCacheWarmerWithDebugEnabled() - { - file_put_contents($this->cacheDir.'/annotations.map', sprintf('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); - - // Assert cache is valid - $phpArrayAdapter = new PhpArrayAdapter($cacheFile, new NullAdapter()); - $reader = new PsrCachedReader( - $this->getReadOnlyReader(), - $phpArrayAdapter, - true - ); - $refClass = new \ReflectionClass($this); - $reader->getClassAnnotations($refClass); - $reader->getMethodAnnotations($refClass->getMethod(__FUNCTION__)); - $reader->getPropertyAnnotations($refClass->getProperty('cacheDir')); - } - - /** - * Test that the cache warming process is not broken if a class loader - * throws an exception (on class / file not found for example). - */ - public function testClassAutoloadException() - { - $this->assertFalse(class_exists($annotatedClass = 'C\C\C', false)); - - file_put_contents($this->cacheDir.'/annotations.map', sprintf('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) { - if ($class === $annotatedClass) { - throw new \DomainException('This exception should be caught by the warmer.'); - } - }, true, true); - - $warmer->warmUp($this->cacheDir); - - spl_autoload_unregister($classLoader); - } - - /** - * Test that the cache warming process is broken if a class loader throws an - * exception but that is unrelated to the class load. - */ - public function testClassAutoloadExceptionWithUnrelatedException() - { - $this->expectException(\DomainException::class); - $this->expectExceptionMessage('This exception should not be caught by the warmer.'); - - $this->assertFalse(class_exists($annotatedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_AnnotationsCacheWarmerTest', false)); - - file_put_contents($this->cacheDir.'/annotations.map', sprintf('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) { - if ($class === $annotatedClass) { - eval('class '.$annotatedClass.'{}'); - throw new \DomainException('This exception should not be caught by the warmer.'); - } - }, true, true); - - $warmer->warmUp($this->cacheDir); - - spl_autoload_unregister($classLoader); - } - - 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']) - ->getMock(); - - $warmer->method('doWarmUp')->willReturnCallback(function ($cacheDir, ArrayAdapter $arrayAdapter) { - $arrayAdapter->getItem('foo_miss'); - - $item = $arrayAdapter->getItem('bar_hit'); - $item->set('data'); - $arrayAdapter->save($item); - - $item = $arrayAdapter->getItem('baz_hit_null'); - $item->set(null); - $arrayAdapter->save($item); - - return true; - }); - - $warmer->warmUp($this->cacheDir); - $data = include $cacheFile; - - $this->assertCount(1, $data[0]); - $this->assertTrue(isset($data[0]['bar_hit'])); - } - - private function getReadOnlyReader(): MockObject&Reader - { - $readerMock = $this->createMock(Reader::class); - $readerMock->expects($this->exactly(0))->method('getClassAnnotations'); - $readerMock->expects($this->exactly(0))->method('getClassAnnotation'); - $readerMock->expects($this->exactly(0))->method('getMethodAnnotations'); - $readerMock->expects($this->exactly(0))->method('getMethodAnnotation'); - $readerMock->expects($this->exactly(0))->method('getPropertyAnnotations'); - $readerMock->expects($this->exactly(0))->method('getPropertyAnnotation'); - - return $readerMock; - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 2e291157abcbd..bca02cbf220aa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -557,10 +557,7 @@ protected static function getBundleDefaultConfig() ], ], 'annotations' => [ - 'cache' => 'php_array', - 'file_cache_dir' => '%kernel.cache_dir%/annotations', - 'debug' => true, - 'enabled' => true, + 'enabled' => false, ], 'serializer' => [ 'default_context' => [], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/legacy_annotations.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/legacy_annotations.php deleted file mode 100644 index a939b34f152d1..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/legacy_annotations.php +++ /dev/null @@ -1,10 +0,0 @@ -loadFromExtension('framework', [ - 'annotations' => [ - 'cache' => 'file', - 'debug' => true, - 'file_cache_dir' => '%kernel.cache_dir%/annotations', - ], - 'http_method_override' => false, -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php deleted file mode 100644 index 48b281e65d7d9..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_legacy_annotations.php +++ /dev/null @@ -1,15 +0,0 @@ -loadFromExtension('framework', [ - 'annotations' => [ - 'enabled' => true, - ], - 'http_method_override' => false, - 'secret' => 's3cr3t', - 'validation' => [ - 'enabled' => true, - 'enable_annotations' => true, - ], -]); - -$container->setAlias('validator.alias', 'validator')->setPublic(true); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/legacy_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/legacy_annotations.xml deleted file mode 100644 index 57229dad686d0..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/legacy_annotations.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml deleted file mode 100644 index 150473a569eaa..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_legacy_annotations.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/legacy_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/legacy_annotations.yml deleted file mode 100644 index 0d34e986c426d..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/legacy_annotations.yml +++ /dev/null @@ -1,7 +0,0 @@ -framework: - annotations: - enabled: true - cache: file - debug: true - file_cache_dir: '%kernel.cache_dir%/annotations' - http_method_override: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml deleted file mode 100644 index afee3fe1537fc..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_legacy_annotations.yml +++ /dev/null @@ -1,13 +0,0 @@ -framework: - annotations: - enabled: true - http_method_override: false - secret: s3cr3t - validation: - enabled: true - enable_annotations: true - -services: - validator.alias: - alias: validator - public: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php index da4468c2e12b1..12ae8ccef6984 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -35,7 +35,6 @@ use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\ChildDefinition; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveTaggedIteratorArgumentPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -94,7 +93,7 @@ abstract class FrameworkExtensionTestCase extends TestCase { use ExpectDeprecationTrait; - private static $containerCache = []; + private static array $containerCache = []; abstract protected function loadFromFile(ContainerBuilder $container, $file); @@ -1223,19 +1222,16 @@ public function testValidationService() $this->assertInstanceOf(ValidatorInterface::class, $container->get('validator.alias')); } - /** - * @group legacy - */ public function testAnnotations() { - $this->expectDeprecation('Since symfony/framework-bundle 6.4: Enabling the integration of Doctrine annotations is deprecated. Set the "framework.annotations.enabled" config option to false.'); - - $container = $this->createContainerFromFile('legacy_annotations', [], true, false); - $container->addCompilerPass(new TestAnnotationsPass()); - $container->compile(); + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Invalid configuration for path "framework.annotations": Enabling the doctrine/annotations integration is not supported anymore.'); - $this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.filesystem_cache_adapter')->getArgument(2)); - $this->assertSame('annotations.filesystem_cache_adapter', (string) $container->getDefinition('annotation_reader')->getArgument(1)); + $this->createContainerFromClosure(function (ContainerBuilder $container) { + $container->loadFromExtension('framework', [ + 'annotations' => true, + ]); + }); } public function testFileLinkFormat() @@ -1264,28 +1260,6 @@ public function testValidationAnnotations() // no cache this time } - /** - * @group legacy - */ - public function testValidationLegacyAnnotations() - { - $this->expectDeprecation('Since symfony/framework-bundle 6.4: Enabling the integration of Doctrine annotations is deprecated. Set the "framework.annotations.enabled" config option to false.'); - - $container = $this->createContainerFromFile('validation_legacy_annotations'); - - $calls = $container->getDefinition('validator.builder')->getMethodCalls(); - - $this->assertCount(8, $calls); - $this->assertSame('enableAnnotationMapping', $calls[4][0]); - $this->assertSame('setDoctrineAnnotationReader', $calls[5][0]); - $this->assertEquals([new Reference('annotation_reader')], $calls[5][1]); - $this->assertSame('addMethodMapping', $calls[6][0]); - $this->assertSame(['loadValidatorMetadata'], $calls[6][1]); - $this->assertSame('setMappingCache', $calls[7][0]); - $this->assertEquals([new Reference('validator.mapping.cache.adapter')], $calls[7][1]); - // no cache this time - } - public function testValidationPaths() { require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php'; @@ -2317,7 +2291,7 @@ protected function createContainer(array $data = []) ], $data))); } - protected function createContainerFromFile(string $file, array $data = [], bool $resetCompilerPasses = true, bool $compile = true, FrameworkExtension $extension = null) + protected function createContainerFromFile(string $file, array $data = [], bool $resetCompilerPasses = true, bool $compile = true, FrameworkExtension $extension = null): ContainerBuilder { $cacheKey = md5(static::class.$file.serialize($data)); if ($compile && isset(self::$containerCache[$cacheKey])) { @@ -2344,7 +2318,7 @@ protected function createContainerFromFile(string $file, array $data = [], bool return self::$containerCache[$cacheKey] = $container; } - protected function createContainerFromClosure($closure, $data = []) + protected function createContainerFromClosure($closure, $data = []): ContainerBuilder { $container = $this->createContainer($data); $container->registerExtension(new FrameworkExtension()); @@ -2416,15 +2390,3 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con }; } } - -/** - * Simulates ReplaceAliasByActualDefinitionPass. - */ -class TestAnnotationsPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container): void - { - $container->setDefinition('annotation_reader', $container->getDefinition('annotations.cached_reader')); - $container->removeDefinition('annotations.cached_reader'); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php index 95f99ef2ca6be..28ce69f935d6f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Annotations\PsrCachedReader; -use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher; @@ -21,34 +18,6 @@ class AutowiringTypesTest extends AbstractWebTestCase { - use ExpectDeprecationTrait; - - /** - * @group legacy - */ - public function testAnnotationReaderAutowiring() - { - $this->expectDeprecation('Since symfony/framework-bundle 6.4: Enabling the integration of Doctrine annotations is deprecated. Set the "framework.annotations.enabled" config option to false.'); - - static::bootKernel(['root_config' => 'no_annotations_cache.yml', 'environment' => 'no_annotations_cache']); - - $annotationReader = self::getContainer()->get('test.autowiring_types.autowired_services')->getAnnotationReader(); - $this->assertInstanceOf(AnnotationReader::class, $annotationReader); - } - - /** - * @group legacy - */ - public function testCachedAnnotationReaderAutowiring() - { - $this->expectDeprecation('Since symfony/framework-bundle 6.4: Enabling the integration of Doctrine annotations is deprecated. Set the "framework.annotations.enabled" config option to false.'); - - static::bootKernel(['root_config' => 'with_annotations.yml', 'environment' => 'with_annotations']); - - $annotationReader = self::getContainer()->get('test.autowiring_types.autowired_services')->getAnnotationReader(); - $this->assertInstanceOf(PsrCachedReader::class, $annotationReader); - } - public function testEventDispatcherAutowiring() { static::bootKernel(['debug' => false]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php index 4743460e6ee5b..c5a5decce9d36 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php @@ -11,26 +11,15 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes; -use Doctrine\Common\Annotations\Reader; use Psr\Cache\CacheItemPoolInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class AutowiredServices { - private $annotationReader; - private $dispatcher; - private $cachePool; - - public function __construct(Reader $annotationReader = null, EventDispatcherInterface $dispatcher, CacheItemPoolInterface $cachePool) - { - $this->annotationReader = $annotationReader; - $this->dispatcher = $dispatcher; - $this->cachePool = $cachePool; - } - - public function getAnnotationReader() - { - return $this->annotationReader; + public function __construct( + private readonly EventDispatcherInterface $dispatcher, + private readonly CacheItemPoolInterface $cachePool, + ) { } public function getDispatcher() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml deleted file mode 100644 index fa78d720045a9..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml +++ /dev/null @@ -1,8 +0,0 @@ -imports: - - { resource: config.yml } - -framework: - http_method_override: false - annotations: - enabled: true - cache: none diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/with_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/with_annotations.yml deleted file mode 100644 index cb87d7f4ebd73..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/with_annotations.yml +++ /dev/null @@ -1,6 +0,0 @@ -imports: - - { resource: config.yml } - -framework: - annotations: - enabled: true diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 722a4c5f10243..bf371b6e873e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -33,7 +33,6 @@ "symfony/routing": "^6.4|^7.0" }, "require-dev": { - "doctrine/annotations": "^1.13.1|^2", "doctrine/persistence": "^1.3|^2|^3", "symfony/asset": "^6.4|^7.0", "symfony/asset-mapper": "^6.4|^7.0", @@ -73,7 +72,6 @@ "twig/twig": "^2.10|^3.0" }, "conflict": { - "doctrine/annotations": "<1.13.1", "doctrine/persistence": "<1.3", "phpdocumentor/reflection-docblock": "<3.2.2", "phpdocumentor/type-resolver": "<1.4.0",