Skip to content
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

[TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession() #50794

Closed
wants to merge 5 commits into from

Conversation

Dirkhuethorst
Copy link
Contributor

@Dirkhuethorst Dirkhuethorst commented Jun 27, 2023

Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface', to be in line with the return type of getSession in http-foundation/Request.php

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #50789
License MIT
Doc PR

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

It looks like you unchecked the "Allow edits from maintainer" box. That is fine, but please note that if you have multiple commits, you'll need to squash your commits into one before this can be merged. Or, you can check the "Allow edits from maintainers" box and the maintainer can squash for you.

Cheers!

Carsonbot

Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface', to be in line with the return type of getSession in http-foundation/Request.php
Change the return type of AppVariable.php getSession from 'Session' to 'FlashBagAwareSessionInterface'
@derrabus
Copy link
Member

The failing tests on the low-deps run look related.

@Nyholm
Copy link
Member

Nyholm commented Jun 27, 2023

Thank you for this PR.

I see you replaced the return type from class Session to interface FlashBagAwareSessionInterface. This is not always correct. It could be a Session that do not implement FlashBag feature.

I suggest to change it to SessionInterface

@Nyholm Nyholm changed the title [TwigBridge] Fix for GitHub ticket 50789 [TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession() Jun 27, 2023
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

The FlashBagAwareSessionInterface was introduced in symfony/http-foundation: 6.2 by #46491, and symfony/twig-bridge: 6.2 allows symfony/http-foundation: 5.4 in which the interface doesn't exit.
We usually don't update the dependencies constraints in maintenance branches except for security reasons. I don't think we should accept this change as a bugfix, it looks more like a new feature that would target the next version (6.4 ATM).

Also, Symfony\Component\HttpFoundation\Session\Session implements \IteratorAggregate and \Countable on top of FlashBagAwareSessionInterface or SessionInterface. Changing the return type to this single interface would reduce the functions that could be used in the templates.

src/Symfony/Bridge/Twig/AppVariable.php Outdated Show resolved Hide resolved
@Nyholm
Copy link
Member

Nyholm commented Jun 27, 2023

I was hesitating if this was a bugfix or not. But with @GromNaN arguments, I agree. This is a feature.

@Nyholm Nyholm added Feature and removed Bug labels Jun 27, 2023
@derrabus
Copy link
Member

I think, if we change the return type to ?SessionInterface, we can file it as a bugfix. Using a custom implementation of the SessionInterface should've worked in Symfony 5 and it stopped working because of a too narrow native return type in Symfony 6. I believe this breaking change was unintended.

Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface'
@Dirkhuethorst
Copy link
Contributor Author

I've changed the return type to SessionInterface, but now the Psalm check fails because in the AppVariable class the Flashbag of the session is accessed.

src/Symfony/Bridge/Twig/AppVariable.php:147:30: UndefinedInterfaceMethod: Method Symfony\Component\HttpFoundation\Session\SessionInterface::getFlashBag does not exist (see https://psalm.dev/181)

I am not sure how to proceed with this issue

@GromNaN
Copy link
Member

GromNaN commented Jul 17, 2023

You can return [] if $session is not an instance of FlashBagAwareSessionInterface or !method_exists($session, 'getFlashBag').

@Dirkhuethorst
Copy link
Contributor Author

You can return [] if $session is not an instance of FlashBagAwareSessionInterface.

Won't that break backwards compatibility with http-foundation 5.4 where the FlashBagAwareSessionInterface does not exist?

Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface'
Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface'
@fabpot fabpot removed this from the 6.2 milestone Jul 30, 2023
@fabpot fabpot added this to the 6.3 milestone Jul 30, 2023
@fabpot
Copy link
Member

fabpot commented Sep 10, 2023

Thank you @Dirkhuethorst.

fabpot added a commit that referenced this pull request Sep 10, 2023
…Variable::getSession() (Dirkhuethorst)

This PR was submitted for the 6.2 branch but it was squashed and merged into the 6.3 branch instead.

Discussion
----------

[TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession()

Change the return type of AppVariable.php getSession from 'Session' to 'SessionInterface', to be in line with the return type of getSession in http-foundation/Request.php

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | Fix #50789
| License       | MIT
| Doc PR        |

Commits
-------

9dafdc1 [TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession()
@fabpot
Copy link
Member

fabpot commented Sep 10, 2023

Merged, but Github didn't get the memo.

@fabpot fabpot closed this Sep 10, 2023
chalasr added a commit that referenced this pull request Sep 11, 2023
…ashes()` (derrabus)

This PR was merged into the 7.0 branch.

Discussion
----------

[TwigBridge] Remove duck typing from `AppVariable::getFlashes()`

| Q             | A
| ------------- | ---
| Branch?       | 7.0
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Follows #50794
| License       | MIT
| Doc PR        | N/A

Commits
-------

3bd4e60 [TwigBridge] Remove duck typing from AppVariable::getFlashes()
@fabpot fabpot mentioned this pull request Sep 30, 2023
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.

None yet

6 participants