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

Skip to content

[FrameworkBundle] Expose the AbstractController's container to its subclasses #23180

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
Jun 15, 2017
Merged

[FrameworkBundle] Expose the AbstractController's container to its subclasses #23180

merged 1 commit into from
Jun 15, 2017

Conversation

BPScott
Copy link
Contributor

@BPScott BPScott commented Jun 14, 2017

Q A
Branch? 3.3
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

This is useful if an application provides their own base Controller that
references items in the container. It also makes it simpler for that
base controller to add additional optional dependencies by only overriding
getSubscribedServices instead of having to reimplement setContainer and
use ControllerTrait.

@BPScott BPScott changed the title Expose the AbstractController's container to its subclasses [FrameworkBundle] Expose the AbstractController's container to its subclasses Jun 14, 2017
@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Jun 15, 2017
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.

Even if we usually don't encourage protected properties, I'm 👍 here:
extending AbstractController::getSubscribedServices() is a legitimate use case that's really missing in 3.3.

Extending setContainer or using ControllerTrait as an alternative is unsupported because both are internal.

Using service argument injection doesn't fit the really-lazy use case (when eg. you first have some authorization check in an action before using a service.)

We could also add get/has methods. Not sure if that'd be better thought. Hence my vote.

@@ -35,7 +35,7 @@
{
use ControllerTrait;

private $container;
protected $container;
Copy link
Member

Choose a reason for hiding this comment

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

Pleas add a docblock comment to help IDE with the type of this.

Useful if an application provides their own base Controller that
references items in the container. It also makes it simpler for that
base controller to add additional optional dependencies by only overriding
getSubscribedServices instead of having to reimplement setContainer and
use ControllerTrait.
@BPScott
Copy link
Contributor Author

BPScott commented Jun 15, 2017

Added the docblock.

Adding the get/has methods would also solve my use-case. Am happy to add those too or in place of changing the visibility if desired. Controller does both (protected $container comes via ContainerAwareTrait).

Laziness is exactly the use case I'm aiming for. This is what I'm trying to do - my base controller will contain various utility methods, and I don't want the overhead of creating the services used by those utilities until I know I need them.

@fabpot
Copy link
Member

fabpot commented Jun 15, 2017

Thank you @BPScott.

@fabpot fabpot merged commit ee17131 into symfony:3.3 Jun 15, 2017
fabpot added a commit that referenced this pull request Jun 15, 2017
…r to its subclasses (BPScott)

This PR was merged into the 3.3 branch.

Discussion
----------

[FrameworkBundle] Expose the AbstractController's container to its subclasses

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

This is useful if an application provides their own base Controller that
references items in the container. It also makes it simpler for that
base controller to add additional optional dependencies by only overriding
getSubscribedServices instead of having to reimplement setContainer and
use ControllerTrait.

Commits
-------

ee17131 Expose the AbstractController's container to its subclasses
@BPScott BPScott deleted the expose-abstractcontroller-container branch June 15, 2017 15:46
@fabpot fabpot mentioned this pull request Jul 4, 2017
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.

4 participants