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

Appearance settings

[FrameworkBundle] Make Controller helpers final #24407

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
Oct 3, 2017

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

I propose to make all ControllerTrait methods final so we can add type hints.
I also propose to add ControllerTrait::has/get so that AbstractController also has the methods.
This will help move from Controller to AbstractController.

@fabpot
Copy link
Member

fabpot commented Oct 3, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit bbc52a1 into symfony:3.4 Oct 3, 2017
fabpot added a commit that referenced this pull request Oct 3, 2017
…-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle] Make Controller helpers final

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

I propose to make all ControllerTrait methods final so we can add type hints.
I also propose to add ControllerTrait::has/get so that AbstractController also has the methods.
This will help move from Controller to AbstractController.

Commits
-------

bbc52a1 [FrameworkBundle] Make Controller helpers final
@nicolas-grekas nicolas-grekas deleted the final-controller branch October 3, 2017 20:08
@ossinkine
Copy link
Contributor

@nicolas-grekas Could you please explain what is the sense of making this methods final?

@nicolas-grekas
Copy link
Member Author

@ossinkine see PR description. Why would you need to extend them?

@ossinkine
Copy link
Contributor

@nicolas-grekas PR description just says you propose to make them final but does not say why.
For example, I want to override render method in abstract controller to transparently set default parameters or set custom header to response:

abstract class MyController extends Controller
{
    public function render($view, array $parameters = [], Response $response = null)
    {
        $parameters = array_merge(['foo' => 'bar'], $parameters);

        return parent::render($view, $parameters, $response);
    }
}

So children controllers continue to use render method.

By the same logic, other methods can be overridden

@nicolas-grekas
Copy link
Member Author

@ossinkine after #24722, the method will have a new signature (type-hints, as stated in the above description), so that if your code extends the methods, it will break. That's why.

@ossinkine
Copy link
Contributor

@nicolas-grekas I understand the new signature breaks BC and I've have to fix my code. But why I can't override the methods in future when my method signature is fixed?
I will need to create one more method like renderWithDefaultParameters, right?

@TeLiXj
Copy link
Contributor

TeLiXj commented Oct 31, 2017

I'm surprised after try 3.4 beta 2 and discover this like ossinkine.
IMHO add type-hints in the future couldn't be a reason to mark this method as final. In the next version we can fix our signature to adapt to parent type-hints.

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.

8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.