Skip to content

Commit

Permalink
Reduce conditions in addServiceDefinitionFromCallable
Browse files Browse the repository at this point in the history
  • Loading branch information
bnf committed Sep 12, 2018
1 parent 202e37b commit d8cf411
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/ServiceProviderCompilationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function registerService($serviceName, $serviceProviderKey, $callable, C
}

private function extendService($serviceName, $serviceProviderKey, $callable, ContainerBuilder $container) {
$this->addServiceDefinitionFromCallable($serviceName, $serviceProviderKey, $callable, $container, true);
$this->addServiceDefinitionFromCallable($serviceName, $serviceProviderKey, $callable, $container, 'extendService');
}

private function getDecoratedServiceName($serviceName, ContainerBuilder $container) {
Expand All @@ -104,19 +104,15 @@ private function getDecoratedServiceName($serviceName, ContainerBuilder $contain
];
}

private function addServiceDefinitionFromCallable($serviceName, $serviceProviderKey, callable $callable, ContainerBuilder $container, bool $extension = false)
private function addServiceDefinitionFromCallable($serviceName, $serviceProviderKey, callable $callable, ContainerBuilder $container, string $method = 'createService')
{
/*if ($callable instanceof DefinitionInterface) {
// TODO: plug the definition-interop converter here!
}*/

$finalServiceName = $serviceName;
$innerName = null;

$factoryDefinition = new Definition($this->getReturnType($callable, $serviceName));
$factoryDefinition->setPublic(true);

if ($extension && $container->has($serviceName)) {
if ($method === 'extendService' && $container->has($serviceName)) {
list($finalServiceName, $previousServiceName) = $this->getDecoratedServiceName($serviceName, $container);
$innerName = $finalServiceName . '.inner';

Expand All @@ -126,8 +122,7 @@ private function addServiceDefinitionFromCallable($serviceName, $serviceProvider
if ((is_array($callable) && is_string($callable[0])) || is_string($callable)) {
$factoryDefinition->setFactory($callable);
} else {
$registryMethod = $extension ? 'extendService' : 'createService';
$factoryDefinition->setFactory([ new Reference('service_provider_registry_'.$this->registryId), $registryMethod ]);
$factoryDefinition->setFactory([ new Reference('service_provider_registry_'.$this->registryId), $method ]);
$factoryDefinition->addArgument($serviceProviderKey);
$factoryDefinition->addArgument($serviceName);
}
Expand Down

0 comments on commit d8cf411

Please sign in to comment.