-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Rework config hierarchy: defaults > instanceof > service config #22356
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…child, parent definitions
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ChildDefinition; | ||
use Symfony\Component\DependencyInjection\Exception\RuntimeException; | ||
|
||
/** | ||
* Applies tags inheritance to definitions. | ||
|
@@ -31,7 +32,7 @@ protected function processValue($value, $isRoot = false) | |
$value->setInheritTags(false); | ||
|
||
if (!$this->container->has($parent = $value->getParent())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This surprised me at first - it looks like we're silencing invalid parent ids. But, you've done this simply so that the later ResolveDefinitionTemplatesPass can throw the proper exception. Maybe add a one-line comment mentioning a later pass checks for parent validity? I want to leave some breadcrumbs for the future :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, I made it throw, so that tag inheritance is made incompatible with dynamically created parents and save a few surprises (since tags would not be inherited for them, despite the field) |
||
return parent::processValue($value, $isRoot); | ||
throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent)); | ||
} | ||
|
||
$parentDef = $this->container->findDefinition($parent); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
|
||
_instanceof: | ||
Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStubParent: | ||
# should override _defaults | ||
autowire: false | ||
shared: false | ||
tags: | ||
- { name: foo_tag } | ||
calls: | ||
- [setSunshine, [bright]] | ||
|
||
# a second instanceof that will be applied | ||
Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub: | ||
tags: | ||
- { name: bar_tag } | ||
|
||
service_simple: | ||
class: Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub | ||
tags: | ||
- { name: foo_tag, priority: 100 } | ||
# calls from instanceof are kept, but this comes later | ||
calls: | ||
- [enableSummer, [true]] | ||
- [setSunshine, [warm]] | ||
|
||
service_override_instanceof: | ||
class: Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub | ||
# override instanceof | ||
autowire: true | ||
|
||
parent_service: | ||
abstract: true | ||
lazy: true | ||
|
||
# instanceof will not be applied to this | ||
child_service: | ||
class: Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub | ||
parent: parent_service | ||
|
||
parent_service_with_class: | ||
abstract: true | ||
class: Symfony\Component\DependencyInjection\Tests\Compiler\IntegrationTestStub | ||
|
||
child_service_with_parent_instanceof: | ||
parent: parent_service_with_class | ||
shared: true |
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.
We could add a one-line comment here:
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.
comment added