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] Document ServiceSubscriberTrait#9809

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

Merged

Conversation

@kbond
Copy link
Member

Documentation forsymfony/symfony#27077

@kbondkbond changed the titleDocument ServiceSubscriberTrait[DependencyInjection] Document ServiceSubscriberTraitMay 23, 2018
@javiereguiluzjaviereguiluz added DependencyInjection Waiting Code MergeDocs for features pending to be merged labelsMay 23, 2018
@javiereguiluzjaviereguiluz modified the milestones:4.0,4.2May 23, 2018
@nicolas-grekas
Copy link
Member

What about adding a sentence to tell why this is nice? (Autocompletion mostly isn't it?)

provided that takes the class name and method name as arguments::

// src/AppBundle/MyService.php
namespace AppBundle;
Copy link
Member

Choose a reason for hiding this comment

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

bundle-less up to 4.0, should be:

// src/MyService.phpnamespaceApp;

@kbondkbondforce-pushed theservice-subscriber-trait branch 2 times, most recently from2b9e556 to0de578bCompareMay 31, 2018 13:17
@kbondkbondforce-pushed theservice-subscriber-trait branch from0de578b tob0ac3a4CompareMay 31, 2018 13:29
@kbond
Copy link
MemberAuthor

I added an example showing how to create composable traits and a note about not using__METHOD__ in this case.

symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull requestJun 4, 2018
This PR was squashed before being merged into the 4.2-dev branch (closes #27077).Discussion----------[DependencyInjection] add ServiceSubscriberTrait| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | #23898| License       | MIT| Doc PR        |symfony/symfony-docs#9809This allows you to easily configure Service Subscribers with the following convention:```phpclass MyService implements ServiceSubscriberInterface{    use ServiceSubscriberTrait;    public function doSomething()    {        // $this->router() ...    }    private function router(): RouterInterface    {        return $this->container->get(__METHOD__);    }}```This also allows you to create helper traits like `RouterAware`, `LoggerAware` etc... and compose your services with them (*not* using `__METHOD__` in traits because it doesn't behave as expected.).```phptrait LoggerAware{    private function logger(): LoggerInterface    {        return $this->container->get(__CLASS__.'::'.__FUNCTION__);    }}``````phptrait RouterAware{    private function router(): RouterInterface    {        return $this->container->get(__CLASS__.'::'.__FUNCTION__);    }}``````phpclass MyService implements ServiceSubscriberInterface{    use ServiceSubscriberTrait, LoggerAware, RouterAware;    public function doSomething()    {        // $this->router() ...        // $this->logger() ...    }}```Commits-------238e793431 [DependencyInjection] add ServiceSubscriberTrait
nicolas-grekas added a commit to symfony/symfony that referenced this pull requestJun 4, 2018
This PR was squashed before being merged into the 4.2-dev branch (closes#27077).Discussion----------[DependencyInjection] add ServiceSubscriberTrait| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#23898| License       | MIT| Doc PR        |symfony/symfony-docs#9809This allows you to easily configure Service Subscribers with the following convention:```phpclass MyService implements ServiceSubscriberInterface{    use ServiceSubscriberTrait;    public function doSomething()    {        // $this->router() ...    }    private function router(): RouterInterface    {        return $this->container->get(__METHOD__);    }}```This also allows you to create helper traits like `RouterAware`, `LoggerAware` etc... and compose your services with them (*not* using `__METHOD__` in traits because it doesn't behave as expected.).```phptrait LoggerAware{    private function logger(): LoggerInterface    {        return $this->container->get(__CLASS__.'::'.__FUNCTION__);    }}``````phptrait RouterAware{    private function router(): RouterInterface    {        return $this->container->get(__CLASS__.'::'.__FUNCTION__);    }}``````phpclass MyService implements ServiceSubscriberInterface{    use ServiceSubscriberTrait, LoggerAware, RouterAware;    public function doSomething()    {        // $this->router() ...        // $this->logger() ...    }}```Commits-------238e793 [DependencyInjection] add ServiceSubscriberTrait
@HeahDudeHeahDude removed the Waiting Code MergeDocs for features pending to be merged labelJun 10, 2018
@javiereguiluz
Copy link
Member

@kbond thanks for contributing these docs (and the original feature too). I love it because it explains things perfectly!

@javiereguiluzjaviereguiluz merged commitb0ac3a4 intosymfony:masterJun 11, 2018
javiereguiluz added a commit that referenced this pull requestJun 11, 2018
…ond)This PR was merged into the master branch.Discussion----------[DependencyInjection] Document ServiceSubscriberTraitDocumentation forsymfony/symfony#27077Commits-------b0ac3a4 document ServiceSubscriberTrait
@kbondkbond deleted the service-subscriber-trait branchJune 12, 2018 19:05
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

3 more reviewers

@ycerutoycerutoyceruto left review comments

@tgalopintgalopintgalopin approved these changes

@HeahDudeHeahDudeHeahDude approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

7 participants

@kbond@nicolas-grekas@javiereguiluz@tgalopin@yceruto@HeahDude@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp