File tree 1 file changed +5
-3
lines changed
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -121,16 +121,18 @@ The following snippet adds CSRF protection to the form factory::
121
121
122
122
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
123
123
use Symfony\Component\Form\Forms;
124
+ use Symfony\Component\HttpFoundation\RequestStack;
124
125
use Symfony\Component\HttpFoundation\Session\Session;
125
126
use Symfony\Component\Security\Csrf\CsrfTokenManager;
126
127
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
127
128
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
128
129
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);
131
133
132
134
$csrfGenerator = new UriSafeTokenGenerator();
133
- $csrfStorage = new SessionTokenStorage($session );
135
+ $csrfStorage = new SessionTokenStorage($requestStack );
134
136
$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);
135
137
136
138
$formFactory = Forms::createFormFactoryBuilder()
You can’t perform that action at this time.
0 commit comments