8000 [HttpKernel] Deprecate `AddAnnotatedClassesToCachePass` and related code infrastructure by nicolas-grekas · Pull Request #53801 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Deprecate AddAnnotatedClassesToCachePass and 8000 related code infrastructure #53801

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
Apr 8, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ PropertyInfo

* Deprecate `PropertyTypeExtractorInterface::getTypes()`, use `PropertyTypeExtractorInterface::getType()` instead

HttpKernel
----------

* Deprecate `Extension::addAnnotatedClassesToCompile()` and related code infrastructure

SecurityBundle
--------------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
* Add `$validationFailedStatusCode` argument to `#[MapQueryParameter]` that allows setting a custom HTTP status code when validation fails
* Add `NearMissValueResolverException` to let value resolvers report when an argument could be under their watch but failed to be resolved
* Add `$type` argument to `#[MapRequestPayload]` that allows mapping a list of items
* Deprecate `Extension::addAnnotatedClassesToCompile()` and related code infrastructure

7.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
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 <fabien@symfony.com>
*
* @deprecated since Symfony 7.1, to be removed in 8.0
*/
class AddAnnotatedClassesToCachePass implements CompilerPassInterface
{
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Allow adding classes to the class cache.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal since Symfony 7.1, to be deprecated in 8.1; use Symfony\Component\DependencyInjection\Extension\Extension instead
Copy link
Member Author
@nicolas-grekas nicolas-grekas Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot deprecate this class right away in 7.1 because we rely on it in FrameworkBundle and others.
Making it first internal then deprecate in 8.1 provides a smooth upgrade path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if it is already a no-op, FrameworkBundle could stop registering it.

Copy link
Member Author
@nicolas-grekas nicolas-grekas Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean AddAnnotatedClassesToCachePass, that's done in this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see. This is about the base class then.

Marking as @internal first which removes it from our BC policy before deprecating it only in 8.1 looks weird to me. If we don't deprecate it, we might keep it as non-internal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's @internal since, which means its deprecated to use, but we signals to us we won't remove it in 8.0 for BC reasons

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but @internal since 7.1 would become @internal in 8.0, which can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can but doesn't have to, while deprecated means it should be removed
I'm looking for a smoother plan

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine by me

*/
abstract class Extension extends BaseExtension
{
Expand All @@ -26,19 +28,27 @@ abstract class Extension extends BaseExtension
* 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);
}
}
11 changes: 8 additions & 3 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\HttpKernel\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;

// Help opcache.preload discover always-needed symbols
Expand Down Expand Up @@ -278,9 +277,13 @@ public function getContainer(): ContainerInterface

/**
* @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('<?php return %s;', var_export($annotatedClasses, true)));
}

Expand Down Expand Up @@ -314,9 +317,13 @@ public function getCharset(): string
* 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 [];
}

Expand Down Expand Up @@ -591,8 +598,6 @@ protected function buildContainer(): ContainerBuilder
$this->prepareContainer($container);
$this->registerContainerConfiguration($this->getContainerLoader($container));

$container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));

return $container;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;

/**
* @group legacy
*/
class AddAnnotatedClassesToCachePassTest extends TestCase
{
public function testExpandClasses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
use Symfony\Component\HttpKernel\Tests\Fixtures\AcmeFooBundle\AcmeFooBundle;

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=8.2",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/error-handler": "^6.4|^7.0",
"symfony/event-dispatcher": "^6.4|^7.0",
"symfony/http-foundation": "^6.4|^7.0",
Expand Down
Loading
0