Skip to content

Commit 2d73281

Browse files
committed
[FrameworkBundle][TwigBridge] Fix BC break from strong dependency on CSRF token storage
1 parent b2e4c10 commit 2d73281

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

Extension/CsrfExtension.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,22 @@
1111

1212
namespace Symfony\Bridge\Twig\Extension;
1313

14-
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
1514
use Twig\Extension\AbstractExtension;
1615
use Twig\TwigFunction;
1716

1817
/**
1918
* @author Christian Flothmann <[email protected]>
19+
* @author Titouan Galopin <[email protected]>
2020
*/
2121
class CsrfExtension extends AbstractExtension
2222
{
23-
private $csrfTokenManager;
24-
25-
public function __construct(CsrfTokenManagerInterface $csrfTokenManager)
26-
{
27-
$this->csrfTokenManager = $csrfTokenManager;
28-
}
29-
3023
/**
3124
* {@inheritdoc}
3225
*/
3326
public function getFunctions(): array
3427
{
3528
return array(
36-
new TwigFunction('csrf_token', array($this, 'getCsrfToken')),
29+
new TwigFunction('csrf_token', array(CsrfRuntime::class, 'getCsrfToken')),
3730
);
3831
}
39-
40-
public function getCsrfToken(string $tokenId): string
41-
{
42-
return $this->csrfTokenManager->getToken($tokenId)->getValue();
43-
}
4432
}

Extension/CsrfRuntime.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Twig\Extension;
13+
14+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
15+
16+
/**
17+
* @author Christian Flothmann <[email protected]>
18+
* @author Titouan Galopin <[email protected]>
19+
*/
20+
class CsrfRuntime
21+
{
22+
private $csrfTokenManager;
23+
24+
public function __construct(CsrfTokenManagerInterface $csrfTokenManager)
25+
{
26+
$this->csrfTokenManager = $csrfTokenManager;
27+
}
28+
29+
public function getCsrfToken(string $tokenId): string
30+
{
31+
return $this->csrfTokenManager->getToken($tokenId)->getValue();
32+
}
33+
}

0 commit comments

Comments
 (0)