Skip to content

Commit

Permalink
Add context services to locator
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnucki committed Nov 7, 2018
1 parent dec922e commit cafe22d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/enqueue/Symfony/DependencyInjection/TransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function buildContext(ContainerBuilder $container, array $config): void
->setFactory([new Reference($factoryId), 'createContext'])
;

$this->fillLocator($container, 'context');

if ('default' === $this->name) {
$container->setAlias(Context::class, $this->format('context'));
}
Expand Down Expand Up @@ -187,14 +189,8 @@ public function buildQueueConsumer(ContainerBuilder $container, array $config):

$container->register($this->format('processor_registry'), ContainerProcessorRegistry::class);

$locatorId = 'enqueue.locator';
if ($container->hasDefinition($locatorId)) {
$locator = $container->getDefinition($locatorId);
$locator->replaceArgument(0, array_replace($locator->getArgument(0), [
$this->format('queue_consumer') => new Reference($this->format('queue_consumer')),
$this->format('processor_registry') => new Reference($this->format('processor_registry')),
]));
}
$this->fillLocator($container, 'queue_consumer');
$this->fillLocator($container, 'processor_registry');

if ('default' === $this->name) {
$container->setAlias(QueueConsumerInterface::class, $this->format('queue_consumer'));
Expand Down Expand Up @@ -226,4 +222,16 @@ private function assertServiceExists(ContainerBuilder $container, string $servic
throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $serviceId));
}
}

private function fillLocator(ContainerBuilder $container, string $serviceName): void
{
$locatorId = 'enqueue.locator';

if ($container->hasDefinition($locatorId)) {
$locator = $container->getDefinition($locatorId);
$locator->replaceArgument(0, array_replace($locator->getArgument(0), [
$this->format($serviceName) => new Reference($this->format($serviceName)),
]));
}
}
}

0 comments on commit cafe22d

Please sign in to comment.