Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing weird infinite loop issue #12

Merged
merged 1 commit into from Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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