Skip to content

Commit 5de7a72

Browse files
committed
[Form] Fixed a code example related to CSRF
1 parent 0047a35 commit 5de7a72

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

components/form.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,18 @@ The following snippet adds CSRF protection to the form factory::
121121

122122
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
123123
use Symfony\Component\Form\Forms;
124+
use Symfony\Component\HttpFoundation\RequestStack;
124125
use Symfony\Component\HttpFoundation\Session\Session;
125126
use Symfony\Component\Security\Csrf\CsrfTokenManager;
126127
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
127128
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
128129

129-
// creates a Session object from the HttpFoundation component
130-
$session = new Session();
130+
// creates a RequestStack object using the current request
131+
$requestStack = new RequestStack();
132+
$requestStack->push($request);
131133

132134
$csrfGenerator = new UriSafeTokenGenerator();
133-
$csrfStorage = new SessionTokenStorage($session);
135+
$csrfStorage = new SessionTokenStorage($requestStack);
134136
$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);
135137

136138
$formFactory = Forms::createFormFactoryBuilder()

0 commit comments

Comments
 (0)