-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Labels
FeatureHttpKernelRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)
Description
| Q | A |
|---|---|
| Bug report? | no |
| Feature request? | yes |
| BC Break report? | no |
| RFC? | yes |
| Symfony version | 3.3 |
The getFlashBag() Issue
One constantly recurring issue, is the missing method of getFlashBag() in the SessionInterface. This leads to being unable to get the flash bag in a clean way.
- Injection the
SessionInterfaceis better thanSession, but nogetFlashBag()available. - You can get the
Sessionfrom theRequest, but officially this is aSessionInterface, so nogetFlashBag(). - You can inject the
FlashBagInterface, but this service is private and in theory shouldn't be used like this afaik.
Just to name a few issues and pull requests:
- adding getFlashBag to SessionInterface in later 3.1.x, or 3.2.x ? #20258 adding getFlashBag to SessionInterface in later 3.1.x, or 3.2.x ?
- [Session] Changed session.flash_bag service to publicly available #11957 [Session] Changed session.flash_bag service to publicly available
- [Session] "getFlashBag" interfacing issue #11279 [Session] "getFlashBag" interfacing issue
- Update SessionInterface.php #11035 Update SessionInterface.php
- Update Request.php #11032 Update Request.php
- getFlashBag missing in SessionInterface #10036 getFlashBag missing in SessionInterface
- [HttpFoundation] [Session] SessionInterface is missing "getFlashBag" method: correct? #5568 [HttpFoundation] [Session] SessionInterface is missing "getFlashBag" method: correct?
Possible Solution
There are 2 solutions that might be worth looking into now that we have ArgumentValueResolvers. Either the FlashBag or Session could be requested via the action.
class fooController
{
public function barAction(Session $session)
{
$flashBag = $session->getFlashBag(); // this is now valid
}
public function bazAction(FlashBag $session)
{
// still need to do $request->getSession(); sadly
}
}Personally I'm leaning towards the Session type-hint. I think this would be a nice addition as the session has no real business in the Request object, but interface wise still is stateful (hence the no-constructor injection).
jvasseur, yannickl88, chalasr, HeahDude, tyx and 1 more
Metadata
Metadata
Assignees
Labels
FeatureHttpKernelRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)