Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Allow service subscribers to return SubscribedService[] #47101

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
Aug 19, 2022

Conversation

kbond
Copy link
Member

@kbond kbond commented Jul 28, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets n/a
License MIT
Doc PR todo

This allows ServiceSubscriberInterface::getSubscribedServices() to return SubscribedService[] which now has the ability to add DI attribute objects (ie Target).

public static function getSubscribedServices(): array
{
    return [
        new SubscribedService('logger', Psr\Log\LoggerInterface::class),
        new SubscribedService(type: Psr\Log\LoggerInterface::class, nullable: true),
        new SubscribedService('http_client', HttpClientInterface::class, attributes: new Target('githubApi'))),
    ];
}

When using the ServiceSubscriberTrait, the SubscribedService attribute can add attributes as well:

#[SubscribedService(attributes: new Target('githubApi'))]
private function httpClient(): ?HttpClientInterface
{
    return $this->container->get(__METHOD__);
}

TODO:

  • Implementation
  • Tests
  • Changelog

@carsonbot carsonbot added this to the 6.2 milestone Jul 28, 2022
@carsonbot carsonbot changed the title [WIP][DI] Allow ServiceSubscriberInterface::getSubscribedServices() to return SubscribedService[] [DependencyInjection] [WIP] Allow ServiceSubscriberInterface::getSubscribedServices() to return SubscribedService[] Jul 28, 2022
@kbond kbond changed the title [DependencyInjection] [WIP] Allow ServiceSubscriberInterface::getSubscribedServices() to return SubscribedService[] [DependencyInjection] [WIP] Allow service subscribers to return SubscribedService[] Jul 28, 2022
@kbond kbond force-pushed the service-subscriber-improvements branch 3 times, most recently from dfdeb74 to 263acdd Compare July 28, 2022 16:51
@nicolas-grekas
Copy link
Member

I like it :) Let's see how DI can leverage that for Autowiring now.

@kbond kbond force-pushed the service-subscriber-improvements branch 2 times, most recently from 11073d1 to 29ab4b0 Compare August 16, 2022 16:02
@kbond kbond requested a review from dunglas as a code owner August 16, 2022 16:02
@kbond kbond force-pushed the service-subscriber-improvements branch from 29ab4b0 to 0fb543f Compare August 16, 2022 16:03
@kbond kbond force-pushed the service-subscriber-improvements branch 2 times, most recently from 25882d6 to aa868d8 Compare August 16, 2022 16:21
@kbond kbond force-pushed the service-subscriber-improvements branch from aa868d8 to c90f7f3 Compare August 16, 2022 19:12
@kbond kbond changed the title [DependencyInjection] [WIP] Allow service subscribers to return SubscribedService[] [DependencyInjection] Allow service subscribers to return SubscribedService[] Aug 16, 2022
@kbond kbond force-pushed the service-subscriber-improvements branch 3 times, most recently from d921b76 to 2babe71 Compare August 16, 2022 20:38
@kbond kbond force-pushed the service-subscriber-improvements branch from 2babe71 to 8ed139e Compare August 17, 2022 14:04
@nicolas-grekas nicolas-grekas force-pushed the service-subscriber-improvements branch from 6a125e3 to 7785a60 Compare August 18, 2022 07:49
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

(I made some changes, see 2nd commit)

@fabpot fabpot force-pushed the service-subscriber-improvements branch from 7785a60 to 049f15e Compare August 19, 2022 13:41
@fabpot
Copy link
Member

fabpot commented Aug 19, 2022

Thank you @kbond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants