Skip to content

6338 use csrfManager instead of csrfProvider #6586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions components/form/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,14 @@ that help you render the HTML widget, label and error for each field
(as well as a few other things). To configure the integration, you'll need
to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension\\FormExtension`::

use Symfony\Component\Form\Forms;
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Component\Form\Forms;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;

// the Twig file that holds all the default markup for rendering forms
// this file comes with TwigBridge
Expand All @@ -202,9 +206,17 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
)));
$formEngine = new TwigRendererEngine(array($defaultFormTheme));
$formEngine->setEnvironment($twig);

// create a Session object from the HttpFoundation component
$session = new Session();

$csrfGenerator = new UriSafeTokenGenerator();
$csrfStorage = new SessionTokenStorage($session);
Copy link
Member

@xabbuh xabbuh May 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it wasn't better to use the NativeSessionTokenStorage to not depend on the HttpFoundation component here.

Never mind, we already have this above.

$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);

// add the FormExtension to Twig
$twig->addExtension(
new FormExtension(new TwigRenderer($formEngine, $csrfProvider))
new FormExtension(new TwigRenderer($formEngine, $csrfManager))
);

// create your form factory as normal
Expand Down