Skip to content

[RFC] ArgumentValueResolver for the Session (or Flashbag) #21159

Closed
@linaori

Description

@linaori
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 SessionInterface is better than Session, but no getFlashBag() available.
  • You can get the Session from the Request, but officially this is a SessionInterface, so no getFlashBag().
  • 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:

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureHttpKernelRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions