diff --git a/packages/aws-tool-kit/DependencyInjection/AwsToolKitIntegration.php b/packages/aws-tool-kit/DependencyInjection/AwsToolKitIntegration.php index 7a1cab82a..9538a7782 100644 --- a/packages/aws-tool-kit/DependencyInjection/AwsToolKitIntegration.php +++ b/packages/aws-tool-kit/DependencyInjection/AwsToolKitIntegration.php @@ -2,17 +2,19 @@ namespace Draw\Component\AwsToolKit\DependencyInjection; +use Draw\Component\AwsToolKit\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass; use Draw\Component\AwsToolKit\EventListener\NewestInstanceRoleCheckListener; use Draw\Component\AwsToolKit\Imds\ImdsClientInterface; use Draw\Component\AwsToolKit\Imds\ImdsClientV1; use Draw\Component\AwsToolKit\Imds\ImdsClientV2; +use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface; use Draw\Component\DependencyInjection\Integration\IntegrationInterface; use Draw\Component\DependencyInjection\Integration\IntegrationTrait; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -class AwsToolKitIntegration implements IntegrationInterface +class AwsToolKitIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface { use IntegrationTrait; @@ -21,6 +23,11 @@ public function getConfigSectionName(): string return 'aws_tool_kit'; } + public function buildContainer(ContainerBuilder $container): void + { + $container->addCompilerPass(new AddNewestInstanceRoleCommandOptionPass()); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $this->registerClasses( diff --git a/packages/aws-tool-kit/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPass.php b/packages/aws-tool-kit/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPass.php new file mode 100644 index 000000000..d8908fe3b --- /dev/null +++ b/packages/aws-tool-kit/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPass.php @@ -0,0 +1,35 @@ +findDefinition(NewestInstanceRoleCheckListener::class); + } catch (ServiceNotFoundException) { + return; + } + + foreach (DefinitionFinder::findConsoleCommandDefinitions($container) as $definition) { + $definition + ->addMethodCall( + 'addOption', + [ + NewestInstanceRoleCheckListener::OPTION_AWS_NEWEST_INSTANCE_ROLE, + null, + InputOption::VALUE_REQUIRED, + 'The instance role the server must be the newest of to run the command.', + ] + ); + } + } +} diff --git a/packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPassTest.php b/packages/aws-tool-kit/Tests/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPassTest.php similarity index 91% rename from packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPassTest.php rename to packages/aws-tool-kit/Tests/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPassTest.php index 11750d593..14d2a1204 100644 --- a/packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPassTest.php +++ b/packages/aws-tool-kit/Tests/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPassTest.php @@ -1,8 +1,8 @@ findTaggedServiceIds('console.command')) as $serviceId) { - $definition = $container->getDefinition($serviceId); - if ($definition->isAbstract()) { - continue; - } - + foreach (DefinitionFinder::findConsoleCommandDefinitions($container) as $definition) { $definition->addMethodCall( 'addOption', [ diff --git a/packages/console/DependencyInjection/ConsoleIntegration.php b/packages/console/DependencyInjection/ConsoleIntegration.php index 6b58153b9..8a45575c4 100644 --- a/packages/console/DependencyInjection/ConsoleIntegration.php +++ b/packages/console/DependencyInjection/ConsoleIntegration.php @@ -3,10 +3,12 @@ namespace Draw\Component\Console\DependencyInjection; use Draw\Component\Console\Command\PurgeExecutionCommand; +use Draw\Component\Console\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass; use Draw\Component\Console\Descriptor\TextDescriptor; use Draw\Component\Console\Entity\Execution; use Draw\Component\Console\EventListener\CommandFlowListener; use Draw\Component\Console\EventListener\DocumentationFilterCommandEventListener; +use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface; use Draw\Component\DependencyInjection\Integration\IntegrationInterface; use Draw\Component\DependencyInjection\Integration\IntegrationTrait; use Draw\Component\DependencyInjection\Integration\PrependIntegrationInterface; @@ -17,7 +19,7 @@ use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Reference; -class ConsoleIntegration implements IntegrationInterface, PrependIntegrationInterface +class ConsoleIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface, PrependIntegrationInterface { use IntegrationTrait; @@ -26,6 +28,11 @@ public function getConfigSectionName(): string return 'console'; } + public function buildContainer(ContainerBuilder $container): void + { + $container->addCompilerPass(new AddCommandExecutionOptionsCompilerPass()); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $this->registerClasses( diff --git a/packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddCommandExecutionOptionsCompilerPassTest.php b/packages/console/Tests/DependencyInjection/Compiler/AddCommandExecutionOptionsCompilerPassTest.php similarity index 92% rename from packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddCommandExecutionOptionsCompilerPassTest.php rename to packages/console/Tests/DependencyInjection/Compiler/AddCommandExecutionOptionsCompilerPassTest.php index d038891f3..01c88ad6b 100644 --- a/packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/AddCommandExecutionOptionsCompilerPassTest.php +++ b/packages/console/Tests/DependencyInjection/Compiler/AddCommandExecutionOptionsCompilerPassTest.php @@ -1,8 +1,8 @@ findDefinition(PostExecutionQueueCronJobListener::class); + } catch (ServiceNotFoundException) { + return; + } + + foreach (DefinitionFinder::findConsoleCommandDefinitions($container) as $definition) { + $definition + ->addMethodCall( + 'addOption', + [ + PostExecutionQueueCronJobListener::OPTION_POST_EXECUTION_QUEUE_CRON_JOB, + null, + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + 'Queue does cron job by name after execution of the command.', + ] + ); + } + } +} diff --git a/packages/cron-job/DependencyInjection/CronJobIntegration.php b/packages/cron-job/DependencyInjection/CronJobIntegration.php index 8c8f9c41f..d8713f596 100644 --- a/packages/cron-job/DependencyInjection/CronJobIntegration.php +++ b/packages/cron-job/DependencyInjection/CronJobIntegration.php @@ -5,7 +5,9 @@ namespace Draw\Component\CronJob\DependencyInjection; use Draw\Component\CronJob\CronJobProcessor; +use Draw\Component\CronJob\DependencyInjection\Compiler\AddPostCronJobExecutionOptionPass; use Draw\Component\CronJob\Entity\CronJob; +use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface; use Draw\Component\DependencyInjection\Integration\IntegrationInterface; use Draw\Component\DependencyInjection\Integration\IntegrationTrait; use Draw\Component\DependencyInjection\Integration\PrependIntegrationInterface; @@ -13,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -class CronJobIntegration implements IntegrationInterface, PrependIntegrationInterface +class CronJobIntegration implements IntegrationInterface, ContainerBuilderIntegrationInterface, PrependIntegrationInterface { use IntegrationTrait; @@ -22,6 +24,11 @@ public function getConfigSectionName(): string return 'cron_job'; } + public function buildContainer(ContainerBuilder $container): void + { + $container->addCompilerPass(new AddPostCronJobExecutionOptionPass()); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $this->registerClasses( diff --git a/packages/dependency-injection/Container/DefinitionFinder.php b/packages/dependency-injection/Container/DefinitionFinder.php new file mode 100644 index 000000000..7cb39e435 --- /dev/null +++ b/packages/dependency-injection/Container/DefinitionFinder.php @@ -0,0 +1,24 @@ + + */ + public static function findConsoleCommandDefinitions(ContainerBuilder $container, bool $ignoreAbstract = true): iterable + { + foreach (array_keys($container->findTaggedServiceIds('console.command')) as $serviceId) { + $definition = $container->getDefinition($serviceId); + if ($ignoreAbstract && $definition->isAbstract()) { + continue; + } + + yield $definition; + } + } +} diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/TagIfExpressionCompilerPass.php b/packages/dependency-injection/DependencyInjection/Compiler/TagIfExpressionCompilerPass.php similarity index 93% rename from packages/framework-extra-bundle/DependencyInjection/Compiler/TagIfExpressionCompilerPass.php rename to packages/dependency-injection/DependencyInjection/Compiler/TagIfExpressionCompilerPass.php index d56124558..27f6fbacc 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/TagIfExpressionCompilerPass.php +++ b/packages/dependency-injection/DependencyInjection/Compiler/TagIfExpressionCompilerPass.php @@ -1,6 +1,6 @@ addCompilerPass(new TagIfExpressionCompilerPass()); + } + + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void + { + } + + public function addConfiguration(ArrayNodeDefinition $node): void + { + } +} diff --git a/packages/dependency-injection/Integration/ContainerBuilderIntegrationInterface.php b/packages/dependency-injection/Integration/ContainerBuilderIntegrationInterface.php new file mode 100644 index 000000000..b0e7f4818 --- /dev/null +++ b/packages/dependency-injection/Integration/ContainerBuilderIntegrationInterface.php @@ -0,0 +1,10 @@ + + */ + public function getIntegrations(): array + { + return $this->integrations; + } + private function registerDefaultIntegrations(): void { foreach ($this->provideExtensionClasses() as $extensionClass) { diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/EntityMigratorCompilerPass.php b/packages/entity-migrator/DependencyInjection/Compiler/EntityMigratorCompilerPass.php similarity index 94% rename from packages/framework-extra-bundle/DependencyInjection/Compiler/EntityMigratorCompilerPass.php rename to packages/entity-migrator/DependencyInjection/Compiler/EntityMigratorCompilerPass.php index 1c734b6a4..b8e0ecc1b 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/EntityMigratorCompilerPass.php +++ b/packages/entity-migrator/DependencyInjection/Compiler/EntityMigratorCompilerPass.php @@ -1,6 +1,6 @@ addCompilerPass(new EntityMigratorCompilerPass()); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $container diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPass.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPass.php deleted file mode 100644 index 18b30982a..000000000 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/AddNewestInstanceRoleCommandOptionPass.php +++ /dev/null @@ -1,37 +0,0 @@ -findDefinition(NewestInstanceRoleCheckListener::class); - } catch (ServiceNotFoundException) { - return; - } - - foreach (array_keys($container->findTaggedServiceIds('console.command')) as $serviceId) { - $definition = $container->getDefinition($serviceId); - if (!$definition->isAbstract()) { - $definition - ->addMethodCall( - 'addOption', - [ - NewestInstanceRoleCheckListener::OPTION_AWS_NEWEST_INSTANCE_ROLE, - null, - InputOption::VALUE_REQUIRED, - 'The instance role the server must be the newest of to run the command.', - ] - ); - } - } - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/AddPostCronJobExecutionOptionPass.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/AddPostCronJobExecutionOptionPass.php deleted file mode 100644 index fef7eaebe..000000000 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/AddPostCronJobExecutionOptionPass.php +++ /dev/null @@ -1,37 +0,0 @@ -findDefinition(PostExecutionQueueCronJobListener::class); - } catch (ServiceNotFoundException) { - return; - } - - foreach (array_keys($container->findTaggedServiceIds('console.command')) as $serviceId) { - $definition = $container->getDefinition($serviceId); - if (!$definition->isAbstract()) { - $definition - ->addMethodCall( - 'addOption', - [ - PostExecutionQueueCronJobListener::OPTION_POST_EXECUTION_QUEUE_CRON_JOB, - null, - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Queue does cron job by name after execution of the command.', - ] - ); - } - } - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/ConsolePathAwareCompilerPassTrait.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/ConsolePathAwareCompilerPassTrait.php deleted file mode 100644 index 45b8dd2a2..000000000 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/ConsolePathAwareCompilerPassTrait.php +++ /dev/null @@ -1,30 +0,0 @@ -findDefinition($definitionId); - } catch (ServiceNotFoundException) { - return; - } - - if (null === $symfonyConsolePath = $container->getParameter('draw.symfony_console_path')) { - $symfonyConsolePath = $container->getParameterBag()->resolveValue('%kernel.project_dir%/bin/console'); - } - - if (false === realpath($symfonyConsolePath)) { - throw new \RuntimeException('The draw_framework_extra.symfony_console_path value ['.$symfonyConsolePath.'] is invalid'); - } - - $definition->setArgument('$consolePath', realpath($symfonyConsolePath)); - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerBrokerCompilerPass.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerBrokerCompilerPass.php deleted file mode 100644 index 1419f79a7..000000000 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerBrokerCompilerPass.php +++ /dev/null @@ -1,17 +0,0 @@ -setConsolePathArgument($container, StartMessengerBrokerCommand::class); - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerRetryFailedMessageMessageHandlerCompilerPass.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerRetryFailedMessageMessageHandlerCompilerPass.php deleted file mode 100644 index 4d7ed7cc9..000000000 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerRetryFailedMessageMessageHandlerCompilerPass.php +++ /dev/null @@ -1,19 +0,0 @@ -setConsolePathArgument($container, RetryFailedMessageMessageHandler::class); - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/UserCheckerDecoratorPass.php b/packages/framework-extra-bundle/DependencyInjection/Compiler/UserCheckerDecoratorPass.php deleted file mode 100644 index e43076d26..000000000 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/UserCheckerDecoratorPass.php +++ /dev/null @@ -1,26 +0,0 @@ -hasDefinition('security.user_checker')) { - $container->setDefinition( - 'draw.security.core.user.event_driven_user_checker', - new Definition(EventDrivenUserChecker::class) - ) - ->setAutoconfigured(true) - ->setAutowired(true) - ->setDecoratedService('security.user_checker', 'draw.security.core.user.event_driven_user_checker.inner') - ->setArgument('$decoratedUserChecker', new Reference('draw.security.core.user.event_driven_user_checker.inner')); - } - } -} diff --git a/packages/framework-extra-bundle/DependencyInjection/DrawFrameworkExtraExtension.php b/packages/framework-extra-bundle/DependencyInjection/DrawFrameworkExtraExtension.php index 65d2d2b5d..cdbfd755e 100644 --- a/packages/framework-extra-bundle/DependencyInjection/DrawFrameworkExtraExtension.php +++ b/packages/framework-extra-bundle/DependencyInjection/DrawFrameworkExtraExtension.php @@ -10,6 +10,7 @@ use Draw\Component\AwsToolKit\DependencyInjection\AwsToolKitIntegration; use Draw\Component\Console\DependencyInjection\ConsoleIntegration; use Draw\Component\CronJob\DependencyInjection\CronJobIntegration; +use Draw\Component\DependencyInjection\DependencyInjection\DependencyInjectionIntegration; use Draw\Component\DependencyInjection\Integration\ExtendableExtensionTrait; use Draw\Component\DependencyInjection\Integration\IntegrationInterface; use Draw\Component\EntityMigrator\DependencyInjection\EntityMigratorIntegration; @@ -47,6 +48,7 @@ public function __construct(?array $integrations = null) private function provideExtensionClasses(): array { return [ + DependencyInjectionIntegration::class, AwsToolKitIntegration::class, ConfigurationIntegration::class, ConsoleIntegration::class, diff --git a/packages/framework-extra-bundle/DrawFrameworkExtraBundle.php b/packages/framework-extra-bundle/DrawFrameworkExtraBundle.php index 1e659c63f..3ecd929be 100644 --- a/packages/framework-extra-bundle/DrawFrameworkExtraBundle.php +++ b/packages/framework-extra-bundle/DrawFrameworkExtraBundle.php @@ -2,32 +2,8 @@ namespace Draw\Bundle\FrameworkExtraBundle; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddPostCronJobExecutionOptionPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\EmailWriterCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\EntityMigratorCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\JmsDoctrineObjectConstructionCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\LoggerDecoratorPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\MessengerBrokerCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\MessengerRetryFailedMessageMessageHandlerCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\MessengerTransportNamesCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\TagIfExpressionCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\UserCheckerDecoratorPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Factory\Security\JwtAuthenticatorFactory; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Factory\Security\MessengerMessageAuthenticatorFactory; -use Draw\Component\Console\EventListener\CommandFlowListener; -use Draw\Component\EntityMigrator\Migrator; -use Draw\Component\Mailer\EmailWriter\EmailWriterInterface; -use Draw\Component\Messenger\Broker\Broker; -use Draw\Component\Messenger\Expirable\Command\PurgeExpiredMessageCommand; -use Draw\Component\Messenger\MessageHandler\RetryFailedMessageMessageHandler; -use Draw\Component\OpenApi\OpenApi; -use Draw\Component\Security\Core\User\EventDrivenUserChecker; -use Draw\Component\Security\Http\Authenticator\JwtAuthenticator; -use Draw\Component\Security\Http\Authenticator\MessageAuthenticator; -use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; -use Symfony\Component\DependencyInjection\Compiler\PassConfig; +use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\DrawFrameworkExtraExtension; +use Draw\Component\DependencyInjection\Integration\ContainerBuilderIntegrationInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -35,66 +11,15 @@ class DrawFrameworkExtraBundle extends Bundle { public function build(ContainerBuilder $container): void { - $container->addCompilerPass(new TagIfExpressionCompilerPass()); + $containerExtension = $this->getContainerExtension(); - // It needs to run after the LoggerChannelPass - $container->addCompilerPass(new LoggerDecoratorPass(), priority: -1); + \assert($containerExtension instanceof DrawFrameworkExtraExtension); - if (class_exists(EventDrivenUserChecker::class)) { - $container->addCompilerPass(new UserCheckerDecoratorPass()); - } - - if (class_exists(Broker::class)) { - $container->addCompilerPass(new MessengerBrokerCompilerPass()); - } - - if (class_exists(RetryFailedMessageMessageHandler::class)) { - $container->addCompilerPass(new MessengerRetryFailedMessageMessageHandlerCompilerPass()); - } - - if (class_exists(AddNewestInstanceRoleCommandOptionPass::class)) { - $container->addCompilerPass(new AddNewestInstanceRoleCommandOptionPass()); - } - - if (class_exists(AddPostCronJobExecutionOptionPass::class)) { - $container->addCompilerPass(new AddPostCronJobExecutionOptionPass()); - } - - if (class_exists(CommandFlowListener::class)) { - $container->addCompilerPass(new AddCommandExecutionOptionsCompilerPass()); - } - - if (interface_exists(EmailWriterInterface::class)) { - $container->addCompilerPass(new EmailWriterCompilerPass()); - } - - if (class_exists(Migrator::class)) { - $container->addCompilerPass(new EntityMigratorCompilerPass()); - } - - if (class_exists(PurgeExpiredMessageCommand::class)) { - $container->addCompilerPass( - new MessengerTransportNamesCompilerPass(), - PassConfig::TYPE_BEFORE_OPTIMIZATION, - -1 - ); - } - - if (class_exists(OpenApi::class)) { - $container->addCompilerPass(new JmsDoctrineObjectConstructionCompilerPass()); - } - - if ($container->hasExtension('security')) { - /** @var SecurityExtension $extension */ - $extension = $container->getExtension('security'); - - if (class_exists(JwtAuthenticator::class)) { - $extension->addAuthenticatorFactory(new JwtAuthenticatorFactory()); - } - - if (class_exists(MessageAuthenticator::class)) { - $extension->addAuthenticatorFactory(new MessengerMessageAuthenticatorFactory()); + foreach ($containerExtension->getIntegrations() as $integration) { + if ($integration instanceof ContainerBuilderIntegrationInterface) { + $integration->buildContainer($container); } } + } } diff --git a/packages/framework-extra-bundle/Tests/DrawFrameworkExtraBundleTest.php b/packages/framework-extra-bundle/Tests/DrawFrameworkExtraBundleTest.php index 2de7082e2..327228731 100644 --- a/packages/framework-extra-bundle/Tests/DrawFrameworkExtraBundleTest.php +++ b/packages/framework-extra-bundle/Tests/DrawFrameworkExtraBundleTest.php @@ -2,21 +2,19 @@ namespace Draw\Bundle\FrameworkExtraBundle\Tests; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\AddPostCronJobExecutionOptionPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\EmailWriterCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\EntityMigratorCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\JmsDoctrineObjectConstructionCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\LoggerDecoratorPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\MessengerBrokerCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\MessengerRetryFailedMessageMessageHandlerCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\MessengerTransportNamesCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\TagIfExpressionCompilerPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler\UserCheckerDecoratorPass; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Factory\Security\JwtAuthenticatorFactory; -use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Factory\Security\MessengerMessageAuthenticatorFactory; use Draw\Bundle\FrameworkExtraBundle\DrawFrameworkExtraBundle; +use Draw\Component\AwsToolKit\DependencyInjection\Compiler\AddNewestInstanceRoleCommandOptionPass; +use Draw\Component\Console\DependencyInjection\Compiler\AddCommandExecutionOptionsCompilerPass; +use Draw\Component\CronJob\DependencyInjection\Compiler\AddPostCronJobExecutionOptionPass; +use Draw\Component\DependencyInjection\DependencyInjection\Compiler\TagIfExpressionCompilerPass; +use Draw\Component\EntityMigrator\DependencyInjection\Compiler\EntityMigratorCompilerPass; +use Draw\Component\Log\DependencyInjection\Compiler\LoggerDecoratorPass; +use Draw\Component\Mailer\DependencyInjection\Compiler\EmailWriterCompilerPass; +use Draw\Component\Messenger\DependencyInjection\Compiler\MessengerTransportNamesCompilerPass; +use Draw\Component\OpenApi\DependencyInjection\Compiler\JmsDoctrineObjectConstructionCompilerPass; +use Draw\Component\Security\DependencyInjection\Compiler\UserCheckerDecoratorPass; +use Draw\Component\Security\DependencyInjection\Factory\JwtAuthenticatorFactory; +use Draw\Component\Security\DependencyInjection\Factory\MessengerMessageAuthenticatorFactory; use Draw\Component\Tester\MockTrait; use PHPUnit\Framework\TestCase; use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; @@ -39,7 +37,7 @@ public function testBuild(): void $containerBuilder = $this->createMock(ContainerBuilder::class); $containerBuilder - ->expects(static::exactly(12)) + ->expects(static::exactly(10)) ->method('addCompilerPass') ->with( ...static::withConsecutive( @@ -49,27 +47,12 @@ public function testBuild(): void 0, ], [ - static::isInstanceOf(LoggerDecoratorPass::class), - PassConfig::TYPE_BEFORE_OPTIMIZATION, - -1, - ], - [ - static::isInstanceOf(UserCheckerDecoratorPass::class), - PassConfig::TYPE_BEFORE_OPTIMIZATION, - 0, - ], - [ - static::isInstanceOf(MessengerBrokerCompilerPass::class), - PassConfig::TYPE_BEFORE_OPTIMIZATION, - 0, - ], - [ - static::isInstanceOf(MessengerRetryFailedMessageMessageHandlerCompilerPass::class), + static::isInstanceOf(AddNewestInstanceRoleCommandOptionPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0, ], [ - static::isInstanceOf(AddNewestInstanceRoleCommandOptionPass::class), + static::isInstanceOf(AddCommandExecutionOptionsCompilerPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0, ], @@ -79,17 +62,17 @@ public function testBuild(): void 0, ], [ - static::isInstanceOf(AddCommandExecutionOptionsCompilerPass::class), + static::isInstanceOf(EntityMigratorCompilerPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0, ], [ - static::isInstanceOf(EmailWriterCompilerPass::class), + static::isInstanceOf(LoggerDecoratorPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, - 0, + -1, ], [ - static::isInstanceOf(EntityMigratorCompilerPass::class), + static::isInstanceOf(EmailWriterCompilerPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 0, ], @@ -103,6 +86,11 @@ public function testBuild(): void PassConfig::TYPE_BEFORE_OPTIMIZATION, 0, ], + [ + static::isInstanceOf(UserCheckerDecoratorPass::class), + PassConfig::TYPE_BEFORE_OPTIMIZATION, + 0, + ], ) ) ->willReturnSelf(); diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php b/packages/log/DependencyInjection/Compiler/LoggerDecoratorPass.php similarity index 98% rename from packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php rename to packages/log/DependencyInjection/Compiler/LoggerDecoratorPass.php index 5bbd0ff6e..c7f01c34c 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/LoggerDecoratorPass.php +++ b/packages/log/DependencyInjection/Compiler/LoggerDecoratorPass.php @@ -1,6 +1,6 @@ addCompilerPass(new LoggerDecoratorPass(), priority: -1); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $enableAllProcessors = $config['enable_all_processors']; diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/EmailWriterCompilerPass.php b/packages/mailer/DependencyInjection/Compiler/EmailWriterCompilerPass.php similarity index 96% rename from packages/framework-extra-bundle/DependencyInjection/Compiler/EmailWriterCompilerPass.php rename to packages/mailer/DependencyInjection/Compiler/EmailWriterCompilerPass.php index 80488c2d0..25e463618 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/EmailWriterCompilerPass.php +++ b/packages/mailer/DependencyInjection/Compiler/EmailWriterCompilerPass.php @@ -1,6 +1,6 @@ addCompilerPass(new EmailWriterCompilerPass()); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $this->registerClasses( diff --git a/packages/messenger/Broker/Command/StartMessengerBrokerCommand.php b/packages/messenger/Broker/Command/StartMessengerBrokerCommand.php index e28249422..55be43b1c 100644 --- a/packages/messenger/Broker/Command/StartMessengerBrokerCommand.php +++ b/packages/messenger/Broker/Command/StartMessengerBrokerCommand.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class StartMessengerBrokerCommand extends Command @@ -18,6 +19,7 @@ class StartMessengerBrokerCommand extends Command private const OPTION_VALUE_CONCURRENT_AUTO = 'auto'; public function __construct( + #[Autowire('%draw.symfony_console_path%')] private string $consolePath, private ProcessFactoryInterface $processFactory, private EventDispatcherInterface $eventDispatcher, diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerTransportNamesCompilerPass.php b/packages/messenger/DependencyInjection/Compiler/MessengerTransportNamesCompilerPass.php similarity index 89% rename from packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerTransportNamesCompilerPass.php rename to packages/messenger/DependencyInjection/Compiler/MessengerTransportNamesCompilerPass.php index cba0567cf..91e7228d4 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/MessengerTransportNamesCompilerPass.php +++ b/packages/messenger/DependencyInjection/Compiler/MessengerTransportNamesCompilerPass.php @@ -1,6 +1,6 @@ addCompilerPass( + new MessengerTransportNamesCompilerPass(), + PassConfig::TYPE_BEFORE_OPTIMIZATION, + -1 + ); + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $namespace = 'Draw\\Component\\Messenger\\'; diff --git a/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php b/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php index 6e736f2ab..556caec11 100644 --- a/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php +++ b/packages/messenger/MessageHandler/RetryFailedMessageMessageHandler.php @@ -6,12 +6,14 @@ use Draw\Component\Messenger\Message\RetryFailedMessageMessage; use Draw\Contracts\Process\ProcessFactoryInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Messenger\Attribute\AsMessageHandler; class RetryFailedMessageMessageHandler { public function __construct( private ProcessFactoryInterface $processFactory, + #[Autowire('%draw.symfony_console_path%')] private string $consolePath, ) { } diff --git a/packages/framework-extra-bundle/DependencyInjection/Compiler/JmsDoctrineObjectConstructionCompilerPass.php b/packages/open-api/DependencyInjection/Compiler/JmsDoctrineObjectConstructionCompilerPass.php similarity index 91% rename from packages/framework-extra-bundle/DependencyInjection/Compiler/JmsDoctrineObjectConstructionCompilerPass.php rename to packages/open-api/DependencyInjection/Compiler/JmsDoctrineObjectConstructionCompilerPass.php index 855ba0dcd..7eab25c45 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Compiler/JmsDoctrineObjectConstructionCompilerPass.php +++ b/packages/open-api/DependencyInjection/Compiler/JmsDoctrineObjectConstructionCompilerPass.php @@ -1,6 +1,6 @@ addCompilerPass(new JmsDoctrineObjectConstructionCompilerPass()); + } + public function addConfiguration(ArrayNodeDefinition $node): void { $node diff --git a/packages/security/DependencyInjection/Compiler/UserCheckerDecoratorPass.php b/packages/security/DependencyInjection/Compiler/UserCheckerDecoratorPass.php new file mode 100644 index 000000000..7160fc7f5 --- /dev/null +++ b/packages/security/DependencyInjection/Compiler/UserCheckerDecoratorPass.php @@ -0,0 +1,28 @@ +hasDefinition('security.user_checker')) { + return; + } + + $container->setDefinition( + 'draw.security.core.user.event_driven_user_checker', + new Definition(EventDrivenUserChecker::class) + ) + ->setAutoconfigured(true) + ->setAutowired(true) + ->setDecoratedService('security.user_checker', 'draw.security.core.user.event_driven_user_checker.inner') + ->setArgument('$decoratedUserChecker', new Reference('draw.security.core.user.event_driven_user_checker.inner')); + } +} diff --git a/packages/framework-extra-bundle/DependencyInjection/Factory/Security/JwtAuthenticatorFactory.php b/packages/security/DependencyInjection/Factory/JwtAuthenticatorFactory.php similarity index 97% rename from packages/framework-extra-bundle/DependencyInjection/Factory/Security/JwtAuthenticatorFactory.php rename to packages/security/DependencyInjection/Factory/JwtAuthenticatorFactory.php index a089cdd70..ccaebd8c6 100644 --- a/packages/framework-extra-bundle/DependencyInjection/Factory/Security/JwtAuthenticatorFactory.php +++ b/packages/security/DependencyInjection/Factory/JwtAuthenticatorFactory.php @@ -1,6 +1,6 @@ addCompilerPass(new UserCheckerDecoratorPass()); + + if ($container->hasExtension('security')) { + $extension = $container->getExtension('security'); + + \assert($extension instanceof SecurityExtension); + + $extension->addAuthenticatorFactory(new JwtAuthenticatorFactory()); + $extension->addAuthenticatorFactory(new MessengerMessageAuthenticatorFactory()); + } + } + public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void { $this->loadCore($config, $loader, $container); diff --git a/packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/UserCheckerDecoratorPassTest.php b/packages/security/Tests/DependencyInjection/Compiler/UserCheckerDecoratorPassTest.php similarity index 90% rename from packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/UserCheckerDecoratorPassTest.php rename to packages/security/Tests/DependencyInjection/Compiler/UserCheckerDecoratorPassTest.php index a77b5da73..ac187cf5a 100644 --- a/packages/framework-extra-bundle/Tests/DependencyInjection/Compiler/UserCheckerDecoratorPassTest.php +++ b/packages/security/Tests/DependencyInjection/Compiler/UserCheckerDecoratorPassTest.php @@ -1,9 +1,9 @@