8000 feature #59987 [FrameworkBundle] Auto-exclude DI extensions, test cas… · symfony/symfony@e09e68f · GitHub
[go: up one dir, main page]

Skip to content

Commit e09e68f

Browse files
committed
feature #59987 [FrameworkBundle] Auto-exclude DI extensions, test cases, entities and messenger messages (nicolas-grekas)
This PR was merged into the 7.3 branch. Discussion ---------- [FrameworkBundle] Auto-exclude DI extensions, test cases, entities and messenger messages | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT So that we can remove the exclude lines from the default recipe. Commits ------- 9288993 [FrameworkBundle] Auto-exclude DI extensions, test cases, entities and messenger messages
2 parents c3c37f2 + 9288993 commit e09e68f

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-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, test cases, entities and messenger messages
1718

1819
7.2
1920
---

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

Lines changed: 26 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;
@@ -117,6 +122,7 @@
117122
use Symfony\Component\Mailer\EventListener\SmimeSignedMessageListener;
118123
use Symfony\Component\Mailer\Mailer;
119124
use Symfony\Component\Mercure\HubRegistry;
125+
use Symfony\Component\Messenger\Attribute\AsMessage;
120126
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
121127
use Symfony\Component\Messenger\Bridge as MessengerBridge;
122128
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
@@ -757,12 +763,29 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu
757763
}
758764
);
759765
}
760-
$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute): void {
761-
$definition->addTag('json_streamer.streamable', [
766+
767+
$container->registerForAutoconfiguration(CompilerPassInterface::class)
768+
->addExcludeTag('container.excluded.compiler_pass');
769+
$container->registerForAutoconfiguration(TestCase::class)
770+
->addExcludeTag('container.excluded.test_case');
771+
$container->registerAttributeForAutoconfiguration(AsMessage::class, static function (ChildDefinition $definition) {
772+
$definition->addExcludeTag('container.excluded.messenger.message');
773+
});
774+
$container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) {
775+
$definition->addExcludeTag('container.excluded.doctrine.entity');
776+
});
777+
$container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) {
778+
$definition->addExcludeTag('container.excluded.doctrine.embeddable');
779+
});
780+
$container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) {
781+
$definition->addExcludeTag('container.excluded.doctrine.mapped_superclass');
782+
});
783+
784+
$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute) {
785+
$definition->addExcludeTag('json_streamer.streamable', [
762786
'object' => $attribute->asObject,
763787
'list' => $attribute->asList,
764788
]);
765-
$definition->addTag('container.excluded');
766789
});
767790

768791
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)
0