Skip to content

Commit

Permalink
handle disaled csrf protection in the Twig FormExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Jan 23, 2012
1 parent 2a998e0 commit 3a1699a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Symfony/Bridge/Twig/Extension/FormExtension.php
Expand Up @@ -33,7 +33,7 @@ class FormExtension extends \Twig_Extension
protected $varStack;
protected $template;

public function __construct(CsrfProviderInterface $csrfProvider, array $resources = array())
public function __construct(CsrfProviderInterface $csrfProvider = null, array $resources = array())
{
$this->csrfProvider = $csrfProvider;
$this->themes = new \SplObjectStorage();
Expand Down Expand Up @@ -298,6 +298,10 @@ protected function render(FormView $view, $section, array $variables = array())
*/
public function getCsrfToken($intention)
{
if (!$this->csrfProvider instanceof CsrfProviderInterface) {
throw new \BadMethodCallException('CSRF token can only be generated if the "form.csrf_provider" service is available');
}

return $this->csrfProvider->generateCsrfToken($intention);
}

Expand Down
Expand Up @@ -202,7 +202,7 @@ public function rest(FormView $view, array $variables = array())
*/
public function csrfToken($intention)
{
if (! $this->csrfProvider instanceof CsrfProviderInterface) {
if (!$this->csrfProvider instanceof CsrfProviderInterface) {
throw new \BadMethodCallException('CSRF token can only be generated if the "form.csrf_provider" service is available');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -75,7 +75,7 @@

<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
<tag name="twig.extension" />
<argument type="service" id="form.csrf_provider" />
<argument type="service" id="form.csrf_provider" on-invalid="null" />
<argument>%twig.form.resources%</argument>
</service>

Expand Down

0 comments on commit 3a1699a

Please sign in to comment.