8000 [DependencyInjection] replace alias in factory services by xabbuh · Pull Request #17867 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] replace alias in factory services #17867

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

Merged
merged 1 commit into from
Feb 23, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ private function updateReferences($container, $currentId, $newId)
$definition->setProperties(
$this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
);

$definition->setFactoryService($this->updateFactoryServiceReference($definition->getFactoryService(), $currentId, $newId));
}
}

Expand Down Expand Up @@ -122,4 +124,13 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId)

return $arguments;
}

private function updateFactoryServiceReference($factoryService, $currentId, $newId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why introducing a new method if it is as short and only used one time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now, the 2.7 version has more code, so looks fine to me as it will ease merging.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we can indeed inline this for the 2.3 fix. I have no hard feelings about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it like this.

{
if (null === $factoryService) {
return;
}

return $currentId === $factoryService ? $newId : $currentId;
}
}
Original file line number Diff line number Diff line change
7638 Expand Up @@ -21,7 +21,9 @@ public function testProcess()
{
$container = new ContainerBuilder();

$container->register('a', '\stdClass');
$aDefinition = $container->register('a', '\stdClass');
$aDefinition->setFactoryService('b');
$aDefinition->setFactoryMethod('createA');

$bDefinition = new Definition('\stdClass');
$bDefinition->setPublic(false);
Expand All @@ -39,6 +41,7 @@ public function testProcess()
$container->has('b_alias') && !$container->hasAlias('b_alias'),
'->process() replaces alias to actual.'
);
$this->assertSame('b_alias', $aDefinition->getFactoryService());
}

/**
Expand Down
0