-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Adding warning about depending on concrete implementation of Session #13884
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
Adding warning about depending on concrete implementation of Session #13884
Conversation
Oleg, your proposed content is perfectly fine technically speaking. Thanks for that! However, there's a problem. This @symfony/team-symfony-docs what do you think? Thanks! |
@javiereguiluz Any updates on this? |
My personal opinion would be that the current state of this doc is probably the best.. I agree that it's not good to rely on an implementation, but sadly for session you sort of have to (as you also explained in the note). This is one of the few bad designs left in Symfony 5 and there are some ideas to fix it (See e.g. symfony/symfony#10557 ). However, until it's fixed, relying on the |
@@ -534,6 +534,14 @@ After processing the request, the controller sets a flash message in the session | |||
and then redirects. The message key (``notice`` in this example) can be anything: | |||
you'll use this key to retrieve the message. | |||
|
|||
.. warning:: | |||
|
|||
If you want avoid depending on concrete implementation of `Session` and rely on :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want avoid depending on concrete implementation of `Session` and rely on :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`: | |
If you want avoid depending on concrete implementation of ``Session`` and rely on :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`: |
.. warning:: | ||
|
||
If you want avoid depending on concrete implementation of `Session` and rely on :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`: | ||
you will find your self in a situation that `getFlashBag` is not declared in an interface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will find your self in a situation that `getFlashBag` is not declared in an interface. | |
you will find your self in a situation that ``getFlashBag`` is not declared in an interface. |
If you want avoid depending on concrete implementation of `Session` and rely on :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`: | ||
you will find your self in a situation that `getFlashBag` is not declared in an interface. | ||
In order fix this "problem" you must inject `FlashBagInterface`/`session.flash_bag` and relay on `FlashBagInterface` | ||
instead of `Session` for access to "Flash Messages" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of `Session` for access to "Flash Messages" | |
instead of ``Session`` for access to "Flash Messages" |
|
||
If you want avoid depending on concrete implementation of `Session` and rely on :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`: | ||
you will find your self in a situation that `getFlashBag` is not declared in an interface. | ||
In order fix this "problem" you must inject `FlashBagInterface`/`session.flash_bag` and relay on `FlashBagInterface` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order fix this "problem" you must inject `FlashBagInterface`/`session.flash_bag` and relay on `FlashBagInterface` | |
In order fix this "problem" you must inject ``FlashBagInterface``/``session.flash_bag`` and relay on ``FlashBagInterface`` |
I'm closing this because of the reasons given above. Moreover, the In any case, thanks for this proposal and for taking care of reviewing/improving docs. Thanks! |
Relying on the concrete implementation of any class goes against best practices.
So if the application relies on
SessionInterface
user will find themself in a situation when "getFlashBag" is not declared in aSessionInterface
exactly for this case I've added a warning about usingSessionInterface
andFlashBagInterface
Example of an issue when concrete Session class is used sonata-project/SonataUserBundle#1174
Example of an issue when SessionInterface is not enough: sonata-project/SonataUserBundle#1184