-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Allow auto-configured method calls. #24996
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
[DI] Allow auto-configured method calls. #24996
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for starting this work
@@ -63,7 +60,10 @@ private function processDefinition(ContainerBuilder $container, $id, Definition | |||
|
|||
$definition->setInstanceofConditionals(array()); | |||
$parent = $shared = null; | |||
$instanceofTags = array(); | |||
$instanceof = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another variable instead of an array would be better I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in b61d981
@@ -77,11 +77,13 @@ private function processDefinition(ContainerBuilder $container, $id, Definition | |||
foreach ($instanceofDefs as $key => $instanceofDef) { | |||
/** @var ChildDefinition $instanceofDef */ | |||
$instanceofDef = clone $instanceofDef; | |||
$instanceofDef->setAbstract(true)->setParent($parent ?: 'abstract.instanceof.'.$id); | |||
$parent = 'instanceof.'.$interface.'.'.$key.'.'.$id; | |||
$instanceofDef->setAbstract(true)->setParent($parent ?: "abstract.instanceof.$id"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert these changes, they are unrelated (did fabbot suggest them? if yes, please ignore it :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fabbot, just did it because string interpolation run faster in PHP7, but I can revert it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please do, that's unrelated
@@ -91,23 +93,24 @@ private function processDefinition(ContainerBuilder $container, $id, Definition | |||
|
|||
if ($parent) { | |||
$bindings = $definition->getBindings(); | |||
$abstract = $container->setDefinition('abstract.instanceof.'.$id, $definition); | |||
$abstract = $container->setDefinition("abstract.instanceof.$id", $definition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -60,7 +60,6 @@ public function testProcessInheritance() | |||
(new ResolveChildDefinitionsPass())->process($container); | |||
|
|||
$expected = array( | |||
array('foo', array('bar')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing an existing test case is always suspicious,
is this really legitimate? won't it introduce BC breaks?
we need to answer these questions carefully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change came from the fact that if a definition has already a method call (line 125: if (!$definition->hasMethodCall($call[0])) {
), I do not add it again to avoid call a setter multiple times. Hard to say if we should deduplicate or not method calls...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard to say if we should deduplicate or not method calls
we should not:
$twig->addExtension($ext1);
$twig->addExtension($ext1);
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed method filtering. Method order has changed, but seems normal since we now allow calls inheritance and they are added at the end of the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test order fixed in da6d7e4
@@ -20,7 +20,6 @@ services: | |||
# calls from instanceof are kept, but this comes later | |||
calls: | |||
# first call is from instanceof | |||
- [setSunshine, [bright]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above: changing an existing test case needs to be doubly confirmed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas fixed in da6d7e4
- [enableSummer, [true]] | ||
- [setSunshine, [warm]] | ||
# Call from instanceof |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the order of calls changes, that means a BC break
44b706c
to
9d0bd6e
Compare
Methods calls are now in the right order, error on Travis is unrelated (error with RedisAdapter). |
@GaryPEGEOT Why did you close here? |
Continued in #26768 |
Lost some of my commits, so openned a new one |
Allow to auto-configure method calls like: