Skip to content

Commit 19b0d44

Browse files
committed
feature #21164 [HttpKernel] Added the SessionValueResolver (iltar)
This PR was merged into the 3.3-dev branch. Discussion ---------- [HttpKernel] Added the SessionValueResolver | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21159 | License | MIT | Doc PR | (soon) This feature adds the `SessionValueResolver`. That means that you no longer have to rely on injecting a `SessionInterface` implementation via the constructor or getting this implementation from the `Request`. Regardless of method, it does not know about the `getFlashBag()`. By adding the `Session` to the action arguments, you can now type-hint against the implementation rather than interface, which contains the `getFlashBag()`, making it accessible rather than using duck-typing. _It should also feel less like injecting a service into the constructor which has a state or getting a service from the request._ **Old Situation** ```php class Controller { public function __construct(SessionInterface $session) { /* ... */ } public function fooAction(Request $request) { $this->get('session')->get(...); $request->getSession()->get(...); $this->session->get(...) // duck-typing $this->get('session')->getFlashBag(); $request->getSession()->getFlashBag(); $this->session->getFlashBag(); $this->addFlash(...); } } ``` **New Situation** _- The controller shortcut for flashbag could in theory be removed now_ ```php class Controller { public function fooAction(Session $session) { $session->get(...); $session->getFlashBag(); } } ``` Commits ------- b4464dcea1 Added the SessionValueResolver
2 parents cac366c + 6fb06c8 commit 19b0d44

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Resources/config/web.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<tag name="controller.argument_value_resolver" priority="50" />
3333
</service>
3434

35+
<service id="argument_resolver.session" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver\SessionValueResolver" public="false">
36+
<tag name="controller.argument_value_resolver" priority="50" />
37+
</service>
38+
3539
<service id="argument_resolver.default" class="Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver" public="false">
3640
<tag name="controller.argument_value_resolver" priority="-100" />
3741
</service>

0 commit comments

Comments
 (0)