Sfoglia il codice sorgente

[Form] Move CSRF options from types to the CSRF extension

Victor Berchet 14 anni fa
parent
commit
ba31b5acc5

+ 0 - 1
src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

@@ -121,7 +121,6 @@ class ChoiceType extends AbstractType
             'choice_list'       => null,
             'choices'           => array(),
             'preferred_choices' => array(),
-            'csrf_protection'   => false,
             'empty_data'        => $multiple || $expanded ? array() : '',
             'error_bubbling'    => false,
         );

+ 0 - 1
src/Symfony/Component/Form/Extension/Core/Type/DateType.php

@@ -123,7 +123,6 @@ class DateType extends AbstractType
             'format'            => \IntlDateFormatter::MEDIUM,
             'data_timezone'     => null,
             'user_timezone'     => null,
-            'csrf_protection'   => false,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
             'by_reference'      => false,

+ 0 - 1
src/Symfony/Component/Form/Extension/Core/Type/FileType.php

@@ -58,7 +58,6 @@ class FileType extends AbstractType
     {
         return array(
             'type'              => 'string',
-            'csrf_protection'   => false,
         );
     }
 

+ 0 - 1
src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php

@@ -36,7 +36,6 @@ class RepeatedType extends AbstractType
             'options'           => array(),
             'first_name'        => 'first',
             'second_name'       => 'second',
-            'csrf_protection'   => false,
             'error_bubbling'    => false,
         );
     }

+ 0 - 1
src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

@@ -97,7 +97,6 @@ class TimeType extends AbstractType
             'pattern'           => null,
             'data_timezone'     => null,
             'user_timezone'     => null,
-            'csrf_protection'   => false,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
             'by_reference'      => false,

+ 5 - 0
src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php

@@ -34,7 +34,12 @@ class CsrfExtension extends AbstractExtension
     protected function loadTypeExtensions()
     {
         return array(
+            new Type\ChoiceTypeCsrfExtension(),
+            new Type\DateTypeCsrfExtension(),
+            new Type\FileTypeCsrfExtension(),
             new Type\FormTypeCsrfExtension(),
+            new Type\RepeatedTypeCsrfExtension(),
+            new Type\TimeTypeCsrfExtension(),
         );
     }
 }

+ 27 - 0
src/Symfony/Component/Form/Extension/Csrf/Type/ChoiceTypeCsrfExtension.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Csrf\Type;
+
+use Symfony\Component\Form\AbstractTypeExtension;
+
+class ChoiceTypeCsrfExtension extends AbstractTypeExtension
+{
+    public function getDefaultOptions(array $options)
+    {
+        return array('csrf_protection' => false);
+    }
+
+    public function getExtendedType()
+    {
+        return 'choice';
+    }
+}

+ 27 - 0
src/Symfony/Component/Form/Extension/Csrf/Type/DateTypeCsrfExtension.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Csrf\Type;
+
+use Symfony\Component\Form\AbstractTypeExtension;
+
+class DateTypeCsrfExtension extends AbstractTypeExtension
+{
+    public function getDefaultOptions(array $options)
+    {
+        return array('csrf_protection' => false);
+    }
+
+    public function getExtendedType()
+    {
+        return 'date';
+    }
+}

+ 27 - 0
src/Symfony/Component/Form/Extension/Csrf/Type/FileTypeCsrfExtension.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Csrf\Type;
+
+use Symfony\Component\Form\AbstractTypeExtension;
+
+class FileTypeCsrfExtension extends AbstractTypeExtension
+{
+    public function getDefaultOptions(array $options)
+    {
+        return array('csrf_protection' => false);
+    }
+
+    public function getExtendedType()
+    {
+        return 'file';
+    }
+}

+ 27 - 0
src/Symfony/Component/Form/Extension/Csrf/Type/RepeatedTypeCsrfExtension.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Csrf\Type;
+
+use Symfony\Component\Form\AbstractTypeExtension;
+
+class RepeatedTypeCsrfExtension extends AbstractTypeExtension
+{
+    public function getDefaultOptions(array $options)
+    {
+        return array('csrf_protection' => false);
+    }
+
+    public function getExtendedType()
+    {
+        return 'repeated';
+    }
+}

+ 27 - 0
src/Symfony/Component/Form/Extension/Csrf/Type/TimeTypeCsrfExtension.php

@@ -0,0 +1,27 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Csrf\Type;
+
+use Symfony\Component\Form\AbstractTypeExtension;
+
+class TimeTypeCsrfExtension extends AbstractTypeExtension
+{
+    public function getDefaultOptions(array $options)
+    {
+        return array('csrf_protection' => false);
+    }
+
+    public function getExtendedType()
+    {
+        return 'time';
+    }
+}