Skip to content

[FrameworkBundle] Auto-exclude DI extensions, test cases, entities and messenger messages #59987

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
Mar 17, 2025
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
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CHANGELOG
* Add support for signal plain name in the `messenger.stop_worker_on_signals` configuration
* Deprecate the `framework.validation.cache` option
* Add `--method` option to the `debug:router` command
* Auto-exclude DI extensions, test cases, entities and messenger messages

7.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;

use Composer\InstalledVersions;
use Doctrine\ORM\Mapping\Embeddable;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use phpDocumentor\Reflection\Types\ContextFactory;
use PhpParser\Parser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Clock\ClockInterface as PsrClockInterface;
use Psr\Container\ContainerInterface as PsrContainerInterface;
Expand Down Expand Up @@ -57,6 +61,7 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -117,6 +122,7 @@
use Symfony\Component\Mailer\EventListener\SmimeSignedMessageListener;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mercure\HubRegistry;
use Symfony\Component\Messenger\Attribute\AsMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Bridge as MessengerBridge;
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
Expand Down Expand Up @@ -757,12 +763,29 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu
}
);
}
$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute): void {
$definition->addTag('json_streamer.streamable', [

$container->registerForAutoconfiguration(CompilerPassInterface::class)
->addExcludeTag('container.excluded.compiler_pass');
$container->registerForAutoconfiguration(TestCase::class)
->addExcludeTag('container.excluded.test_case');
$container->registerAttributeForAutoconfiguration(AsMessage::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.messenger.message');
});
$container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.entity');
});
$container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.embeddable');
});
$container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.mapped_superclass');
});

$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute) {
$definition->addExcludeTag('json_streamer.streamable', [
'object' => $attribute->asObject,
'list' => $attribute->asList,
]);
$definition->addTag('container.excluded');
});

if (!$container->getParameter('kernel.debug')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
->setPublic(true)
;
}
$container->setAlias($kernelClass, 'kernel')->setPublic(true);

$kernelDefinition = $container->getDefinition('kernel');
$kernelDefinition->addTag('routing.route_loader');
Expand Down Expand Up @@ -197,8 +198,6 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$kernelLoader->registerAliasesForSinglyImplementedInterfaces();
AbstractConfigurator::$valuePreProcessor = $valuePreProcessor;
}

$container->setAlias($kernelClass, 'kernel')->setPublic(true);
});
}

Expand Down
Loading