-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] [POC] allow ServiceSubscriberTrait
to autowire properties
#46617
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
Conversation
ServiceSubscriberTrait
to autowire propertiesServiceSubscriberTrait
to autowire properties
187925e
to
deeb6fd
Compare
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.
Many interesting challenges here, that's very much R&D :)
@@ -67,10 +99,28 @@ public function setContainer(ContainerInterface $container): ?ContainerInterface | |||
{ | |||
$this->container = $container; | |||
|
|||
if ($container instanceof ServiceProviderInterface) { | |||
// TODO: what if this isn't an instance of ServiceProviderInterface? |
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 should use reflection instead of relying on ServiceProviderInterface and unset only the properties that have the attribute
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 would be at runtime, that ok?
{ | ||
// TODO: ensure cannot be called from outside of the scope of the object? | ||
// TODO: what if class has a child/parent that allows this? | ||
// TODO: call parent::__get()? |
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.
LazyGhostObjectTrait to the rescue somehow?
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'm not very familiar with this trait. How could it be used?
src/Symfony/Contracts/Tests/Service/ServiceSubscriberTraitTest.php
Outdated
Show resolved
Hide resolved
56b0944
to
573b694
Compare
573b694
to
e2fb640
Compare
I'm closing here because while this is an interesting topic, I feel like this would bring too much complexity in comparison to other approaches based on Autowire attributes, especially since #51392 |
This comes from a slack discussion with @nicolas-grekas.
This PR allows
ServiceSubscriberInterface
services using theServiceSubscriber
trait to autowire properties marked with theSubscribedService
attribute.TODO: