Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] [POC] allowServiceSubscriberTrait 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@kbond
Copy link
Member

@kbondkbond commentedJun 7, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?no
Ticketsn/a
LicenseMIT
Doc PRtodo

This comes from a slack discussion with@nicolas-grekas.

This PR allowsServiceSubscriberInterface services using theServiceSubscriber trait toautowire properties marked with theSubscribedService attribute.

class MyServiceimplements ServiceSubscriberInterface{use ServiceSubscriberTrait;    #[SubscribedService]privateAnotherService$anotherService;publicfunctionsomeMethod()    {$this->anotherService->something();// lazily initializes the property the first time it's accessed    }}

TODO:

  • nullable properties?
  • more tests
  • changelog

nicolas-grekas reacted with heart emojiHypeMC reacted with rocket emoji
@carsonbotcarsonbot added this to the6.2 milestoneJun 7, 2022
@carsonbotcarsonbot changed the title[POC][DI] allowServiceSubscriberTrait to autowire properties[DependencyInjection] [POC] allowServiceSubscriberTrait to autowire propertiesJun 7, 2022
@kbondkbondforce-pushed theservice-subscriber-properties branch 2 times, most recently from187925e todeeb6fdCompareJune 7, 2022 22:01
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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 :)

$this->container =$container;

if ($containerinstanceof ServiceProviderInterface) {
// TODO: what if this isn't an instance of ServiceProviderInterface?

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

Copy link
MemberAuthor

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()?

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?

Copy link
MemberAuthor

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?

@kbondkbondforce-pushed theservice-subscriber-properties branch 3 times, most recently from56b0944 to573b694CompareAugust 29, 2022 13:31
@kbondkbondforce-pushed theservice-subscriber-properties branch from573b694 toe2fb640CompareAugust 29, 2022 13:35
@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedSep 13, 2023
edited
Loading

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
Thanks for giving the idea a try!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

3 participants

@kbond@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp