Skip to content

Commit

Permalink
Merge pull request #623 from Gnucki/add-context-services-to-locator
Browse files Browse the repository at this point in the history
Add context services to locator
  • Loading branch information
makasim authored Nov 7, 2018
2 parents dec922e + a7124d3 commit dbeef43
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 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->addServiceToLocator($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->addServiceToLocator($container, 'queue_consumer');
$this->addServiceToLocator($container, 'processor_registry');

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

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

if ($container->hasDefinition($locatorId)) {
$locator = $container->getDefinition($locatorId);

$map = $locator->getArgument(0);
$map[$this->format($serviceName)] = $this->reference($serviceName);

$locator->replaceArgument(0, $map);
}
}
}

0 comments on commit dbeef43

Please sign in to comment.