Skip to content

Commit

Permalink
TASK: Do not add listeners pass multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Dec 11, 2023
1 parent b648f34 commit 3f8f46d
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,34 @@ static function (ChildDefinition $definition, AsMessageHandler $attribute): void
$containerBuilder->registerForAutoconfiguration(EventSubscriberInterface::class)
->addTag('kernel.event_subscriber');

// Compiler passes
$registerListenersPass = new RegisterListenersPass();
if (class_exists(ConsoleEvents::class) && method_exists($registerListenersPass, 'setNoPreloadEvents')) {
$registerListenersPass->setNoPreloadEvents([
ConsoleEvents::COMMAND,
ConsoleEvents::TERMINATE,
ConsoleEvents::ERROR,
]);
$shouldAddRegisterListenersPass = true;
$beforeRemovingPasses = $containerBuilder->getCompilerPassConfig()->getBeforeRemovingPasses();
foreach ($beforeRemovingPasses as $beforeRemovingPass) {
if ($beforeRemovingPass instanceof RegisterListenersPass) {
$shouldAddRegisterListenersPass = false;
break;
}
}

if ($shouldAddRegisterListenersPass) {
// Compiler passes
$registerListenersPass = new RegisterListenersPass();
if (class_exists(ConsoleEvents::class) && method_exists($registerListenersPass, 'setNoPreloadEvents')) {
$registerListenersPass->setNoPreloadEvents([
ConsoleEvents::COMMAND,
ConsoleEvents::TERMINATE,
ConsoleEvents::ERROR,
]);
}
// must be registered before removing private services as some might be listeners/subscribers
// but as late as possible to get resolved parameters
$containerBuilder->addCompilerPass($registerListenersPass, PassConfig::TYPE_BEFORE_REMOVING);
}

$services->set(ShowConfigurationCommand::class)->tag('console.command', [
'command' => 't3_messenger:show-configuration',
]);

// must be registered before removing private services as some might be listeners/subscribers
// but as late as possible to get resolved parameters
$containerBuilder->addCompilerPass($registerListenersPass, PassConfig::TYPE_BEFORE_REMOVING);
$containerBuilder->addCompilerPass(new MessengerMailerPass('event.listener'));
$containerBuilder->addCompilerPass(new T3MessengerPass(new MessengerConfigurationResolver()));
$containerBuilder->addCompilerPass(new MessengerPass());
Expand Down

0 comments on commit 3f8f46d

Please sign in to comment.