Skip to content

Commit

Permalink
Fixing weird infinite loop issue
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Aug 30, 2018
1 parent b20c237 commit 275fc35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/Definition/FactoryCallDefinition.php
Expand Up @@ -123,4 +123,9 @@ public function toPhpCode(string $containerVariable, array $usedVariables = arra

return new InlineEntry($code, $prependedCode, $usedVariables);
}

public function cloneWithoutIdentifier(): self
{
return new self(null, $this->factory, $this->methodName, $this->methodArguments);
}
}
5 changes: 5 additions & 0 deletions src/ServiceProvider/CreateServiceFromRegistryDefinition.php
Expand Up @@ -69,4 +69,9 @@ public function toPhpCode(string $containerVariable, array $usedVariables = arra

return new InlineEntry($code, null, $usedVariables);
}

public function cloneWithoutIdentifier(): self
{
return new self(null, $this->serviceName, $this->serviceProviderKey);
}
}
5 changes: 5 additions & 0 deletions src/ServiceProvider/ExtendServiceFromRegistryDefinition.php
Expand Up @@ -82,4 +82,9 @@ public function toPhpCode(string $containerVariable, array $usedVariables = arra

return new InlineEntry($code, null, $usedVariables);
}

public function cloneWithoutIdentifier(): self
{
return new self(null, $this->serviceName, $this->serviceProviderKey, $this->previousDefinition);
}
}
12 changes: 5 additions & 7 deletions src/ServiceProvider/ServiceProviderLoader.php
Expand Up @@ -126,9 +126,11 @@ private function extendService(string $serviceName, int $serviceProviderKey, cal

// TODO: it would be way easier if we could simply rename a definition!!!
if ($previousDefinition instanceof FactoryCallDefinition) {
$innerDefinition = new FactoryCallDefinition(null /*$innerName*/, $previousDefinition->getFactory(), $previousDefinition->getMethodName(), $previousDefinition->getMethodArguments());
} elseif ($previousDefinition instanceof CreateServiceFromRegistryDefinition || $previousDefinition instanceof ExtendServiceFromRegistryDefinition) {
$innerDefinition = $previousDefinition;
$innerDefinition = $previousDefinition->cloneWithoutIdentifier();
} elseif ($previousDefinition instanceof CreateServiceFromRegistryDefinition) {
$innerDefinition = $previousDefinition->cloneWithoutIdentifier();
} elseif ($previousDefinition instanceof ExtendServiceFromRegistryDefinition) {
$innerDefinition = $previousDefinition->cloneWithoutIdentifier();
} else {
// @codeCoverageIgnoreStart
throw new CompilerException('Unable to rename definition from class '.get_class($previousDefinition));
Expand All @@ -153,8 +155,6 @@ private function extendService(string $serviceName, int $serviceProviderKey, cal
*/
private function getCreateServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, callable $callable, ContainerDefinition $containerDefinition): DumpableInterface
{
// FIXME: we must split this method in 2. One for the factories and one for the extensions!

if ($callable instanceof DefinitionInterface) {
return $this->converter->convert($decoratedServiceName, $callable);
}
Expand Down Expand Up @@ -183,8 +183,6 @@ private function getCreateServiceDefinitionFromCallable($decoratedServiceName, $
*/
private function getExtendServiceDefinitionFromCallable($decoratedServiceName, $serviceName, $serviceProviderKey, callable $callable, ContainerDefinition $containerDefinition, DumpableInterface $previousDefinition = null): DumpableInterface
{
// FIXME: we must split this method in 2. One for the factories and one for the extensions!

if ($callable instanceof DefinitionInterface) {
return $this->converter->convert($decoratedServiceName, $callable);
}
Expand Down

0 comments on commit 275fc35

Please sign in to comment.