diff --git a/UPGRADE-8.0.md b/UPGRADE-8.0.md index 18707ddb21f16..3a0bfdb2cc5fc 100644 --- a/UPGRADE-8.0.md +++ b/UPGRADE-8.0.md @@ -151,6 +151,13 @@ HttpClient * Remove support for amphp/http-client < 5 * Remove setLogger() methods on decorators; configure the logger on the wrapped client directly instead +HttpKernel +---------- + + * Remove `AddAnnotatedClassesToCachePass` + * Remove `Extension::getAnnotatedClassesToCompile()` and `Extension::addAnnotatedClassesToCompile()` + * Remove `Kernel::getAnnotatedClassesToCompile()` and `Kernel::setAnnotatedClassCache()` + Ldap ---- diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 5df71549449f3..f198a1d2dae2e 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -1,6 +1,13 @@ CHANGELOG ========= +8.0 +--- + +* Remove `AddAnnotatedClassesToCachePass` +* Remove `Extension::getAnnotatedClassesToCompile()` and `Extension::addAnnotatedClassesToCompile()` +* Remove `Kernel::getAnnotatedClassesToCompile()` and `Kernel::setAnnotatedClassCache()` + 7.3 --- diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php deleted file mode 100644 index c8ed6b8e41b33..0000000000000 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/AddAnnotatedClassesToCachePass.php +++ /dev/null @@ -1,144 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\DependencyInjection; - -use Composer\Autoload\ClassLoader; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\ErrorHandler\DebugClassLoader; -use Symfony\Component\HttpKernel\Kernel; - -trigger_deprecation('symfony/http-kernel', '7.1', 'The "%s" class is deprecated since Symfony 7.1 and will be removed in 8.0.', AddAnnotatedClassesToCachePass::class); - -/** - * Sets the classes to compile in the cache for the container. - * - * @author Fabien Potencier - * - * @deprecated since Symfony 7.1, to be removed in 8.0 - */ -class AddAnnotatedClassesToCachePass implements CompilerPassInterface -{ - public function __construct( - private Kernel $kernel, - ) { - } - - public function process(ContainerBuilder $container): void - { - $annotatedClasses = []; - foreach ($container->getExtensions() as $extension) { - if ($extension instanceof Extension) { - $annotatedClasses[] = $extension->getAnnotatedClassesToCompile(); - } - } - - $annotatedClasses = array_merge($this->kernel->getAnnotatedClassesToCompile(), ...$annotatedClasses); - - $existingClasses = $this->getClassesInComposerClassMaps(); - - $annotatedClasses = $container->getParameterBag()->resolveValue($annotatedClasses); - $this->kernel->setAnnotatedClassCache($this->expandClasses($annotatedClasses, $existingClasses)); - } - - /** - * Expands the given class patterns using a list of existing classes. - * - * @param array $patterns The class patterns to expand - * @param array $classes The existing classes to match against the patterns - */ - private function expandClasses(array $patterns, array $classes): array - { - $expanded = []; - - // Explicit classes declared in the patterns are returned directly - foreach ($patterns as $key => $pattern) { - if (!str_ends_with($pattern, '\\') && !str_contains($pattern, '*')) { - unset($patterns[$key]); - $expanded[] = ltrim($pattern, '\\'); - } - } - - // Match patterns with the classes list - $regexps = $this->patternsToRegexps($patterns); - - foreach ($classes as $class) { - $class = ltrim($class, '\\'); - - if ($this->matchAnyRegexps($class, $regexps)) { - $expanded[] = $class; - } - } - - return array_unique($expanded); - } - - private function getClassesInComposerClassMaps(): array - { - $classes = []; - - foreach (spl_autoload_functions() as $function) { - if (!\is_array($function)) { - continue; - } - - if ($function[0] instanceof DebugClassLoader) { - $function = $function[0]->getClassLoader(); - } - - if (\is_array($function) && $function[0] instanceof ClassLoader) { - $classes += array_filter($function[0]->getClassMap()); - } - } - - return array_keys($classes); - } - - private function patternsToRegexps(array $patterns): array - { - $regexps = []; - - foreach ($patterns as $pattern) { - // Escape user input - $regex = preg_quote(ltrim($pattern, '\\')); - - // Wildcards * and ** - $regex = strtr($regex, ['\\*\\*' => '.*?', '\\*' => '[^\\\\]*?']); - - // If this class does not end by a slash, anchor the end - if (!str_ends_with($regex, '\\')) { - $regex .= '$'; - } - - $regexps[] = '{^\\\\'.$regex.'}'; - } - - return $regexps; - } - - private function matchAnyRegexps(string $class, array $regexps): bool - { - $isTest = str_contains($class, 'Test'); - - foreach ($regexps as $regex) { - if ($isTest && !str_contains($regex, 'Test')) { - continue; - } - - if (preg_match($regex, '\\'.$class)) { - return true; - } - } - - return false; - } -} diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php index 87b81a8c5e689..ed5a68a529b73 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php @@ -22,33 +22,4 @@ */ abstract class Extension extends BaseExtension { - private array $annotatedClasses = []; - - /** - * Gets the annotated classes to cache. - * - * @return string[] - * - * @deprecated since Symfony 7.1, to be removed in 8.0 - */ - public function getAnnotatedClassesToCompile(): array - { - trigger_deprecation('symfony/http-kernel', '7.1', 'The "%s()" method is deprecated since Symfony 7.1 and will be removed in 8.0.', __METHOD__); - - return $this->annotatedClasses; - } - - /** - * Adds annotated classes to the class cache. - * - * @param string[] $annotatedClasses An array of class patterns - * - * @deprecated since Symfony 7.1, to be removed in 8.0 - */ - public function addAnnotatedClassesToCompile(array $annotatedClasses): void - { - trigger_deprecation('symfony/http-kernel', '7.1', 'The "%s()" method is deprecated since Symfony 7.1 and will be removed in 8.0.', __METHOD__); - - $this->annotatedClasses = array_merge($this->annotatedClasses, $annotatedClasses); - } } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index e9cc298f3612b..5af2cb7edea06 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -275,18 +275,6 @@ public function getContainer(): ContainerInterface return $this->container; } - /** - * @internal - * - * @deprecated since Symfony 7.1, to be removed in 8.0 - */ - public function setAnnotatedClassCache(array $annotatedClasses): void - { - trigger_deprecation('symfony/http-kernel', '7.1', 'The "%s()" method is deprecated since Symfony 7.1 and will be removed in 8.0.', __METHOD__); - - file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map', \sprintf('debug && null !== $this->startTime ? $this->startTime : -\INF; @@ -313,20 +301,6 @@ public function getCharset(): string return 'UTF-8'; } - /** - * Gets the patterns defining the classes to parse and cache for annotations. - * - * @return string[] - * - * @deprecated since Symfony 7.1, to be removed in 8.0 - */ - public function getAnnotatedClassesToCompile(): array - { - trigger_deprecation('symfony/http-kernel', '7.1', 'The "%s()" method is deprecated since Symfony 7.1 and will be removed in 8.0.', __METHOD__); - - return []; - } - /** * Initializes bundles. * diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddAnnotatedClassesToCachePassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddAnnotatedClassesToCachePassTest.php deleted file mode 100644 index e57c349609ace..0000000000000 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddAnnotatedClassesToCachePassTest.php +++ /dev/null @@ -1,101 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass; - -/** - * @group legacy - */ -class AddAnnotatedClassesToCachePassTest extends TestCase -{ - public function testExpandClasses() - { - $r = new \ReflectionClass(AddAnnotatedClassesToCachePass::class); - $pass = $r->newInstanceWithoutConstructor(); - $r = new \ReflectionMethod(AddAnnotatedClassesToCachePass::class, 'expandClasses'); - $expand = $r->getClosure($pass); - - $this->assertSame('Foo', $expand(['Foo'], [])[0]); - $this->assertSame('Foo', $expand(['\\Foo'], [])[0]); - $this->assertSame('Foo', $expand(['Foo'], ['\\Foo'])[0]); - $this->assertSame('Foo', $expand(['Foo'], ['Foo'])[0]); - $this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar'])[0]); - $this->assertSame('Foo', $expand(['Foo'], ['\\Foo\\Bar'])[0]); - $this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar\\Acme'])[0]); - - $this->assertSame('Foo\\Bar', $expand(['Foo\\'], ['\\Foo\\Bar'])[0]); - $this->assertSame('Foo\\Bar\\Acme', $expand(['Foo\\'], ['\\Foo\\Bar\\Acme'])[0]); - $this->assertSame([], $expand(['Foo\\'], ['\\Foo'])); - - $this->assertSame('Acme\\Foo\\Bar', $expand(['**\\Foo\\'], ['\\Acme\\Foo\\Bar'])[0]); - $this->assertSame([], $expand(['**\\Foo\\'], ['\\Foo\\Bar'])); - $this->assertSame([], $expand(['**\\Foo\\'], ['\\Acme\\Foo'])); - $this->assertSame([], $expand(['**\\Foo\\'], ['\\Foo'])); - - $this->assertSame('Acme\\Foo', $expand(['**\\Foo'], ['\\Acme\\Foo'])[0]); - $this->assertSame([], $expand(['**\\Foo'], ['\\Acme\\Foo\\AcmeBundle'])); - $this->assertSame([], $expand(['**\\Foo'], ['\\Acme\\FooBar\\AcmeBundle'])); - - $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bar'])[0]); - $this->assertSame([], $expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])); - - $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]); - $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]); - - $this->assertSame('Acme\\Bar', $expand(['*\\Bar'], ['\\Acme\\Bar'])[0]); - $this->assertSame([], $expand(['*\\Bar'], ['\\Bar'])); - $this->assertSame([], $expand(['*\\Bar'], ['\\Foo\\Acme\\Bar'])); - - $this->assertSame('Foo\\Acme\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]); - $this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]); - $this->assertSame([], $expand(['**\\Bar'], ['\\Bar'])); - - $this->assertSame('Foo\\Bar', $expand(['Foo\\*'], ['\\Foo\\Bar'])[0]); - $this->assertSame([], $expand(['Foo\\*'], ['\\Foo\\Acme\\Bar'])); - - $this->assertSame('Foo\\Bar', $expand(['Foo\\**'], ['\\Foo\\Bar'])[0]); - $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]); - - $this->assertSame(['Foo\\Bar'], $expand(['Foo\\*'], ['Foo\\Bar', 'Foo\\BarTest'])); - $this->assertSame(['Foo\\Bar', 'Foo\\BarTest'], $expand(['Foo\\*', 'Foo\\*Test'], ['Foo\\Bar', 'Foo\\BarTest'])); - - $this->assertSame( - 'Acme\\FooBundle\\Controller\\DefaultController', - $expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\DefaultController'])[0] - ); - - $this->assertSame( - 'FooBundle\\Controller\\DefaultController', - $expand(['**Bundle\\Controller\\'], ['\\FooBundle\\Controller\\DefaultController'])[0] - ); - - $this->assertSame( - 'Acme\\FooBundle\\Controller\\Bar\\DefaultController', - $expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'])[0] - ); - - $this->assertSame( - 'Bundle\\Controller\\Bar\\DefaultController', - $expand(['**Bundle\\Controller\\'], ['\\Bundle\\Controller\\Bar\\DefaultController'])[0] - ); - - $this->assertSame( - 'Acme\\Bundle\\Controller\\Bar\\DefaultController', - $expand(['**Bundle\\Controller\\'], ['\\Acme\\Bundle\\Controller\\Bar\\DefaultController'])[0] - ); - - $this->assertSame('Foo\\Bar', $expand(['Foo\\Bar'], [])[0]); - $this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]); - } -} diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 55416dc35ee66..7ed05041ad1bd 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -18,7 +18,6 @@ "require": { "php": ">=8.4", "psr/log": "^1|^2|^3", - "symfony/deprecation-contracts": "^2.5|^3", "symfony/error-handler": "^7.4|^8.0", "symfony/event-dispatcher": "^7.4|^8.0", "symfony/http-foundation": "^7.4|^8.0",