..).
Author: Fabien Potencier (fabien.potencier@symfony-project.com)
 /**
  * Boots the Bundle.
  */
 public function boot()
 {
     if ($this->container->has('error_handler')) {
         $this->container->get('error_handler');
     }
     if ($this->container->hasParameter('csrf_secret')) {
         FormConfiguration::setDefaultCsrfSecret($this->container->getParameter('csrf_secret'));
         FormConfiguration::enableDefaultCsrfProtection();
     }
 }
示例#2
0
 public function testLocalesAreSelectable()
 {
     FormConfiguration::setDefaultLocale('de_AT');
     $field = new LocaleField('language');
     $choices = $field->getOtherChoices();
     $this->assertArrayHasKey('en', $choices);
     $this->assertEquals('Englisch', $choices['en']);
     $this->assertArrayHasKey('en_GB', $choices);
     $this->assertEquals('Englisch (Vereinigtes Königreich)', $choices['en_GB']);
     $this->assertArrayHasKey('zh_Hans_MO', $choices);
     $this->assertEquals('Chinesisch (vereinfacht, Sonderverwaltungszone Macao)', $choices['zh_Hans_MO']);
 }
示例#3
0
 public function testCountriesAreSelectable()
 {
     FormConfiguration::setDefaultLocale('de_AT');
     $field = new CountryField('country');
     $choices = $field->getOtherChoices();
     $this->assertArrayHasKey('DE', $choices);
     $this->assertEquals('Deutschland', $choices['DE']);
     $this->assertArrayHasKey('GB', $choices);
     $this->assertEquals('Vereinigtes Königreich', $choices['GB']);
     $this->assertArrayHasKey('US', $choices);
     $this->assertEquals('Vereinigte Staaten', $choices['US']);
     $this->assertArrayHasKey('FR', $choices);
     $this->assertEquals('Frankreich', $choices['FR']);
     $this->assertArrayHasKey('MY', $choices);
     $this->assertEquals('Malaysia', $choices['MY']);
 }
示例#4
0
 public function testCountriesAreSelectable()
 {
     FormConfiguration::setDefaultLocale('de_AT');
     $field = new LanguageField('language');
     $choices = $field->getOtherChoices();
     $this->assertArrayHasKey('en', $choices);
     $this->assertEquals('Englisch', $choices['en']);
     $this->assertArrayHasKey('en_GB', $choices);
     $this->assertEquals('Britisches Englisch', $choices['en_GB']);
     $this->assertArrayHasKey('en_US', $choices);
     $this->assertEquals('Amerikanisches Englisch', $choices['en_US']);
     $this->assertArrayHasKey('fr', $choices);
     $this->assertEquals('Französisch', $choices['fr']);
     $this->assertArrayHasKey('my', $choices);
     $this->assertEquals('Birmanisch', $choices['my']);
 }
 /**
  * Boots the Bundle.
  */
 public function boot()
 {
     if ($this->container->has('error_handler')) {
         $this->container->get('error_handler');
     }
     if ($this->container->hasParameter('csrf_secret')) {
         FormConfiguration::addDefaultCsrfSecret($this->container->getParameter('csrf_secret'));
         FormConfiguration::enableDefaultCsrfProtection();
     }
     $container = $this->container;
     // the session ID should always be included in the CSRF token, even
     // if default CSRF protection is not enabled
     FormConfiguration::addDefaultCsrfSecret(function () use($container) {
         // automatically starts the session when the CSRF token is
         // generated
         $container->get('session')->start();
         return $container->get('session')->getId();
     });
 }
示例#6
0
文件: Field.php 项目: spf13/symfony
 public function __construct($key, array $options = array())
 {
     $this->addOption('trim', true);
     $this->addOption('required', true);
     $this->addOption('disabled', false);
     $this->addOption('property_path', (string) $key);
     $this->addOption('value_transformer');
     $this->addOption('normalization_transformer');
     $this->key = (string) $key;
     $this->locale = FormConfiguration::getDefaultLocale();
     parent::__construct($options);
     if ($this->getOption('value_transformer')) {
         $this->setValueTransformer($this->getOption('value_transformer'));
     }
     if ($this->getOption('normalization_transformer')) {
         $this->setNormalizationTransformer($this->getOption('normalization_transformer'));
     }
     $this->normalizedData = $this->normalize($this->data);
     $this->transformedData = $this->transform($this->normalizedData);
     $this->required = $this->getOption('required');
     $this->setPropertyPath($this->getOption('property_path'));
 }
示例#7
0
文件: Form.php 项目: notbrain/symfony
 /**
  * Enables CSRF protection for this form.
  */
 public function enableCsrfProtection($csrfFieldName = null, $csrfSecret = null)
 {
     if (!$this->isCsrfProtected()) {
         if (null === $csrfFieldName) {
             $csrfFieldName = FormConfiguration::getDefaultCsrfFieldName();
         }
         if (null === $csrfSecret) {
             $csrfSecret = md5(__FILE__ . php_uname());
         }
         $field = new HiddenField($csrfFieldName, array('property_path' => null));
         $field->setData($this->generateCsrfToken($csrfSecret));
         $this->add($field);
         $this->csrfFieldName = $csrfFieldName;
         $this->csrfSecret = $csrfSecret;
     }
 }
示例#8
0
 public function testDefaultCsrfFieldNameCanBeSet()
 {
     FormConfiguration::setDefaultCsrfFieldName('foobar');
     $form = new Form('author', new Author(), $this->validator);
     $form->enableCsrfProtection();
     $this->assertEquals('foobar', $form->getCsrfFieldName());
 }
示例#9
0
 public function testLocaleIsPassedToValueTransformer()
 {
     FormConfiguration::setDefaultLocale('de_DE');
     $transformer = $this->getMock('Symfony\\Component\\Form\\ValueTransformer\\ValueTransformerInterface');
     $transformer->expects($this->exactly(1))->method('setLocale')->with($this->equalTo('de_DE'));
     $field = new TestField('title', array('value_transformer' => $transformer));
 }
示例#10
0
 protected function setUp()
 {
     FormConfiguration::setDefaultLocale('de_AT');
 }