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

Skip to content
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
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