Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created new FlashBagProvider for accessing flash message bag
- FlashBagProvider is not wired in contructor anymore because it had side effects (session was started when the container was built) - see symfony/symfony#36063
- Loading branch information
1 parent
42baad8
commit 808845f
Showing
3 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/framework/src/Component/FlashMessage/FlashBagProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Component\FlashMessage; | ||
|
||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; | ||
|
||
class FlashBagProvider | ||
{ | ||
/** | ||
* @var \Symfony\Component\HttpFoundation\RequestStack | ||
*/ | ||
protected RequestStack $requestStack; | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack | ||
*/ | ||
public function __construct(RequestStack $requestStack) | ||
{ | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
/** | ||
* @return \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface|null | ||
*/ | ||
public function getFlashBag(): ?FlashBagInterface | ||
{ | ||
$currentRequest = $this->requestStack->getCurrentRequest(); | ||
if ($currentRequest === null) { | ||
return null; | ||
} | ||
|
||
/** @var \Symfony\Component\HttpFoundation\Session\Session $session */ | ||
$session = $currentRequest->getSession(); | ||
|
||
return $session->getFlashBag(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters