Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #27454 [FrameworkBundle][TwigBridge] Fix BC break from strong dep…
…endency on CSRF token storage (tgalopin) This PR was merged into the 4.1 branch. Discussion ---------- [FrameworkBundle][TwigBridge] Fix BC break from strong dependency on CSRF token storage | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - The PR #25197 introduced the `csrf_token` function in Twig. This extension relies on `CsrfTokenManagerInterface`, which itself relies on the session. In some contexts such as when sessions are stored in Redis and we try to warmup the cache in CLI without Redis available, this makes the process fails. This PR fixes this by using a Twig runtime instead of a direct extension to avoid a strong dependency on `CsrfTokenManagerInterface`. Commits ------- 68994a6 [FrameworkBundle][TwigBridge] Fix BC break from strong dependency on CSRF token storage
- Loading branch information
Showing
3 changed files
with
40 additions
and
15 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
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Twig\Extension; | ||
|
||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; | ||
|
||
/** | ||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de> | ||
* @author Titouan Galopin <galopintitouan@gmail.com> | ||
*/ | ||
class CsrfRuntime | ||
{ | ||
private $csrfTokenManager; | ||
|
||
public function __construct(CsrfTokenManagerInterface $csrfTokenManager) | ||
{ | ||
$this->csrfTokenManager = $csrfTokenManager; | ||
} | ||
|
||
public function getCsrfToken(string $tokenId): string | ||
{ | ||
return $this->csrfTokenManager->getToken($tokenId)->getValue(); | ||
} | ||
} |
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