Skip to content

Commit

Permalink
Merge pull request #944 from alcaeus/wire-messenger-transport-factory
Browse files Browse the repository at this point in the history
Wire messenger transport factory
  • Loading branch information
alcaeus committed Apr 6, 2019
2 parents d295756 + 45817de commit 8fb9dbb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 20 additions & 7 deletions DependencyInjection/DoctrineExtension.php
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory;

/**
* DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
Expand Down Expand Up @@ -367,13 +368,7 @@ protected function ormLoad(array $config, ContainerBuilder $container)
$container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class)
->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG);

// If the Messenger component is installed and the doctrine transaction middleware is available, wire it:
if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineTransactionMiddleware::class)) {
return;
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('messenger.xml');
$this->loadMessengerServices($container);
}

/**
Expand Down Expand Up @@ -793,4 +788,22 @@ public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($container->getParameter('kernel.debug'));
}

private function loadMessengerServices(ContainerBuilder $container) : void
{
// If the Messenger component is installed and the doctrine transaction middleware is available, wire it:
if (! interface_exists(MessageBusInterface::class) || ! class_exists(DoctrineTransactionMiddleware::class)) {
return;
}

$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('messenger.xml');

if (! class_exists(DoctrineTransportFactory::class)) {
return;
}

$transportFactoryDefinition = $container->getDefinition('messenger.transport.doctrine.factory');
$transportFactoryDefinition->addTag('messenger.transport_factory');
}
}
8 changes: 8 additions & 0 deletions Resources/config/messenger.xml
Expand Up @@ -11,5 +11,13 @@
<service id="messenger.middleware.doctrine_transaction" class="Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware" abstract="true" public="false">
<argument type="service" id="doctrine" />
</service>

<!--
The following service isn't tagged as transport factory because the class may not exist.
The tag is added conditionally in DoctrineExtension.
-->
<service id="messenger.transport.doctrine.factory" class="Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory" public="false">
<argument type="service" id="doctrine" />
</service>
</services>
</container>

0 comments on commit 8fb9dbb

Please sign in to comment.