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

[FrameworkBundle] Return the invokable service if its name is the class name#18289

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
dunglas wants to merge2 commits intosymfony:masterfromdunglas:invokable_service

Conversation

@dunglas
Copy link
Member

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/a

if a service is invokable and has the same name than its class name, the controller resolver of FrameworkBundle doesn't retrieve the service and tries to construct a new instance of the class instead.

This is a very rare edge case, but this fix is useful fordunglas/DunglasActionBundle#36: referencing auto-registered controllers following the ADR style in YAML and XML routing files will be more intuitive.

Currently:defaults: { _controller: 'Your\Action\FQN:__invoke' }, after this fix:defaults: { _controller: 'Your\Action\FQN' }.

This PR also fix a currently useless test.

hason, GuilhemN, and chalasr reacted with thumbs up emoji
@dunglasdunglas changed the title[FrameworkBundle] Return the service if it's name is the class name[FrameworkBundle] Return the service if its name is the class nameMar 24, 2016
@dunglasdunglas changed the title[FrameworkBundle] Return the service if its name is the class name[FrameworkBundle] Return the invokable service if its name is the class nameMar 24, 2016
$controller =$this->container->get($class);
}else {
$controller =parent::instantiateController($class);
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should make that check increateController() where we also retrieve the controller from the container when theservice_name:method_name notation is used:https://github.com/dunglas/symfony/blob/invokable_service/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php#L56-L71

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is not possible without a larger refactoring becausecreateController is never called in this case:https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php#L70

An alternative is to refactor the wholegetController method but it's risky and intrusive. It's why I've chosen this simple fix.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, yeah, it's probably not worth to make such big changes.

@xabbuh
Copy link
Member

👍 (with@stof's comment applied)

{
$controller =parent::instantiateController($class);
if ($this->container->has($class)) {
$controller =$this->container->get($class);
Copy link
Member

Choose a reason for hiding this comment

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

the simple way to fix my comment about ContainerAwareInterface is to return directly here

@stof
Copy link
Member

Status: needs work

@dunglas
Copy link
MemberAuthor

@stof fixed

Status: needs review

@fabpot
Copy link
Member

Thank you@dunglas.

@dunglasdunglas deleted the invokable_service branchMarch 25, 2016 17:28
@dunglas
Copy link
MemberAuthor

I've unintentionally opened this PR against master, but it should be merged in 2.7 (as described in the PR header).@fabpot is it possible to merge it back in other branches?

fabpot added a commit that referenced this pull requestApr 1, 2016
… name is the class name (dunglas)This PR was merged into the 2.7 branch.Discussion----------[FrameworkBundle][2.7] Return the invokable service if its name is the class name| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/A| License       | MIT| Doc PR        | n/aBackport#18289 to 2.7 as this is a bug fix.Commits-------5c87d76 [FrameworkBundle] Return the invokable service if its name is the class name
@fabpotfabpot mentioned this pull requestMay 13, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@dunglas@xabbuh@stof@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp