Skip to content

Commit a223206

Browse files
[FrameworkBundle] Auto-exclude DI extensions, test cases, entities and messenger messages
1 parent c3c37f2 commit a223206

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CHANGELOG
1414
* Add support for signal plain name in the `messenger.stop_worker_on_signals` configuration
1515
* Deprecate the `framework.validation.cache` option
1616
* Add `--method` option to the `debug:router` command
17+
* Auto-exclude DI extensions, kernel, test cases, entities and messenger messages
1718

1819
7.2
1920
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

1414
use Composer\InstalledVersions;
15+
use Doctrine\ORM\Mapping\Embeddable;
16+
use Doctrine\ORM\Mapping\Entity;
17+
use Doctrine\ORM\Mapping\MappedSuperclass;
1518
use Http\Client\HttpAsyncClient;
1619
use Http\Client\HttpClient;
1720
use phpDocumentor\Reflection\DocBlockFactoryInterface;
1821
use phpDocumentor\Reflection\Types\ContextFactory;
1922
use PhpParser\Parser;
2023
use PHPStan\PhpDocParser\Parser\PhpDocParser;
24+
use PHPUnit\Framework\TestCase;
2125
use Psr\Cache\CacheItemPoolInterface;
2226
use Psr\Clock\ClockInterface as PsrClockInterface;
2327
use Psr\Container\ContainerInterface as PsrContainerInterface;
@@ -57,6 +61,7 @@
5761
use Symfony\Component\DependencyInjection\Alias;
5862
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
5963
use Symfony\Component\DependencyInjection\ChildDefinition;
64+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6065
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
6166
use Symfony\Component\DependencyInjection\ContainerBuilder;
6267
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -99,6 +104,7 @@
99104
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
100105
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
101106
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
107+
use Symfony\Component\HttpKernel\KernelInterface;
102108
use Symfony\Component\HttpKernel\Log\DebugLoggerConfigurator;
103109
use Symfony\Component\JsonStreamer\Attribute\JsonStreamable;
104110
use Symfony\Component\JsonStreamer\JsonStreamWriter;
@@ -117,6 +123,7 @@
117123
use Symfony\Component\Mailer\EventListener\SmimeSignedMessageListener;
118124
use Symfony\Component\Mailer\Mailer;
119125
use Symfony\Component\Mercure\HubRegistry;
126+
use Symfony\Component\Messenger\Attribute\AsMessage;
120127
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
121128
use Symfony\Component\Messenger\Bridge as MessengerBridge;
122129
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
@@ -757,12 +764,29 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu
757764
}
758765
);
759766
}
760-
$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute): void {
761-
$definition->addTag('json_streamer.streamable', [
767+
768+
$container->registerForAutoconfiguration(CompilerPassInterface::class)
769+
->addExcludeTag('container.excluded.compiler_pass');
770+
$container->registerForAutoconfiguration(TestCase::class)
771+
->addExcludeTag('container.excluded.test_case');
772+
$container->registerAttributeForAutoconfiguration(AsMessage::class, static function (ChildDefinition $definition) {
773+
$definition->addExcludeTag('container.excluded.messenger.message');
774+
});
775+
$container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) {
776+
$definition->addExcludeTag('container.excluded.doctrine.entity');
777+
});
778+
$container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) {
779+
$definition->addExcludeTag('container.excluded.doctrine.embeddable');
780+
});
781+
$container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) {
782+
$definition->addExcludeTag('container.excluded.doctrine.mapped_superclass');
783+
});
784+
785+
$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute) {
786+
$definition->addExcludeTag('json_streamer.streamable', [
762787
'object' => $attribute->asObject,
763788
'list' => $attribute->asList,
764789
]);
765-
$definition->addTag('container.excluded');
766790
});
767791

768792
if (!$container->getParameter('kernel.debug')) {

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
165165
->setPublic(true)
166166
;
167167
}
168+
$container->setAlias($kernelClass, 'kernel')->setPublic(true);
168169

169170
$kernelDefinition = $container->getDefinition('kernel');
170171
$kernelDefinition->addTag('routing.route_loader');
@@ -197,8 +198,6 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
197198
$kernelLoader->registerAliasesForSinglyImplementedInterfaces();
198199
AbstractConfigurator::$valuePreProcessor = $valuePreProcessor;
199200
}
200-
201-
$container->setAlias($kernelClass, 'kernel')->setPublic(true);
202201
});
203202
}
204203

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy