Updated vendors

This commit is contained in:
Polonkai Gergely 2012-07-23 08:07:07 +02:00
parent b82b4ffd34
commit b9e6708ffd
110 changed files with 1066 additions and 1243 deletions

View File

@ -3,7 +3,7 @@
"name": "jms/metadata", "name": "jms/metadata",
"version": "1.1.1", "version": "1.1.1",
"version_normalized": "1.1.1.0", "version_normalized": "1.1.1.0",
"time": "2011-12-29 14:32:49", "time": "2011-12-29 12:32:49",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/schmittjoh/metadata", "url": "https://github.com/schmittjoh/metadata",
@ -47,7 +47,7 @@
"name": "jms/cg", "name": "jms/cg",
"version": "1.0.0", "version": "1.0.0",
"version_normalized": "1.0.0.0", "version_normalized": "1.0.0.0",
"time": "2011-12-29 13:40:52", "time": "2011-12-29 11:40:52",
"source": { "source": {
"type": "git", "type": "git",
"url": "git://github.com/schmittjoh/cg-library.git", "url": "git://github.com/schmittjoh/cg-library.git",
@ -89,7 +89,7 @@
"version": "1.0.0", "version": "1.0.0",
"version_normalized": "1.0.0.0", "version_normalized": "1.0.0.0",
"target-dir": "JMS/AopBundle", "target-dir": "JMS/AopBundle",
"time": "2011-12-29 13:50:26", "time": "2011-12-29 11:50:26",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/schmittjoh/JMSAopBundle", "url": "https://github.com/schmittjoh/JMSAopBundle",
@ -133,7 +133,7 @@
"version": "1.1.0", "version": "1.1.0",
"version_normalized": "1.1.0.0", "version_normalized": "1.1.0.0",
"target-dir": "JMS/SecurityExtraBundle", "target-dir": "JMS/SecurityExtraBundle",
"time": "2011-12-29 17:38:12", "time": "2011-12-29 15:38:12",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/schmittjoh/JMSSecurityExtraBundle", "url": "https://github.com/schmittjoh/JMSSecurityExtraBundle",
@ -178,7 +178,7 @@
"version": "1.0.1", "version": "1.0.1",
"version_normalized": "1.0.1.0", "version_normalized": "1.0.1.0",
"target-dir": "JMS/DiExtraBundle", "target-dir": "JMS/DiExtraBundle",
"time": "2012-02-24 09:01:54", "time": "2012-02-24 07:01:54",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/schmittjoh/JMSDiExtraBundle", "url": "https://github.com/schmittjoh/JMSDiExtraBundle",
@ -221,7 +221,7 @@
"name": "doctrine/common", "name": "doctrine/common",
"version": "2.2.2", "version": "2.2.2",
"version_normalized": "2.2.2.0", "version_normalized": "2.2.2.0",
"time": "2012-04-06 11:46:44", "time": "2012-04-06 07:46:44",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/common", "url": "https://github.com/doctrine/common",
@ -287,7 +287,7 @@
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "1.1.0", "version": "1.1.0",
"version_normalized": "1.1.0.0", "version_normalized": "1.1.0.0",
"time": "2012-04-16 22:27:40", "time": "2012-04-16 18:27:40",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Seldaek/monolog.git", "url": "https://github.com/Seldaek/monolog.git",
@ -337,7 +337,7 @@
"name": "twig/extensions", "name": "twig/extensions",
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"time": "2012-05-15 05:28:19", "time": "2012-05-15 01:28:19",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/fabpot/Twig-extensions", "url": "https://github.com/fabpot/Twig-extensions",
@ -383,7 +383,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Doctrine/Bundle/DoctrineBundle", "target-dir": "Doctrine/Bundle/DoctrineBundle",
"time": "2012-07-01 18:42:17", "time": "2012-07-01 14:42:17",
"source": { "source": {
"type": "git", "type": "git",
"url": "git://github.com/doctrine/DoctrineBundle.git", "url": "git://github.com/doctrine/DoctrineBundle.git",
@ -457,7 +457,7 @@
"name": "doctrine/orm", "name": "doctrine/orm",
"version": "2.2.x-dev", "version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev", "version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-07-05 15:48:00", "time": "2012-07-05 11:48:00",
"source": { "source": {
"type": "git", "type": "git",
"url": "git://github.com/doctrine/doctrine2.git", "url": "git://github.com/doctrine/doctrine2.git",
@ -522,7 +522,7 @@
"name": "doctrine/dbal", "name": "doctrine/dbal",
"version": "2.2.x-dev", "version": "2.2.x-dev",
"version_normalized": "2.2.9999999.9999999-dev", "version_normalized": "2.2.9999999.9999999-dev",
"time": "2012-07-07 02:30:35", "time": "2012-07-06 22:30:35",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/dbal", "url": "https://github.com/doctrine/dbal",
@ -588,7 +588,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/GeneratorBundle", "target-dir": "Sensio/Bundle/GeneratorBundle",
"time": "2012-07-12 08:04:48", "time": "2012-07-12 04:04:48",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sensio/SensioGeneratorBundle", "url": "https://github.com/sensio/SensioGeneratorBundle",
@ -641,7 +641,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/MonologBundle", "target-dir": "Symfony/Bundle/MonologBundle",
"time": "2012-06-29 13:48:07", "time": "2012-06-29 09:48:07",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/MonologBundle", "url": "https://github.com/symfony/MonologBundle",
@ -701,7 +701,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/FrameworkExtraBundle", "target-dir": "Sensio/Bundle/FrameworkExtraBundle",
"time": "2012-07-11 07:13:52", "time": "2012-07-11 03:13:52",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sensio/SensioFrameworkExtraBundle", "url": "https://github.com/sensio/SensioFrameworkExtraBundle",
@ -750,7 +750,7 @@
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"time": "2012-07-12 20:47:17", "time": "2012-07-12 16:47:17",
"source": { "source": {
"type": "git", "type": "git",
"url": "git://github.com/swiftmailer/swiftmailer.git", "url": "git://github.com/swiftmailer/swiftmailer.git",
@ -806,7 +806,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Sensio/Bundle/DistributionBundle", "target-dir": "Sensio/Bundle/DistributionBundle",
"time": "2012-07-14 18:24:10", "time": "2012-07-14 14:24:10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sensio/SensioDistributionBundle", "url": "https://github.com/sensio/SensioDistributionBundle",
@ -850,7 +850,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/SwiftmailerBundle", "target-dir": "Symfony/Bundle/SwiftmailerBundle",
"time": "2012-07-19 01:55:12", "time": "2012-07-18 21:55:12",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/SwiftmailerBundle", "url": "https://github.com/symfony/SwiftmailerBundle",
@ -909,7 +909,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Ivory/CKEditorBundle", "target-dir": "Ivory/CKEditorBundle",
"time": "2012-05-28 11:16:47", "time": "2012-05-28 07:16:47",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/egeloen/IvoryCKEditorBundle", "url": "https://github.com/egeloen/IvoryCKEditorBundle",
@ -952,7 +952,7 @@
"name": "kriswallsmith/assetic", "name": "kriswallsmith/assetic",
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"time": "2012-07-20 10:33:33", "time": "2012-07-20 06:33:33",
"source": { "source": {
"type": "git", "type": "git",
"url": "http://github.com/kriswallsmith/assetic.git", "url": "http://github.com/kriswallsmith/assetic.git",
@ -1012,7 +1012,7 @@
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"target-dir": "Symfony/Bundle/AsseticBundle", "target-dir": "Symfony/Bundle/AsseticBundle",
"time": "2012-07-20 19:34:07", "time": "2012-07-20 15:34:07",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/AsseticBundle", "url": "https://github.com/symfony/AsseticBundle",
@ -1067,16 +1067,16 @@
"name": "twig/twig", "name": "twig/twig",
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"time": "2012-07-20 12:41:38", "time": "2012-07-22 08:32:58",
"source": { "source": {
"type": "git", "type": "git",
"url": "git://github.com/fabpot/Twig.git", "url": "git://github.com/fabpot/Twig.git",
"reference": "8a84838798e45424c5fe2d87149db6855ae037bf" "reference": "657de7bdeb680815e0df95f63da9f81e1533d2ea"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://github.com/fabpot/Twig/zipball/8a84838798e45424c5fe2d87149db6855ae037bf", "url": "https://github.com/fabpot/Twig/zipball/657de7bdeb680815e0df95f63da9f81e1533d2ea",
"reference": "8a84838798e45424c5fe2d87149db6855ae037bf", "reference": "657de7bdeb680815e0df95f63da9f81e1533d2ea",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1121,22 +1121,22 @@
"name": "symfony/symfony", "name": "symfony/symfony",
"version": "dev-master", "version": "dev-master",
"version_normalized": "9999999-dev", "version_normalized": "9999999-dev",
"time": "2012-07-21 11:16:18", "time": "2012-07-22 06:03:04",
"source": { "source": {
"type": "git", "type": "git",
"url": "git://github.com/symfony/symfony.git", "url": "git://github.com/symfony/symfony.git",
"reference": "6c256b01b087f94a4ec04487d875fe81375eb6c1" "reference": "c20c1d18dc0b588e10a8fab24264441f0e4a3e7c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://github.com/symfony/symfony/zipball/6c256b01b087f94a4ec04487d875fe81375eb6c1", "url": "https://github.com/symfony/symfony/zipball/c20c1d18dc0b588e10a8fab24264441f0e4a3e7c",
"reference": "6c256b01b087f94a4ec04487d875fe81375eb6c1", "reference": "c20c1d18dc0b588e10a8fab24264441f0e4a3e7c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"twig/twig": ">=1.8,<2.0-dev",
"doctrine/common": ">2.2,<2.4-dev", "doctrine/common": ">2.2,<2.4-dev",
"php": ">=5.3.3" "php": ">=5.3.3",
"twig/twig": ">=1.9.1,<2.0-dev"
}, },
"replace": { "replace": {
"symfony/doctrine-bridge": "self.version", "symfony/doctrine-bridge": "self.version",

View File

@ -224,30 +224,23 @@
`buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`. `buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`.
Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last, Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last,
all methods in these types now receive instances of `FormBuilderInterface` all methods in these types now receive instances of `FormBuilderInterface`
and `FormViewInterface` where they received instances of `FormBuilder` and where they received instances of `FormBuilder` before. You need to change the
`FormView` before. You need to change the method signatures in your method signatures in your form types and extensions as shown below.
form types and extensions as shown below.
Before: Before:
``` ```
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormView;
public function buildForm(FormBuilder $builder, array $options) public function buildForm(FormBuilder $builder, array $options)
public function buildView(FormView $view, FormInterface $form)
public function buildViewBottomUp(FormView $view, FormInterface $form)
``` ```
After: After:
``` ```
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormViewInterface;
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
public function buildView(FormViewInterface $view, FormInterface $form, array $options)
public function finishView(FormViewInterface $view, FormInterface $form, array $options)
``` ```
* The method `createBuilder` was removed from `FormTypeInterface` for performance * The method `createBuilder` was removed from `FormTypeInterface` for performance
@ -383,41 +376,6 @@
If address is an object in this case, the code given in "Before" If address is an object in this case, the code given in "Before"
works without changes. works without changes.
* The methods in class `FormView` were renamed to match the naming used in
`Form` and `FormBuilder`. The following list shows the old names on the
left and the new names on the right:
* `set`: `setVar`
* `has`: `hasVar`
* `get`: `getVar`
* `all`: `getVars`
* `addChild`: `add`
* `getChild`: `get`
* `getChildren`: `all`
* `removeChild`: `remove`
* `hasChild`: `has`
The new method `addVars` was added to make the definition of multiple
variables at once more convenient.
The method `hasChildren` was deprecated. You should use `count` instead.
Before:
```
$view->set('help', 'A text longer than six characters');
$view->set('error_class', 'max_length_error');
```
After:
```
$view->addVars(array(
'help' => 'A text longer than six characters',
'error_class' => 'max_length_error',
));
```
* Form and field names must now start with a letter, digit or underscore * Form and field names must now start with a letter, digit or underscore
and only contain letters, digits, underscores, hyphens and colons. and only contain letters, digits, underscores, hyphens and colons.
@ -601,6 +559,22 @@
{% endblock %} {% endblock %}
``` ```
* The method `renderBlock()` of the helper for the PHP Templating component was
renamed to `block()`. Its first argument is now expected to be a `FormView`
instance.
Before:
```
<?php echo $view['form']->renderBlock('widget_attributes') ?>
```
After:
```
<?php echo $view['form']->block($form, 'widget_attributes') ?>
```
#### Other BC Breaks #### Other BC Breaks
* The order of the first two arguments of the methods `createNamed` and * The order of the first two arguments of the methods `createNamed` and
@ -1054,19 +1028,65 @@
$registry->addType($registry->resolveType(new MyFormType())); $registry->addType($registry->resolveType(new MyFormType()));
``` ```
* The method `renderBlock()` of the helper for the PHP Templating component was * The following methods in class `FormView` were deprecated and will be
deprecated and will be removed in Symfony 2.3. You should use `block()` instead. removed in Symfony 2.3:
* `set`
* `has`
* `get`
* `all`
* `getVars`
* `addChild`
* `getChild`
* `getChildren`
* `removeChild`
* `hasChild`
* `hasChildren`
* `getParent`
* `hasParent`
* `setParent`
You should access the public properties `vars`, `children` and `parent`
instead.
Before: Before:
``` ```
<?php echo $view['form']->renderBlock('widget_attributes') ?> $view->set('help', 'A text longer than six characters');
$view->set('error_class', 'max_length_error');
``` ```
After: After:
``` ```
<?php echo $view['form']->block('widget_attributes') ?> $view->vars = array_replace($view->vars, array(
'help' => 'A text longer than six characters',
'error_class' => 'max_length_error',
));
```
Before:
```
echo $view->get('error_class');
```
After:
```
echo $view->vars['error_class'];
```
Before:
```
if ($view->hasChildren()) { ...
```
After:
```
if (count($view->children)) { ...
``` ```
### Validator ### Validator

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"doctrine/common": ">2.2,<2.4-dev", "doctrine/common": ">2.2,<2.4-dev",
"twig/twig": ">=1.8,<2.0-dev" "twig/twig": ">=1.9.1,<2.0-dev"
}, },
"replace": { "replace": {
"symfony/doctrine-bridge": "self.version", "symfony/doctrine-bridge": "self.version",

View File

@ -124,7 +124,7 @@ class EntityTypeTest extends TypeTestCase
'property' => 'name' 'property' => 'name'
)); ));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
} }
public function testSetDataToUninitializedEntityWithNonRequiredToString() public function testSetDataToUninitializedEntityWithNonRequiredToString()
@ -140,7 +140,7 @@ class EntityTypeTest extends TypeTestCase
'required' => false, 'required' => false,
)); ));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
} }
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder() public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
@ -159,7 +159,7 @@ class EntityTypeTest extends TypeTestCase
'query_builder' => $qb 'query_builder' => $qb
)); ));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
} }
/** /**
@ -503,7 +503,7 @@ class EntityTypeTest extends TypeTestCase
$field->bind('2'); $field->bind('2');
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->vars['choices']);
$this->assertTrue($field->isSynchronized()); $this->assertTrue($field->isSynchronized());
$this->assertSame($entity2, $field->getData()); $this->assertSame($entity2, $field->getData());
$this->assertSame('2', $field->getClientData()); $this->assertSame('2', $field->getClientData());
@ -533,7 +533,7 @@ class EntityTypeTest extends TypeTestCase
'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), 'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
'Group2' => array(3 => new ChoiceView('3', 'Baz')), 'Group2' => array(3 => new ChoiceView('3', 'Baz')),
'4' => new ChoiceView('4', 'Boo!') '4' => new ChoiceView('4', 'Boo!')
), $field->createView()->getVar('choices')); ), $field->createView()->vars['choices']);
} }
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier() public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()

View File

@ -13,7 +13,7 @@ namespace Symfony\Bridge\Twig\Extension;
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Bridge\Twig\Form\TwigRendererInterface; use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
/** /**
@ -62,15 +62,13 @@ class FormExtension extends \Twig_Extension
public function getFunctions() public function getFunctions()
{ {
return array( return array(
'form_enctype' => new \Twig_Function_Method($this, 'renderer->renderEnctype', array('is_safe' => array('html'))), 'form_enctype' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_widget' => new \Twig_Function_Method($this, 'renderer->renderWidget', array('is_safe' => array('html'))), 'form_widget' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_errors' => new \Twig_Function_Method($this, 'renderer->renderErrors', array('is_safe' => array('html'))), 'form_errors' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_label' => new \Twig_Function_Method($this, 'renderer->renderLabel', array('is_safe' => array('html'))), 'form_label' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_row' => new \Twig_Function_Method($this, 'renderer->renderRow', array('is_safe' => array('html'))), 'form_row' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'form_rest' => new \Twig_Function_Method($this, 'renderer->renderRest', array('is_safe' => array('html'))), 'form_rest' => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', array('is_safe' => array('html'))),
'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'), 'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'),
'_form_is_choice_group' => new \Twig_Function_Method($this, 'renderer->isChoiceGroup', array('is_safe' => array('html'))),
'_form_is_choice_selected' => new \Twig_Function_Method($this, 'renderer->isChoiceSelected', array('is_safe' => array('html'))),
); );
} }
@ -84,6 +82,48 @@ class FormExtension extends \Twig_Extension
); );
} }
/**
* {@inheritdoc}
*/
public function getTests()
{
return array(
'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'),
);
}
/**
* Returns whether a choice is selected for a given form value.
*
* Unfortunately Twig does not support an efficient way to execute the
* "is_selected" closure passed to the template by ChoiceType. It is faster
* to implement the logic here (around 65ms for a specific form).
*
* Directly implementing the logic here is also faster than doing so in
* ChoiceView (around 30ms).
*
* The worst option tested so far is to implement the logic in ChoiceView
* and access the ChoiceView method directly in the template. Doing so is
* around 220ms slower than doing the method call here in the filter. Twig
* seems to be much more efficient at executing filters than at executing
* methods of an object.
*
* @param ChoiceView $choice The choice to check.
* @param string|array $selectedValue The selected value to compare.
*
* @return Boolean Whether the choice is selected.
*
* @see ChoiceView::isSelected()
*/
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
{
if (is_array($selectedValue)) {
return false !== array_search($choice->value, $selectedValue, true);
}
return $choice->value === $selectedValue;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -12,7 +12,7 @@
namespace Symfony\Bridge\Twig\Form; namespace Symfony\Bridge\Twig\Form;
use Symfony\Component\Form\AbstractRendererEngine; use Symfony\Component\Form\AbstractRendererEngine;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
@ -40,9 +40,9 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array()) public function renderBlock(FormView $view, $resource, $blockName, array $variables = array())
{ {
$cacheKey = $view->getVar(self::CACHE_KEY_VAR); $cacheKey = $view->vars[self::CACHE_KEY_VAR];
$context = $this->environment->mergeGlobals($variables); $context = $this->environment->mergeGlobals($variables);
@ -55,7 +55,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
// We do not call renderBlock here to avoid too many nested level calls // We do not call renderBlock here to avoid too many nested level calls
// (XDebug limits the level to 100 by default) // (XDebug limits the level to 100 by default)
$this->template->displayBlock($block, $context, $this->resources[$cacheKey]); $this->template->displayBlock($blockName, $context, $this->resources[$cacheKey]);
return ob_get_clean(); return ob_get_clean();
} }
@ -70,13 +70,13 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
* *
* @see getResourceForBlock() * @see getResourceForBlock()
* *
* @param string $cacheKey The cache key of the form view. * @param string $cacheKey The cache key of the form view.
* @param FormViewInterface $view The form view for finding the applying themes. * @param FormView $view The form view for finding the applying themes.
* @param string $block The name of the block to load. * @param string $blockName The name of the block to load.
* *
* @return Boolean True if the resource could be loaded, false otherwise. * @return Boolean True if the resource could be loaded, false otherwise.
*/ */
protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block) protected function loadResourceForBlockName($cacheKey, FormView $view, $blockName)
{ {
// The caller guarantees that $this->resources[$cacheKey][$block] is // The caller guarantees that $this->resources[$cacheKey][$block] is
// not set, but it doesn't have to check whether $this->resources[$cacheKey] // not set, but it doesn't have to check whether $this->resources[$cacheKey]
@ -86,7 +86,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
// As said in the previous, the caller guarantees that // As said in the previous, the caller guarantees that
// $this->resources[$cacheKey][$block] is not set. Since the themes are // $this->resources[$cacheKey][$block] is not set. Since the themes are
// already loaded, it can only be a non-existing block. // already loaded, it can only be a non-existing block.
$this->resources[$cacheKey][$block] = false; $this->resources[$cacheKey][$blockName] = false;
return false; return false;
} }
@ -105,7 +105,7 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
} }
// Check the default themes once we reach the root view without success // Check the default themes once we reach the root view without success
if (!$view->hasParent()) { if (!$view->parent) {
for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) { for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
$this->loadResourcesFromTheme($cacheKey, $this->defaultThemes[$i]); $this->loadResourcesFromTheme($cacheKey, $this->defaultThemes[$i]);
// CONTINUE LOADING (see doc comment) // CONTINUE LOADING (see doc comment)
@ -113,29 +113,29 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE
} }
// Proceed with the themes of the parent view // Proceed with the themes of the parent view
if ($view->hasParent()) { if ($view->parent) {
$parentCacheKey = $view->getParent()->getVar(self::CACHE_KEY_VAR); $parentCacheKey = $view->parent->vars[self::CACHE_KEY_VAR];
if (!isset($this->resources[$parentCacheKey])) { if (!isset($this->resources[$parentCacheKey])) {
$this->loadResourceForBlock($parentCacheKey, $view->getParent(), $block); $this->loadResourceForBlockName($parentCacheKey, $view->parent, $blockName);
} }
// EAGER CACHE POPULATION (see doc comment) // EAGER CACHE POPULATION (see doc comment)
foreach ($this->resources[$parentCacheKey] as $blockName => $resource) { foreach ($this->resources[$parentCacheKey] as $nestedBlockName => $resource) {
if (!isset($this->resources[$cacheKey][$blockName])) { if (!isset($this->resources[$cacheKey][$nestedBlockName])) {
$this->resources[$cacheKey][$blockName] = $resource; $this->resources[$cacheKey][$nestedBlockName] = $resource;
} }
} }
} }
// Even though we loaded the themes, it can happen that none of them // Even though we loaded the themes, it can happen that none of them
// contains the searched block // contains the searched block
if (!isset($this->resources[$cacheKey][$block])) { if (!isset($this->resources[$cacheKey][$blockName])) {
// Cache that we didn't find anything to speed up further accesses // Cache that we didn't find anything to speed up further accesses
$this->resources[$cacheKey][$block] = false; $this->resources[$cacheKey][$blockName] = false;
} }
return false !== $this->resources[$cacheKey][$block]; return false !== $this->resources[$cacheKey][$blockName];
} }
/** /**

View File

@ -0,0 +1,56 @@
<?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\Bridge\Twig\Node;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class SearchAndRenderBlockNode extends \Twig_Node_Expression_Function
{
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$compiler->raw('$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(');
preg_match('/_([^_]+)$/', $this->getAttribute('name'), $matches);
$label = null;
$arguments = iterator_to_array($this->getNode('arguments'));
$blockNameSuffix = $matches[1];
if (isset($arguments[0])) {
$compiler->subcompile($arguments[0]);
$compiler->raw(', \'' . $blockNameSuffix . '\'');
if (isset($arguments[1])) {
$compiler->raw(', ');
// The "label" function allows one extra argument here, the label
if ('label' === $blockNameSuffix) {
if (isset($arguments[2])) {
$compiler->subcompile($arguments[2]);
$compiler->raw(' + ');
}
// Add the label to the variable array
$compiler->raw('array(\'label\' => ');
$compiler->subcompile($arguments[1]);
$compiler->raw(')');
} else {
$compiler->subcompile($arguments[1]);
}
}
}
$compiler->raw(")");
}
}

View File

@ -86,15 +86,14 @@
{% block choice_widget_options %} {% block choice_widget_options %}
{% spaceless %} {% spaceless %}
{% for index, choice in options %} {% for group_label, choice in options %}
{% if _form_is_choice_group(choice) %} {% if choice is iterable %}
<optgroup label="{{ index|trans({}, translation_domain) }}"> <optgroup label="{{ group_label|trans({}, translation_domain) }}">
{% for nested_choice in choice %} {% set options = choice %}
<option value="{{ nested_choice.value }}"{% if _form_is_choice_selected(form, nested_choice) %} selected="selected"{% endif %}>{{ nested_choice.label|trans({}, translation_domain) }}</option> {{ block('choice_widget_options') }}
{% endfor %}
</optgroup> </optgroup>
{% else %} {% else %}
<option value="{{ choice.value }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option> <option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endspaceless %} {% endspaceless %}

View File

@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator; use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator;
use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader;
use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Tests\AbstractDivLayoutTest; use Symfony\Component\Form\Tests\AbstractDivLayoutTest;
class FormExtensionDivLayoutTest extends AbstractDivLayoutTest class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
@ -105,34 +106,71 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
); );
} }
public function isSelectedChoiceProvider()
{
// The commented cases should not be necessary anymore, because the
// choice lists should assure that both values passed here are always
// strings
return array(
// array(true, 0, 0),
array(true, '0', '0'),
array(true, '1', '1'),
// array(true, false, 0),
// array(true, true, 1),
array(true, '', ''),
// array(true, null, ''),
array(true, '1.23', '1.23'),
array(true, 'foo', 'foo'),
array(true, 'foo10', 'foo10'),
array(true, 'foo', array(1, 'foo', 'foo10')),
array(false, 10, array(1, 'foo', 'foo10')),
array(false, 0, array(1, 'foo', 'foo10')),
);
}
/**
* @dataProvider isSelectedChoiceProvider
*/
public function testIsChoiceSelected($expected, $choice, $value)
{
$choice = new ChoiceView($choice, $choice . ' label');
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
}
protected function renderEnctype(FormView $view) protected function renderEnctype(FormView $view)
{ {
return (string) $this->extension->renderer->renderEnctype($view); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
} }
protected function renderLabel(FormView $view, $label = null, array $vars = array()) protected function renderLabel(FormView $view, $label = null, array $vars = array())
{ {
return (string) $this->extension->renderer->renderLabel($view, $label, $vars); if ($label !== null) {
$vars += array('label' => $label);
}
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
} }
protected function renderErrors(FormView $view) protected function renderErrors(FormView $view)
{ {
return (string) $this->extension->renderer->renderErrors($view); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
} }
protected function renderWidget(FormView $view, array $vars = array()) protected function renderWidget(FormView $view, array $vars = array())
{ {
return (string) $this->extension->renderer->renderWidget($view, $vars); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
} }
protected function renderRow(FormView $view, array $vars = array()) protected function renderRow(FormView $view, array $vars = array())
{ {
return (string) $this->extension->renderer->renderRow($view, $vars); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
} }
protected function renderRest(FormView $view, array $vars = array()) protected function renderRest(FormView $view, array $vars = array())
{ {
return (string) $this->extension->renderer->renderRest($view, $vars); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
} }
protected function setTheme(FormView $view, array $themes) protected function setTheme(FormView $view, array $themes)

View File

@ -77,32 +77,36 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
protected function renderEnctype(FormView $view) protected function renderEnctype(FormView $view)
{ {
return (string) $this->extension->renderer->renderEnctype($view); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'enctype');
} }
protected function renderLabel(FormView $view, $label = null, array $vars = array()) protected function renderLabel(FormView $view, $label = null, array $vars = array())
{ {
return (string) $this->extension->renderer->renderLabel($view, $label, $vars); if ($label !== null) {
$vars += array('label' => $label);
}
return (string) $this->extension->renderer->searchAndRenderBlock($view, 'label', $vars);
} }
protected function renderErrors(FormView $view) protected function renderErrors(FormView $view)
{ {
return (string) $this->extension->renderer->renderErrors($view); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'errors');
} }
protected function renderWidget(FormView $view, array $vars = array()) protected function renderWidget(FormView $view, array $vars = array())
{ {
return (string) $this->extension->renderer->renderWidget($view, $vars); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'widget', $vars);
} }
protected function renderRow(FormView $view, array $vars = array()) protected function renderRow(FormView $view, array $vars = array())
{ {
return (string) $this->extension->renderer->renderRow($view, $vars); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'row', $vars);
} }
protected function renderRest(FormView $view, array $vars = array()) protected function renderRest(FormView $view, array $vars = array())
{ {
return (string) $this->extension->renderer->renderRest($view, $vars); return (string) $this->extension->renderer->searchAndRenderBlock($view, 'rest', $vars);
} }
protected function setTheme(FormView $view, array $themes) protected function setTheme(FormView $view, array $themes)

View File

@ -17,7 +17,7 @@
], ],
"require": { "require": {
"php": ">=5.3.3", "php": ">=5.3.3",
"twig/twig": ">=1.8,<2.0-dev" "twig/twig": ">=1.9.1,<2.0-dev"
}, },
"require-dev": { "require-dev": {
"symfony/form": "2.1.*", "symfony/form": "2.1.*",

View File

@ -1 +1 @@
<?php echo $view['form']->block('widget_attributes') ?> <?php echo $view['form']->block($form, 'widget_attributes') ?>

View File

@ -1,5 +1,5 @@
<input type="checkbox" <input type="checkbox"
<?php echo $view['form']->block('widget_attributes') ?> <?php echo $view['form']->block($form, 'widget_attributes') ?>
<?php if ($value): ?> value="<?php echo $view->escape($value) ?>"<?php endif ?> <?php if ($value): ?> value="<?php echo $view->escape($value) ?>"<?php endif ?>
<?php if ($checked): ?> checked="checked"<?php endif ?> <?php if ($checked): ?> checked="checked"<?php endif ?>
/> />

View File

@ -1 +1 @@
<?php echo $view['form']->block('choice_widget_options') ?> <?php echo $view['form']->block($form, 'choice_widget_options') ?>

View File

@ -1,5 +1,5 @@
<?php if ($expanded): ?> <?php if ($expanded): ?>
<?php echo $view['form']->block('choice_widget_expanded') ?> <?php echo $view['form']->block($form, 'choice_widget_expanded') ?>
<?php else: ?> <?php else: ?>
<?php echo $view['form']->block('choice_widget_collapsed') ?> <?php echo $view['form']->block($form, 'choice_widget_collapsed') ?>
<?php endif ?> <?php endif ?>

View File

@ -1,13 +1,13 @@
<select <select
<?php echo $view['form']->block('widget_attributes') ?> <?php echo $view['form']->block($form, 'widget_attributes') ?>
<?php if ($multiple): ?> multiple="multiple"<?php endif ?> <?php if ($multiple): ?> multiple="multiple"<?php endif ?>
> >
<?php if (null !== $empty_value): ?><option value=""><?php echo $view->escape($view['translator']->trans($empty_value, array(), $translation_domain)) ?></option><?php endif; ?> <?php if (null !== $empty_value): ?><option value=""><?php echo $view->escape($view['translator']->trans($empty_value, array(), $translation_domain)) ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?> <?php if (count($preferred_choices) > 0): ?>
<?php echo $view['form']->block('choice_widget_options', array('options' => $preferred_choices)) ?> <?php echo $view['form']->block($form, 'choice_widget_options', array('choices' => $preferred_choices)) ?>
<?php if (count($choices) > 0 && null !== $separator): ?> <?php if (count($choices) > 0 && null !== $separator): ?>
<option disabled="disabled"><?php echo $separator ?></option> <option disabled="disabled"><?php echo $separator ?></option>
<?php endif ?> <?php endif ?>
<?php endif ?> <?php endif ?>
<?php echo $view['form']->block('choice_widget_options', array('options' => $choices)) ?> <?php echo $view['form']->block($form, 'choice_widget_options', array('choices' => $choices)) ?>
</select> </select>

View File

@ -1,4 +1,4 @@
<div <?php echo $view['form']->block('widget_container_attributes') ?>> <div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php foreach ($form as $child): ?> <?php foreach ($form as $child): ?>
<?php echo $view['form']->widget($child) ?> <?php echo $view['form']->widget($child) ?>
<?php echo $view['form']->label($child) ?> <?php echo $view['form']->label($child) ?>

View File

@ -1,11 +1,11 @@
<?php foreach ($options as $index => $choice): ?> <?php $translatorHelper = $view['translator']; // outside of the loop for performance reasons! ?>
<?php if ($view['form']->isChoiceGroup($choice)): ?> <?php $formHelper = $view['form']; ?>
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>"> <?php foreach ($choices as $index => $choice): ?>
<?php foreach ($choice as $nested_choice): ?> <?php if (is_array($choice)): ?>
<option value="<?php echo $view->escape($nested_choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $nested_choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($nested_choice->getLabel(), array(), $translation_domain)) ?></option> <optgroup label="<?php echo $view->escape($translatorHelper->trans($index, array(), $translation_domain)) ?>">
<?php endforeach ?> <?php echo $formHelper->block($form, 'choice_widget_options', array('choices' => $choice)) ?>
</optgroup> </optgroup>
<?php else: ?> <?php else: ?>
<option value="<?php echo $view->escape($choice->getValue()) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->getLabel(), array(), $translation_domain)) ?></option> <option value="<?php echo $view->escape($choice->value) ?>"<?php if ($is_selected($choice->value, $value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
<?php endif ?> <?php endif ?>
<?php endforeach ?> <?php endforeach ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('widget_container_attributes') ?> <?php echo $view['form']->block($form, 'widget_container_attributes') ?>

View File

@ -1,7 +1,7 @@
<?php if ($widget == 'single_text'): ?> <?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->block('form_widget_simple'); ?> <?php echo $view['form']->block($form, 'form_widget_simple'); ?>
<?php else: ?> <?php else: ?>
<div <?php echo $view['form']->block('widget_container_attributes') ?>> <div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array( <?php echo str_replace(array('{{ year }}', '{{ month }}', '{{ day }}'), array(
$view['form']->widget($form['year']), $view['form']->widget($form['year']),
$view['form']->widget($form['month']), $view['form']->widget($form['month']),

View File

@ -1,7 +1,7 @@
<?php if ($widget == 'single_text'): ?> <?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->block('form_widget_simple'); ?> <?php echo $view['form']->block($form, 'form_widget_simple'); ?>
<?php else: ?> <?php else: ?>
<div <?php echo $view['form']->block('widget_container_attributes') ?>> <div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?> <?php echo $view['form']->widget($form['date']).' '.$view['form']->widget($form['time']) ?>
</div> </div>
<?php endif ?> <?php endif ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : 'email')) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'email')) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_enctype') ?> <?php echo $view['form']->block($form, 'form_enctype') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_errors') ?> <?php echo $view['form']->block($form, 'form_errors') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_label') ?> <?php echo $view['form']->block($form, 'form_label') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_rest') ?> <?php echo $view['form']->block($form, 'form_rest') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_row') ?> <?php echo $view['form']->block($form, 'form_row') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_rows') ?> <?php echo $view['form']->block($form, 'form_rows') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple') ?> <?php echo $view['form']->block($form, 'form_widget_simple') ?>

View File

@ -1 +1 @@
<?php if ($form->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?> <?php if ($form->vars['multipart']): ?>enctype="multipart/form-data"<?php endif ?>

View File

@ -1,5 +1,5 @@
<?php if ($compound): ?> <?php if ($compound): ?>
<?php echo $view['form']->block('form_widget_compound')?> <?php echo $view['form']->block($form, 'form_widget_compound')?>
<?php else: ?> <?php else: ?>
<?php echo $view['form']->block('form_widget_simple')?> <?php echo $view['form']->block($form, 'form_widget_simple')?>
<?php endif ?> <?php endif ?>

View File

@ -1,11 +1,11 @@
<div <?php echo $view['form']->block('widget_container_attributes') ?>> <div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php if (!$form->hasParent() && $errors): ?> <?php if (!$form->parent && $errors): ?>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<?php echo $view['form']->errors($form) ?> <?php echo $view['form']->errors($form) ?>
</td> </td>
</tr> </tr>
<?php endif ?> <?php endif ?>
<?php echo $view['form']->block('form_rows') ?> <?php echo $view['form']->block($form, 'form_rows') ?>
<?php echo $view['form']->rest($form) ?> <?php echo $view['form']->rest($form) ?>
</div> </div>

View File

@ -1,5 +1,5 @@
<input <input
type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>" type="<?php echo isset($type) ? $view->escape($type) : 'text' ?>"
<?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?> <?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
<?php echo $view['form']->block('widget_attributes') ?> <?php echo $view['form']->block($form, 'widget_attributes') ?>
/> />

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "hidden")) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "hidden")) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "number")) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>

View File

@ -1 +1 @@
<?php echo str_replace('{{ widget }}', $view['form']->block('form_widget_simple'), $money_pattern) ?> <?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "text")) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "password")) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "password")) ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> % <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "text")) ?> %

View File

@ -1,5 +1,5 @@
<input type="radio" <input type="radio"
<?php echo $view['form']->block('widget_attributes') ?> <?php echo $view['form']->block($form, 'widget_attributes') ?>
value="<?php echo $view->escape($value) ?>" value="<?php echo $view->escape($value) ?>"
<?php if ($checked): ?> checked="checked"<?php endif ?> <?php if ($checked): ?> checked="checked"<?php endif ?>
/> />

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_rows') ?> <?php echo $view['form']->block($form, 'form_rows') ?>

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "search")) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "search")) ?>

View File

@ -1 +1 @@
<textarea <?php echo $view['form']->block('widget_attributes') ?>><?php echo $view->escape($value) ?></textarea> <textarea <?php echo $view['form']->block($form, 'widget_attributes') ?>><?php echo $view->escape($value) ?></textarea>

View File

@ -1,7 +1,7 @@
<?php if ($widget == 'single_text'): ?> <?php if ($widget == 'single_text'): ?>
<?php echo $view['form']->block('form_widget_simple'); ?> <?php echo $view['form']->block($form, 'form_widget_simple'); ?>
<?php else: ?> <?php else: ?>
<div <?php echo $view['form']->block('widget_container_attributes') ?>> <div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php <?php
// There should be no spaces between the colons and the widgets, that's why // There should be no spaces between the colons and the widgets, that's why
// this block is written in a single PHP tag // this block is written in a single PHP tag

View File

@ -1 +1 @@
<?php echo $view['form']->block('form_widget_simple', array('type' => isset($type) ? $type : "url")) ?> <?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "url")) ?>

View File

@ -1,7 +1,7 @@
<table <?php echo $view['form']->block('widget_container_attributes') ?>> <table <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php if (!$form->hasParent()): ?> <?php if (!$form->parent): ?>
<?php echo $view['form']->errors($form) ?> <?php echo $view['form']->errors($form) ?>
<?php endif ?> <?php endif ?>
<?php echo $view['form']->block('form_rows') ?> <?php echo $view['form']->block($form, 'form_rows') ?>
<?php echo $view['form']->rest($form) ?> <?php echo $view['form']->rest($form) ?>
</table> </table>

View File

@ -13,7 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
use Symfony\Component\Templating\Helper\Helper; use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Form\FormRendererInterface; use Symfony\Component\Form\FormRendererInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
@ -49,25 +49,15 @@ class FormHelper extends Helper
return 'form'; return 'form';
} }
public function isChoiceGroup($label)
{
return $this->renderer->isChoiceGroup($label);
}
public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice)
{
return $this->renderer->isChoiceSelected($view, $choice);
}
/** /**
* Sets a theme for a given view. * Sets a theme for a given view.
* *
* The theme format is "<Bundle>:<Controller>". * The theme format is "<Bundle>:<Controller>".
* *
* @param FormViewInterface $view A FormViewInterface instance * @param FormView $view A FormView instance
* @param string|array $themes A theme or an array of theme * @param string|array $themes A theme or an array of theme
*/ */
public function setTheme(FormViewInterface $view, $themes) public function setTheme(FormView $view, $themes)
{ {
$this->renderer->setTheme($view, $themes); $this->renderer->setTheme($view, $themes);
} }
@ -79,13 +69,13 @@ class FormHelper extends Helper
* *
* <form action="..." method="post" <?php echo $view['form']->enctype() ?>> * <form action="..." method="post" <?php echo $view['form']->enctype() ?>>
* *
* @param FormViewInterface $view The view for which to render the encoding type * @param FormView $view The view for which to render the encoding type
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function enctype(FormViewInterface $view) public function enctype(FormView $view)
{ {
return $this->renderer->renderEnctype($view); return $this->renderer->searchAndRenderBlock($view, 'enctype');
} }
/** /**
@ -101,95 +91,84 @@ class FormHelper extends Helper
* *
* <?php echo view['form']->widget(array('separator' => '+++++)) ?> * <?php echo view['form']->widget(array('separator' => '+++++)) ?>
* *
* @param FormViewInterface $view The view for which to render the widget * @param FormView $view The view for which to render the widget
* @param array $variables Additional variables passed to the template * @param array $variables Additional variables passed to the template
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function widget(FormViewInterface $view, array $variables = array()) public function widget(FormView $view, array $variables = array())
{ {
return $this->renderer->renderWidget($view, $variables); return $this->renderer->searchAndRenderBlock($view, 'widget', $variables);
} }
/** /**
* Renders the entire form field "row". * Renders the entire form field "row".
* *
* @param FormViewInterface $view The view for which to render the row * @param FormView $view The view for which to render the row
* @param array $variables Additional variables passed to the template * @param array $variables Additional variables passed to the template
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function row(FormViewInterface $view, array $variables = array()) public function row(FormView $view, array $variables = array())
{ {
return $this->renderer->renderRow($view, $variables); return $this->renderer->searchAndRenderBlock($view, 'row', $variables);
} }
/** /**
* Renders the label of the given view. * Renders the label of the given view.
* *
* @param FormViewInterface $view The view for which to render the label * @param FormView $view The view for which to render the label
* @param string $label The label * @param string $label The label
* @param array $variables Additional variables passed to the template * @param array $variables Additional variables passed to the template
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function label(FormViewInterface $view, $label = null, array $variables = array()) public function label(FormView $view, $label = null, array $variables = array())
{ {
return $this->renderer->renderLabel($view, $label, $variables); if ($label !== null) {
$variables += array('label' => $label);
}
return $this->renderer->searchAndRenderBlock($view, 'label', $variables);
} }
/** /**
* Renders the errors of the given view. * Renders the errors of the given view.
* *
* @param FormViewInterface $view The view to render the errors for * @param FormView $view The view to render the errors for
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function errors(FormViewInterface $view) public function errors(FormView $view)
{ {
return $this->renderer->renderErrors($view); return $this->renderer->searchAndRenderBlock($view, 'errors');
} }
/** /**
* Renders views which have not already been rendered. * Renders views which have not already been rendered.
* *
* @param FormViewInterface $view The parent view * @param FormView $view The parent view
* @param array $variables An array of variables * @param array $variables An array of variables
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function rest(FormViewInterface $view, array $variables = array()) public function rest(FormView $view, array $variables = array())
{ {
return $this->renderer->renderRest($view, $variables); return $this->renderer->searchAndRenderBlock($view, 'rest', $variables);
}
/**
* Alias of {@link block()}
*
* @param string $block The name of the block to render.
* @param array $variables The variable to pass to the template.
*
* @return string The HTML markup
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link block()} instead.
*/
public function renderBlock($block, array $variables = array())
{
return $this->block($block, $variables);
} }
/** /**
* Renders a block of the template. * Renders a block of the template.
* *
* @param string $block The name of the block to render. * @param FormView $view The view for determining the used themes.
* @param array $variables The variable to pass to the template. * @param string $blockName The name of the block to render.
* @param array $variables The variable to pass to the template.
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function block($block, array $variables = array()) public function block(FormView $view, $blockName, array $variables = array())
{ {
return $this->renderer->renderBlock($block, $variables); return $this->renderer->renderBlock($view, $blockName, $variables);
} }
/** /**

View File

@ -28,8 +28,6 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
protected function setUp() protected function setUp()
{ {
ini_set('xdebug.max_nesting_level', 120);
parent::setUp(); parent::setUp();
$root = realpath(__DIR__.'/../../../Resources/views'); $root = realpath(__DIR__.'/../../../Resources/views');

View File

@ -1,2 +1,2 @@
<?php $type = isset($type) ? $type : 'text' ?> <?php $type = isset($type) ? $type : 'text' ?>
<input type="<?php echo $type ?>" <?php $view['form']->renderBlock('widget_attributes') ?> value="<?php echo $value ?>" rel="theme" /> <input type="<?php echo $type ?>" <?php $view['form']->block($form, 'widget_attributes') ?> value="<?php echo $value ?>" rel="theme" />

View File

@ -19,7 +19,7 @@ namespace Symfony\Component\Form;
abstract class AbstractRendererEngine implements FormRendererEngineInterface abstract class AbstractRendererEngine implements FormRendererEngineInterface
{ {
/** /**
* The variable in {@link FormViewInterface} used as cache key. * The variable in {@link FormView} used as cache key.
*/ */
const CACHE_KEY_VAR = 'full_block_name'; const CACHE_KEY_VAR = 'full_block_name';
@ -57,9 +57,9 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setTheme(FormViewInterface $view, $themes) public function setTheme(FormView $view, $themes)
{ {
$cacheKey = $view->getVar(self::CACHE_KEY_VAR); $cacheKey = $view->vars[self::CACHE_KEY_VAR];
// Do not cast, as casting turns objects into arrays of properties // Do not cast, as casting turns objects into arrays of properties
$this->themes[$cacheKey] = is_array($themes) ? $themes : array($themes); $this->themes[$cacheKey] = is_array($themes) ? $themes : array($themes);
@ -74,52 +74,52 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getResourceForBlock(FormViewInterface $view, $block) public function getResourceForBlockName(FormView $view, $blockName)
{ {
$cacheKey = $view->getVar(self::CACHE_KEY_VAR); $cacheKey = $view->vars[self::CACHE_KEY_VAR];
if (!isset($this->resources[$cacheKey][$block])) { if (!isset($this->resources[$cacheKey][$blockName])) {
$this->loadResourceForBlock($cacheKey, $view, $block); $this->loadResourceForBlockName($cacheKey, $view, $blockName);
} }
return $this->resources[$cacheKey][$block]; return $this->resources[$cacheKey][$blockName];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getResourceForBlockHierarchy(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel) public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, $hierarchyLevel)
{ {
$cacheKey = $view->getVar(self::CACHE_KEY_VAR); $cacheKey = $view->vars[self::CACHE_KEY_VAR];
$block = $blockHierarchy[$hierarchyLevel]; $blockName = $blockNameHierarchy[$hierarchyLevel];
if (!isset($this->resources[$cacheKey][$block])) { if (!isset($this->resources[$cacheKey][$blockName])) {
$this->loadResourceForBlockHierarchy($cacheKey, $view, $blockHierarchy, $hierarchyLevel); $this->loadResourceForBlockNameHierarchy($cacheKey, $view, $blockNameHierarchy, $hierarchyLevel);
} }
return $this->resources[$cacheKey][$block]; return $this->resources[$cacheKey][$blockName];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getResourceHierarchyLevel(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel) public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, $hierarchyLevel)
{ {
$cacheKey = $view->getVar(self::CACHE_KEY_VAR); $cacheKey = $view->vars[self::CACHE_KEY_VAR];
$block = $blockHierarchy[$hierarchyLevel]; $blockName = $blockNameHierarchy[$hierarchyLevel];
if (!isset($this->resources[$cacheKey][$block])) { if (!isset($this->resources[$cacheKey][$blockName])) {
$this->loadResourceForBlockHierarchy($cacheKey, $view, $blockHierarchy, $hierarchyLevel); $this->loadResourceForBlockNameHierarchy($cacheKey, $view, $blockNameHierarchy, $hierarchyLevel);
} }
// If $block was previously rendered loaded with loadTemplateForBlock(), the template // If $block was previously rendered loaded with loadTemplateForBlock(), the template
// is cached but the hierarchy level is not. In this case, we know that the block // is cached but the hierarchy level is not. In this case, we know that the block
// exists at this very hierarchy level, so we can just set it. // exists at this very hierarchy level, so we can just set it.
if (!isset($this->resourceHierarchyLevels[$cacheKey][$block])) { if (!isset($this->resourceHierarchyLevels[$cacheKey][$blockName])) {
$this->resourceHierarchyLevels[$cacheKey][$block] = $hierarchyLevel; $this->resourceHierarchyLevels[$cacheKey][$blockName] = $hierarchyLevel;
} }
return $this->resourceHierarchyLevels[$cacheKey][$block]; return $this->resourceHierarchyLevels[$cacheKey][$blockName];
} }
/** /**
@ -127,79 +127,79 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
* *
* @see getResourceForBlock() * @see getResourceForBlock()
* *
* @param string $cacheKey The cache key of the form view. * @param string $cacheKey The cache key of the form view.
* @param FormViewInterface $view The form view for finding the applying themes. * @param FormView $view The form view for finding the applying themes.
* @param string $block The name of the block to load. * @param string $blockName The name of the block to load.
* *
* @return Boolean True if the resource could be loaded, false otherwise. * @return Boolean True if the resource could be loaded, false otherwise.
*/ */
abstract protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block); abstract protected function loadResourceForBlockName($cacheKey, FormView $view, $blockName);
/** /**
* Loads the cache with the resource for a specific level of a block hierarchy. * Loads the cache with the resource for a specific level of a block hierarchy.
* *
* @see getResourceForBlockHierarchy() * @see getResourceForBlockHierarchy()
* *
* @param string $cacheKey The cache key used for storing the * @param string $cacheKey The cache key used for storing the
* resource. * resource.
* @param FormViewInterface $view The form view for finding the applying * @param FormView $view The form view for finding the applying
* themes. * themes.
* @param array $blockHierarchy The block hierarchy, with the most * @param array $blockNameHierarchy The block hierarchy, with the most
* specific block name at the end. * specific block name at the end.
* @param integer $hierarchyLevel The level in the block hierarchy that * @param integer $hierarchyLevel The level in the block hierarchy that
* should be loaded. * should be loaded.
* *
* @return Boolean True if the resource could be loaded, false otherwise. * @return Boolean True if the resource could be loaded, false otherwise.
*/ */
private function loadResourceForBlockHierarchy($cacheKey, FormViewInterface $view, array $blockHierarchy, $hierarchyLevel) private function loadResourceForBlockNameHierarchy($cacheKey, FormView $view, array $blockNameHierarchy, $hierarchyLevel)
{ {
$block = $blockHierarchy[$hierarchyLevel]; $blockName = $blockNameHierarchy[$hierarchyLevel];
// Try to find a template for that block // Try to find a template for that block
if ($this->loadResourceForBlock($cacheKey, $view, $block)) { if ($this->loadResourceForBlockName($cacheKey, $view, $blockName)) {
// If loadTemplateForBlock() returns true, it was able to populate the // If loadTemplateForBlock() returns true, it was able to populate the
// cache. The only missing thing is to set the hierarchy level at which // cache. The only missing thing is to set the hierarchy level at which
// the template was found. // the template was found.
$this->resourceHierarchyLevels[$cacheKey][$block] = $hierarchyLevel; $this->resourceHierarchyLevels[$cacheKey][$blockName] = $hierarchyLevel;
return true; return true;
} }
if ($hierarchyLevel > 0) { if ($hierarchyLevel > 0) {
$parentLevel = $hierarchyLevel - 1; $parentLevel = $hierarchyLevel - 1;
$parentBlock = $blockHierarchy[$parentLevel]; $parentBlockName = $blockNameHierarchy[$parentLevel];
// The next two if statements contain slightly duplicated code. This is by intention // The next two if statements contain slightly duplicated code. This is by intention
// and tries to avoid execution of unnecessary checks in order to increase performance. // and tries to avoid execution of unnecessary checks in order to increase performance.
if (isset($this->resources[$cacheKey][$parentBlock])) { if (isset($this->resources[$cacheKey][$parentBlockName])) {
// It may happen that the parent block is already loaded, but its level is not. // It may happen that the parent block is already loaded, but its level is not.
// In this case, the parent block must have been loaded by loadResourceForBlock(), // In this case, the parent block must have been loaded by loadResourceForBlock(),
// which does not check the hierarchy of the block. Subsequently the block must have // which does not check the hierarchy of the block. Subsequently the block must have
// been found directly on the parent level. // been found directly on the parent level.
if (!isset($this->resourceHierarchyLevels[$cacheKey][$parentBlock])) { if (!isset($this->resourceHierarchyLevels[$cacheKey][$parentBlockName])) {
$this->resourceHierarchyLevels[$cacheKey][$parentBlock] = $parentLevel; $this->resourceHierarchyLevels[$cacheKey][$parentBlockName] = $parentLevel;
} }
// Cache the shortcuts for further accesses // Cache the shortcuts for further accesses
$this->resources[$cacheKey][$block] = $this->resources[$cacheKey][$parentBlock]; $this->resources[$cacheKey][$blockName] = $this->resources[$cacheKey][$parentBlockName];
$this->resourceHierarchyLevels[$cacheKey][$block] = $this->resourceHierarchyLevels[$cacheKey][$parentBlock]; $this->resourceHierarchyLevels[$cacheKey][$blockName] = $this->resourceHierarchyLevels[$cacheKey][$parentBlockName];
return true; return true;
} }
if ($this->loadResourceForBlockHierarchy($cacheKey, $view, $blockHierarchy, $parentLevel)) { if ($this->loadResourceForBlockNameHierarchy($cacheKey, $view, $blockNameHierarchy, $parentLevel)) {
// Cache the shortcuts for further accesses // Cache the shortcuts for further accesses
$this->resources[$cacheKey][$block] = $this->resources[$cacheKey][$parentBlock]; $this->resources[$cacheKey][$blockName] = $this->resources[$cacheKey][$parentBlockName];
$this->resourceHierarchyLevels[$cacheKey][$block] = $this->resourceHierarchyLevels[$cacheKey][$parentBlock]; $this->resourceHierarchyLevels[$cacheKey][$blockName] = $this->resourceHierarchyLevels[$cacheKey][$parentBlockName];
return true; return true;
} }
} }
// Cache the result for further accesses // Cache the result for further accesses
$this->resources[$cacheKey][$block] = false; $this->resources[$cacheKey][$blockName] = false;
$this->resourceHierarchyLevels[$cacheKey][$block] = false; $this->resourceHierarchyLevels[$cacheKey][$blockName] = false;
return false; return false;
} }

View File

@ -36,14 +36,14 @@ abstract class AbstractType implements FormTypeInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
} }
@ -52,19 +52,21 @@ abstract class AbstractType implements FormTypeInterface
*/ */
public function setDefaultOptions(OptionsResolverInterface $resolver) public function setDefaultOptions(OptionsResolverInterface $resolver)
{ {
$resolver->setDefaults($this->getDefaultOptions()); $resolver->setDefaults($this->getDefaultOptions(array()));
$resolver->addAllowedValues($this->getAllowedOptionValues()); $resolver->addAllowedValues($this->getAllowedOptionValues(array()));
} }
/** /**
* Returns the default options for this type. * Returns the default options for this type.
* *
* @param array $options Unsupported as of Symfony 2.1.
*
* @return array The default options * @return array The default options
* *
* @deprecated Deprecated since version 2.1, to be removed in 2.3. * @deprecated Deprecated since version 2.1, to be removed in 2.3.
* Use {@link setDefaultOptions()} instead. * Use {@link setDefaultOptions()} instead.
*/ */
public function getDefaultOptions() public function getDefaultOptions(array $options)
{ {
return array(); return array();
} }
@ -72,12 +74,14 @@ abstract class AbstractType implements FormTypeInterface
/** /**
* Returns the allowed option values for each option (if any). * Returns the allowed option values for each option (if any).
* *
* @param array $options Unsupported as of Symfony 2.1.
*
* @return array The allowed option values * @return array The allowed option values
* *
* @deprecated Deprecated since version 2.1, to be removed in 2.3. * @deprecated Deprecated since version 2.1, to be removed in 2.3.
* Use {@link setDefaultOptions()} instead. * Use {@link setDefaultOptions()} instead.
*/ */
public function getAllowedOptionValues() public function getAllowedOptionValues(array $options)
{ {
return array(); return array();
} }

View File

@ -28,14 +28,14 @@ abstract class AbstractTypeExtension implements FormTypeExtensionInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
} }

View File

@ -106,17 +106,14 @@ CHANGELOG
* removed superfluous methods from DataMapperInterface * removed superfluous methods from DataMapperInterface
* `mapFormToData` * `mapFormToData`
* `mapDataToForm` * `mapDataToForm`
* [BC BREAK] FormType::getDefaultOptions() and FormType::getAllowedOptionValues()
don't receive an options array anymore.
* added `setDefaultOptions` to FormTypeInterface and FormTypeExtensionInterface * added `setDefaultOptions` to FormTypeInterface and FormTypeExtensionInterface
which accepts an OptionsResolverInterface instance which accepts an OptionsResolverInterface instance
* deprecated the methods `getDefaultOptions` and `getAllowedOptionValues` * deprecated the methods `getDefaultOptions` and `getAllowedOptionValues`
in FormTypeInterface and FormTypeExtensionInterface in FormTypeInterface and FormTypeExtensionInterface
* options passed during construction can now be accessed from FormConfigInterface * options passed during construction can now be accessed from FormConfigInterface
* added FormBuilderInterface, FormViewInterface and FormConfigEditorInterface * added FormBuilderInterface and FormConfigEditorInterface
* [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now * [BC BREAK] the method `buildForm` in FormTypeInterface and FormTypeExtensionInterface
receive FormBuilderInterface and FormViewInterface instead of FormBuilder and now receives a FormBuilderInterface instead of a FormBuilder instance
FormView
* [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in * [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in
FormTypeInterface and FormTypeExtensionInterface FormTypeInterface and FormTypeExtensionInterface
* [BC BREAK] the options array is now passed as last argument of the * [BC BREAK] the options array is now passed as last argument of the
@ -134,8 +131,6 @@ CHANGELOG
FormEvents::BIND_NORM_DATA FormEvents::BIND_NORM_DATA
* [BC BREAK] reversed the order of the first two arguments to `createNamed` * [BC BREAK] reversed the order of the first two arguments to `createNamed`
and `createNamedBuilder` in `FormFactoryInterface` and `createNamedBuilder` in `FormFactoryInterface`
* [BC BREAK] adapted methods of FormView to match the naming used in
FormInterface and FormBuilder
* deprecated `getChildren` in Form and FormBuilder in favor of `all` * deprecated `getChildren` in Form and FormBuilder in favor of `all`
* deprecated `hasChildren` in Form and FormBuilder in favor of `count` * deprecated `hasChildren` in Form and FormBuilder in favor of `count`
* FormBuilder now implements \IteratorAggregate * FormBuilder now implements \IteratorAggregate
@ -178,4 +173,5 @@ CHANGELOG
* `toArrayKeys` * `toArrayKeys`
* `isChoiceGroup` * `isChoiceGroup`
* `isChoiceSelected` * `isChoiceSelected`
* added method `block` to FormHelper and deprecated `renderBlock` instead * [BC BREAK] renamed method `renderBlock` in FormHelper to `block` and changed its signature
* made FormView properties public and deprecated their accessor methods

View File

@ -240,27 +240,19 @@ class ChoiceList implements ChoiceListInterface
* view objects. * view objects.
* @param array $bucketForRemaining The bucket where to store the * @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects. * non-preferred view objects.
* @param array $choices The list of choices. * @param array $choices The list of choices.
* @param array $labels The labels corresponding to the choices. * @param array $labels The labels corresponding to the choices.
* @param array $preferredChoices The preferred choices. * @param array $preferredChoices The preferred choices.
* *
* @throws UnexpectedTypeException If the structure of the $labels array * @throws UnexpectedTypeException If the structure of the $labels array
* does not match the structure of the * does not match the structure of the
* $choices array. * $choices array.
*/ */
protected function addChoices(&$bucketForPreferred, &$bucketForRemaining, $choices, $labels, array $preferredChoices) protected function addChoices(&$bucketForPreferred, &$bucketForRemaining, array $choices, array $labels, array $preferredChoices)
{ {
if (!is_array($choices) && !$choices instanceof \Traversable) {
throw new UnexpectedTypeException($choices, 'array or \Traversable');
}
// Add choices to the nested buckets // Add choices to the nested buckets
foreach ($choices as $group => $choice) { foreach ($choices as $group => $choice) {
if (is_array($choice)) { if (is_array($choice)) {
if (!is_array($labels)) {
throw new UnexpectedTypeException($labels, 'array');
}
// Don't do the work if the array is empty // Don't do the work if the array is empty
if (count($choice) > 0) { if (count($choice) > 0) {
$this->addChoiceGroup( $this->addChoiceGroup(
@ -292,11 +284,11 @@ class ChoiceList implements ChoiceListInterface
* view objects. * view objects.
* @param array $bucketForRemaining The bucket where to store the * @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects. * non-preferred view objects.
* @param array $choices The list of choices in the group. * @param array $choices The list of choices in the group.
* @param array $labels The labels corresponding to the choices in the group. * @param array $labels The labels corresponding to the choices in the group.
* @param array $preferredChoices The preferred choices. * @param array $preferredChoices The preferred choices.
*/ */
protected function addChoiceGroup($group, &$bucketForPreferred, &$bucketForRemaining, $choices, $labels, array $preferredChoices) protected function addChoiceGroup($group, &$bucketForPreferred, &$bucketForRemaining, array $choices, array $labels, array $preferredChoices)
{ {
// If this is a choice group, create a new level in the choice // If this is a choice group, create a new level in the choice
// key hierarchy // key hierarchy
@ -323,13 +315,15 @@ class ChoiceList implements ChoiceListInterface
/** /**
* Adds a new choice. * Adds a new choice.
* *
* @param array $bucketForPreferred The bucket where to store the preferred * @param array $bucketForPreferred The bucket where to store the preferred
* view objects. * view objects.
* @param array $bucketForRemaining The bucket where to store the * @param array $bucketForRemaining The bucket where to store the
* non-preferred view objects. * non-preferred view objects.
* @param mixed $choice The choice to add. * @param mixed $choice The choice to add.
* @param string $label The label for the choice. * @param string $label The label for the choice.
* @param array $preferredChoices The preferred choices. * @param array $preferredChoices The preferred choices.
*
* @throws InvalidConfigurationException If no valid value or index could be created.
*/ */
protected function addChoice(&$bucketForPreferred, &$bucketForRemaining, $choice, $label, array $preferredChoices) protected function addChoice(&$bucketForPreferred, &$bucketForRemaining, $choice, $label, array $preferredChoices)
{ {
@ -366,8 +360,10 @@ class ChoiceList implements ChoiceListInterface
* *
* @param mixed $choice The choice to test. * @param mixed $choice The choice to test.
* @param array $preferredChoices An array of preferred choices. * @param array $preferredChoices An array of preferred choices.
*
* @return Boolean Whether the choice is preferred.
*/ */
protected function isPreferred($choice, $preferredChoices) protected function isPreferred($choice, array $preferredChoices)
{ {
return false !== array_search($choice, $preferredChoices, true); return false !== array_search($choice, $preferredChoices, true);
} }

View File

@ -89,7 +89,7 @@ class SimpleChoiceList extends ChoiceList
* *
* @see parent::addChoices * @see parent::addChoices
*/ */
protected function addChoices(&$bucketForPreferred, &$bucketForRemaining, $choices, $labels, array $preferredChoices) protected function addChoices(&$bucketForPreferred, &$bucketForRemaining, array $choices, array $labels, array $preferredChoices)
{ {
// Add choices to the nested buckets // Add choices to the nested buckets
foreach ($choices as $choice => $label) { foreach ($choices as $choice => $label) {
@ -126,8 +126,10 @@ class SimpleChoiceList extends ChoiceList
* *
* @param mixed $choice The choice to test. * @param mixed $choice The choice to test.
* @param array $preferredChoices An array of preferred choices. * @param array $preferredChoices An array of preferred choices.
*
* @return Boolean Whether the choice is preferred.
*/ */
protected function isPreferred($choice, $preferredChoices) protected function isPreferred($choice, array $preferredChoices)
{ {
// Optimize performance over the default implementation // Optimize performance over the default implementation
return isset($preferredChoices[$choice]); return isset($preferredChoices[$choice]);

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class CheckboxType extends AbstractType class CheckboxType extends AbstractType
@ -33,9 +33,9 @@ class CheckboxType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->addVars(array( $view->vars = array_replace($view->vars, array(
'value' => $options['value'], 'value' => $options['value'],
'checked' => null !== $form->getViewData(), 'checked' => null !== $form->getViewData(),
)); ));

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList; use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
@ -79,9 +79,9 @@ class ChoiceType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->addVars(array( $view->vars = array_replace($view->vars, array(
'multiple' => $options['multiple'], 'multiple' => $options['multiple'],
'expanded' => $options['expanded'], 'expanded' => $options['expanded'],
'preferred_choices' => $options['choice_list']->getPreferredViews(), 'preferred_choices' => $options['choice_list']->getPreferredViews(),
@ -90,28 +90,42 @@ class ChoiceType extends AbstractType
'empty_value' => null, 'empty_value' => null,
)); ));
// The decision, whether a choice is selected, is potentially done
// thousand of times during the rendering of a template. Provide a
// closure here that is optimized for the value of the form, to
// avoid making the type check inside the closure.
if ($options['multiple']) {
$view->vars['is_selected'] = function ($choice, array $values) {
return false !== array_search($choice, $values, true);
};
} else {
$view->vars['is_selected'] = function ($choice, $value) {
return $choice === $value;
};
}
// Check if the choices already contain the empty value // Check if the choices already contain the empty value
// Only add the empty value option if this is not the case // Only add the empty value option if this is not the case
if (0 === count($options['choice_list']->getIndicesForValues(array('')))) { if (0 === count($options['choice_list']->getIndicesForValues(array('')))) {
$view->setVar('empty_value', $options['empty_value']); $view->vars['empty_value'] = $options['empty_value'];
} }
if ($options['multiple'] && !$options['expanded']) { if ($options['multiple'] && !$options['expanded']) {
// Add "[]" to the name in case a select tag with multiple options is // Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the // displayed. Otherwise only one of the selected options is sent in the
// POST request. // POST request.
$view->setVar('full_name', $view->getVar('full_name').'[]'); $view->vars['full_name'] = $view->vars['full_name'].'[]';
} }
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
if ($options['expanded']) { if ($options['expanded']) {
// Radio buttons should have the same name as the parent // Radio buttons should have the same name as the parent
$childName = $view->getVar('full_name'); $childName = $view->vars['full_name'];
// Checkboxes should append "[]" to allow multiple selection // Checkboxes should append "[]" to allow multiple selection
if ($options['multiple']) { if ($options['multiple']) {
@ -119,7 +133,7 @@ class ChoiceType extends AbstractType
} }
foreach ($view as $childView) { foreach ($view as $childView) {
$childView->setVar('full_name', $childName); $childView->vars['full_name'] = $childName;
} }
} }
} }
@ -226,8 +240,8 @@ class ChoiceType extends AbstractType
$this->addSubForms($builder, $choiceView, $options); $this->addSubForms($builder, $choiceView, $options);
} else { } else {
$choiceOpts = array( $choiceOpts = array(
'value' => $choiceView->getValue(), 'value' => $choiceView->value,
'label' => $choiceView->getLabel(), 'label' => $choiceView->label,
'translation_domain' => $options['translation_domain'], 'translation_domain' => $options['translation_domain'],
); );

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener; use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\Options;
@ -47,25 +47,25 @@ class CollectionType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->addVars(array( $view->vars = array_replace($view->vars, array(
'allow_add' => $options['allow_add'], 'allow_add' => $options['allow_add'],
'allow_delete' => $options['allow_delete'], 'allow_delete' => $options['allow_delete'],
)); ));
if ($form->getConfig()->hasAttribute('prototype')) { if ($form->getConfig()->hasAttribute('prototype')) {
$view->setVar('prototype', $form->getConfig()->getAttribute('prototype')->createView($view)); $view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
} }
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
if ($form->getConfig()->hasAttribute('prototype') && $view->getVar('prototype')->getVar('multipart')) { if ($form->getConfig()->hasAttribute('prototype') && $view->vars['prototype']->vars['multipart']) {
$view->setVar('multipart', true); $view->vars['multipart'] = true;
} }
} }

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\ReversedTransformer; use Symfony\Component\Form\ReversedTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
@ -174,15 +174,15 @@ class DateTimeType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->setVar('widget', $options['widget']); $view->vars['widget'] = $options['widget'];
// Change the input to a HTML5 date input if // Change the input to a HTML5 date input if
// * the widget is set to "single_text" // * the widget is set to "single_text"
// * the format matches the one expected by HTML5 // * the format matches the one expected by HTML5
if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) { if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
$view->setVar('type', 'datetime'); $view->vars['type'] = 'datetime';
} }
} }

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Exception\CreationException; use Symfony\Component\Form\Exception\CreationException;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
@ -124,15 +124,15 @@ class DateType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
$view->setVar('widget', $options['widget']); $view->vars['widget'] = $options['widget'];
// Change the input to a HTML5 date input if // Change the input to a HTML5 date input if
// * the widget is set to "single_text" // * the widget is set to "single_text"
// * the format matches the one expected by HTML5 // * the format matches the one expected by HTML5
if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) { if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
$view->setVar('type', 'date'); $view->vars['type'] = 'date';
} }
if ($form->getConfig()->hasAttribute('formatter')) { if ($form->getConfig()->hasAttribute('formatter')) {
@ -147,7 +147,7 @@ class DateType extends AbstractType
$pattern = '{{ year }}-{{ month }}-{{ day }}'; $pattern = '{{ year }}-{{ month }}-{{ day }}';
} }
$view->setVar('date_pattern', $pattern); $view->vars['date_pattern'] = $pattern;
} }
} }

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class FileType extends AbstractType class FileType extends AbstractType
@ -21,9 +21,9 @@ class FileType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->addVars(array( $view->vars = array_replace($view->vars, array(
'type' => 'file', 'type' => 'file',
'value' => '', 'value' => '',
)); ));
@ -32,10 +32,10 @@ class FileType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
$view $view
->setVar('multipart', true) ->vars['multipart'] = true
; ;
} }

View File

@ -16,7 +16,7 @@ use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\EventListener\BindRequestListener; use Symfony\Component\Form\Extension\Core\EventListener\BindRequestListener;
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
@ -56,24 +56,22 @@ class FormType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$name = $form->getName(); $name = $form->getName();
$blockName = $options['block_name'] ?: $form->getName(); $blockName = $options['block_name'] ?: $form->getName();
$readOnly = $options['read_only']; $readOnly = $options['read_only'];
$translationDomain = $options['translation_domain']; $translationDomain = $options['translation_domain'];
if ($view->hasParent()) { if ($view->parent) {
if ('' === $name) { if ('' === $name) {
throw new FormException('Form node with empty name can be used only as root form node.'); throw new FormException('Form node with empty name can be used only as root form node.');
} }
$parentView = $view->getParent(); if ('' !== ($parentFullName = $view->parent->vars['full_name'])) {
$id = sprintf('%s_%s', $view->parent->vars['id'], $name);
if ('' !== ($parentFullName = $parentView->getVar('full_name'))) {
$id = sprintf('%s_%s', $parentView->getVar('id'), $name);
$fullName = sprintf('%s[%s]', $parentFullName, $name); $fullName = sprintf('%s[%s]', $parentFullName, $name);
$fullBlockName = sprintf('%s_%s', $parentView->getVar('full_block_name'), $blockName); $fullBlockName = sprintf('%s_%s', $view->parent->vars['full_block_name'], $blockName);
} else { } else {
$id = $name; $id = $name;
$fullName = $name; $fullName = $name;
@ -82,11 +80,11 @@ class FormType extends AbstractType
// Complex fields are read-only if they themselves or their parents are. // Complex fields are read-only if they themselves or their parents are.
if (!$readOnly) { if (!$readOnly) {
$readOnly = $parentView->getVar('read_only'); $readOnly = $view->parent->vars['read_only'];
} }
if (!$translationDomain) { if (!$translationDomain) {
$translationDomain = $parentView->getVar('translation_domain'); $translationDomain = $view->parent->vars['translation_domain'];
} }
} else { } else {
$id = $name; $id = $name;
@ -108,7 +106,7 @@ class FormType extends AbstractType
$translationDomain = 'messages'; $translationDomain = 'messages';
} }
$view->addVars(array( $view->vars = array_replace($view->vars, array(
'form' => $view, 'form' => $view,
'id' => $id, 'id' => $id,
'name' => $name, 'name' => $name,
@ -136,18 +134,18 @@ class FormType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
$multipart = false; $multipart = false;
foreach ($view as $child) { foreach ($view->children as $child) {
if ($child->getVar('multipart')) { if ($child->vars['multipart']) {
$multipart = true; $multipart = true;
break; break;
} }
} }
$view->setVar('multipart', $multipart); $view->vars['multipart'] = $multipart;
} }
/** /**

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class MoneyType extends AbstractType class MoneyType extends AbstractType
@ -40,9 +40,9 @@ class MoneyType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->setVar('money_pattern', self::getPattern($options['currency'])); $view->vars['money_pattern'] = self::getPattern($options['currency']);
} }
/** /**

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PasswordType extends AbstractType class PasswordType extends AbstractType
@ -21,10 +21,10 @@ class PasswordType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
if ($options['always_empty'] || !$form->isBound()) { if ($options['always_empty'] || !$form->isBound()) {
$view->setVar('value', ''); $view->vars['value'] = '';
} }
} }

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\Type; namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
class TextareaType extends AbstractType class TextareaType extends AbstractType
@ -20,9 +20,9 @@ class TextareaType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->setVar('pattern', null); $view->vars['pattern'] = null;
} }
/** /**

View File

@ -18,7 +18,7 @@ use Symfony\Component\Form\ReversedTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@ -109,15 +109,15 @@ class TimeType extends AbstractType
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormView $view, FormInterface $form, array $options)
{ {
$view->addVars(array( $view->vars = array_replace($view->vars, array(
'widget' => $options['widget'], 'widget' => $options['widget'],
'with_seconds' => $options['with_seconds'], 'with_seconds' => $options['with_seconds'],
)); ));
if ('single_text' === $options['widget']) { if ('single_text' === $options['widget']) {
$view->setVar('type', 'time'); $view->vars['type'] = 'time';
} }
} }

View File

@ -23,14 +23,14 @@ class ChoiceView
* *
* @var string * @var string
*/ */
private $value; public $value;
/** /**
* The label displayed to humans. * The label displayed to humans.
* *
* @var string * @var string
*/ */
private $label; public $label;
/** /**
* Creates a new ChoiceView. * Creates a new ChoiceView.
@ -45,22 +45,18 @@ class ChoiceView
} }
/** /**
* Returns the choice value. * Returns whether this choice is selected for the given value.
* *
* @return string The view representation of the choice. * @param string|array $value The selected choice value.
*
* @return Boolean Whether the choice is selected.
*/ */
public function getValue() public function isSelected($value)
{ {
return $this->value; if (is_array($value)) {
} return false !== array_search($this->value, $value, true);
}
/** return $this->value === $value;
* Returns the choice label.
*
* @return string The label displayed to humans.
*/
public function getLabel()
{
return $this->label;
} }
} }

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener; use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@ -59,9 +59,9 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
* @param FormView $view The form view * @param FormView $view The form view
* @param FormInterface $form The form * @param FormInterface $form The form
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormView $view, FormInterface $form, array $options)
{ {
if ($options['csrf_protection'] && !$view->hasParent() && $options['compound']) { if ($options['csrf_protection'] && !$view->parent && $options['compound']) {
$factory = $form->getConfig()->getAttribute('csrf_factory'); $factory = $form->getConfig()->getAttribute('csrf_factory');
$data = $options['csrf_provider']->generateCsrfToken($options['intention']); $data = $options['csrf_provider']->generateCsrfToken($options['intention']);
@ -69,7 +69,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
'mapped' => false, 'mapped' => false,
)); ));
$view->add($csrfForm->createView($view)); $view->children[$options['csrf_field_name']] = $csrfForm->createView($view);
} }
} }

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Extension\Templating; namespace Symfony\Component\Form\Extension\Templating;
use Symfony\Component\Form\AbstractRendererEngine; use Symfony\Component\Form\AbstractRendererEngine;
use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormView;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
/** /**
@ -35,7 +35,7 @@ class TemplatingRendererEngine extends AbstractRendererEngine
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array()) public function renderBlock(FormView $view, $resource, $blockName, array $variables = array())
{ {
return trim($this->engine->render($resource, $variables)); return trim($this->engine->render($resource, $variables));
} }
@ -48,13 +48,13 @@ class TemplatingRendererEngine extends AbstractRendererEngine
* *
* @see getResourceForBlock() * @see getResourceForBlock()
* *
* @param string $cacheKey The cache key of the form view. * @param string $cacheKey The cache key of the form view.
* @param FormViewInterface $view The form view for finding the applying themes. * @param FormView $view The form view for finding the applying themes.
* @param string $block The name of the block to load. * @param string $blockName The name of the block to load.
* *
* @return Boolean True if the resource could be loaded, false otherwise. * @return Boolean True if the resource could be loaded, false otherwise.
*/ */
protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block) protected function loadResourceForBlockName($cacheKey, FormView $view, $blockName)
{ {
// Recursively try to find the block in the themes assigned to $view, // Recursively try to find the block in the themes assigned to $view,
// then of its parent form, then of the parent form of the parent and so on. // then of its parent form, then of the parent form of the parent and so on.
@ -64,16 +64,16 @@ class TemplatingRendererEngine extends AbstractRendererEngine
// Check each theme whether it contains the searched block // Check each theme whether it contains the searched block
if (isset($this->themes[$cacheKey])) { if (isset($this->themes[$cacheKey])) {
for ($i = count($this->themes[$cacheKey]) - 1; $i >= 0; --$i) { for ($i = count($this->themes[$cacheKey]) - 1; $i >= 0; --$i) {
if ($this->loadResourceFromTheme($cacheKey, $block, $this->themes[$cacheKey][$i])) { if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->themes[$cacheKey][$i])) {
return true; return true;
} }
} }
} }
// Check the default themes once we reach the root form without success // Check the default themes once we reach the root form without success
if (!$view->hasParent()) { if (!$view->parent) {
for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) { for ($i = count($this->defaultThemes) - 1; $i >= 0; --$i) {
if ($this->loadResourceFromTheme($cacheKey, $block, $this->defaultThemes[$i])) { if ($this->loadResourceFromTheme($cacheKey, $blockName, $this->defaultThemes[$i])) {
return true; return true;
} }
} }
@ -81,24 +81,24 @@ class TemplatingRendererEngine extends AbstractRendererEngine
// If we did not find anything in the themes of the current view, proceed // If we did not find anything in the themes of the current view, proceed
// with the themes of the parent view // with the themes of the parent view
if ($view->hasParent()) { if ($view->parent) {
$parentCacheKey = $view->getParent()->getVar(self::CACHE_KEY_VAR); $parentCacheKey = $view->parent->vars[self::CACHE_KEY_VAR];
if (!isset($this->resources[$parentCacheKey][$block])) { if (!isset($this->resources[$parentCacheKey][$blockName])) {
$this->loadResourceForBlock($parentCacheKey, $view->getParent(), $block); $this->loadResourceForBlockName($parentCacheKey, $view->parent, $blockName);
} }
// If a template exists in the parent themes, cache that template // If a template exists in the parent themes, cache that template
// for the current theme as well to speed up further accesses // for the current theme as well to speed up further accesses
if ($this->resources[$parentCacheKey][$block]) { if ($this->resources[$parentCacheKey][$blockName]) {
$this->resources[$cacheKey][$block] = $this->resources[$parentCacheKey][$block]; $this->resources[$cacheKey][$blockName] = $this->resources[$parentCacheKey][$blockName];
return true; return true;
} }
} }
// Cache that we didn't find anything to speed up further accesses // Cache that we didn't find anything to speed up further accesses
$this->resources[$cacheKey][$block] = false; $this->resources[$cacheKey][$blockName] = false;
return false; return false;
} }
@ -106,16 +106,16 @@ class TemplatingRendererEngine extends AbstractRendererEngine
/** /**
* Tries to load the resource for a block from a theme. * Tries to load the resource for a block from a theme.
* *
* @param string $cacheKey The cache key for storing the resource. * @param string $cacheKey The cache key for storing the resource.
* @param string $block The name of the block to load a resource for. * @param string $blockName The name of the block to load a resource for.
* @param mixed $theme The theme to load the block from. * @param mixed $theme The theme to load the block from.
* *
* @return Boolean True if the resource could be loaded, false otherwise. * @return Boolean True if the resource could be loaded, false otherwise.
*/ */
protected function loadResourceFromTheme($cacheKey, $block, $theme) protected function loadResourceFromTheme($cacheKey, $blockName, $theme)
{ {
if ($this->engine->exists($templateName = $theme . ':' . $block . '.html.php')) { if ($this->engine->exists($templateName = $theme . ':' . $blockName . '.html.php')) {
$this->resources[$cacheKey][$block] = $templateName; $this->resources[$cacheKey][$blockName] = $templateName;
return true; return true;
} }

View File

@ -1015,7 +1015,7 @@ class Form implements \IteratorAggregate, FormInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createView(FormViewInterface $parent = null) public function createView(FormView $parent = null)
{ {
if (null === $parent && $this->parent) { if (null === $parent && $this->parent) {
$parent = $this->parent->createView(); $parent = $this->parent->createView();

View File

@ -238,9 +238,9 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
/** /**
* Creates a view. * Creates a view.
* *
* @param FormViewInterface $parent The parent view * @param FormView $parent The parent view
* *
* @return FormViewInterface The view * @return FormView The view
*/ */
public function createView(FormViewInterface $parent = null); public function createView(FormView $parent = null);
} }

View File

@ -35,7 +35,7 @@ class FormRenderer implements FormRendererInterface
/** /**
* @var array * @var array
*/ */
private $blockHierarchyMap = array(); private $blockNameHierarchyMap = array();
/** /**
* @var array * @var array
@ -50,7 +50,7 @@ class FormRenderer implements FormRendererInterface
/** /**
* @var array * @var array
*/ */
private $stack = array(); private $variableStack = array();
public function __construct(FormRendererEngineInterface $engine, CsrfProviderInterface $csrfProvider = null) public function __construct(FormRendererEngineInterface $engine, CsrfProviderInterface $csrfProvider = null)
{ {
@ -69,63 +69,11 @@ class FormRenderer implements FormRendererInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setTheme(FormViewInterface $view, $themes) public function setTheme(FormView $view, $themes)
{ {
$this->engine->setTheme($view, $themes); $this->engine->setTheme($view, $themes);
} }
/**
* {@inheritdoc}
*/
public function renderEnctype(FormViewInterface $view)
{
return $this->renderSection($view, 'enctype');
}
/**
* {@inheritdoc}
*/
public function renderRow(FormViewInterface $view, array $variables = array())
{
return $this->renderSection($view, 'row', $variables);
}
/**
* {@inheritdoc}
*/
public function renderRest(FormViewInterface $view, array $variables = array())
{
return $this->renderSection($view, 'rest', $variables);
}
/**
* {@inheritdoc}
*/
public function renderWidget(FormViewInterface $view, array $variables = array())
{
return $this->renderSection($view, 'widget', $variables);
}
/**
* {@inheritdoc}
*/
public function renderErrors(FormViewInterface $view)
{
return $this->renderSection($view, 'errors');
}
/**
* {@inheritdoc}
*/
public function renderLabel(FormViewInterface $view, $label = null, array $variables = array())
{
if ($label !== null) {
$variables += array('label' => $label);
}
return $this->renderSection($view, 'label', $variables);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -141,18 +89,18 @@ class FormRenderer implements FormRendererInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderBlock($block, array $variables = array()) public function renderBlock(FormView $view, $blockName, array $variables = array())
{ {
if (0 == count($this->stack)) { if (0 == count($this->variableStack)) {
throw new FormException('This method should only be called while rendering a form element.'); throw new FormException('This method should only be called while rendering a form element.');
} }
list($view, $scopeVariables) = end($this->stack); $scopeVariables = end($this->variableStack);
$resource = $this->engine->getResourceForBlock($view, $block); $resource = $this->engine->getResourceForBlockName($view, $blockName);
if (!$resource) { if (!$resource) {
throw new FormException(sprintf('No block "%s" found while rendering the form.', $block)); throw new FormException(sprintf('No block "%s" found while rendering the form.', $blockName));
} }
// Merge the passed with the existing attributes // Merge the passed with the existing attributes
@ -169,61 +117,30 @@ class FormRenderer implements FormRendererInterface
// cannot be overwritten // cannot be overwritten
$variables = array_replace($scopeVariables, $variables); $variables = array_replace($scopeVariables, $variables);
return $this->engine->renderBlock($view, $resource, $block, $variables); $this->variableStack[] = $variables;
// Do the rendering
$html = $this->engine->renderBlock($view, $resource, $blockName, $variables);
// Clear the stack
array_pop($this->variableStack);
return $html;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isChoiceGroup($choice) public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $variables = array())
{ {
return is_array($choice) || $choice instanceof \Traversable; $renderOnlyOnce = in_array($blockNameSuffix, array('row', 'widget'));
}
/**
* {@inheritdoc}
*/
public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice)
{
$value = $view->getVar('value');
$choiceValue = $choice->getValue();
if (is_array($value)) {
return false !== array_search($choiceValue, $value, true);
}
return $choiceValue === $value;
}
/**
* {@inheritdoc}
*/
public function humanize($text)
{
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
}
/**
* Renders the given section of a form view.
*
* @param FormViewInterface $view The form view.
* @param string $section The name of the section to render.
* @param array $variables The variables to pass to the template.
*
* @return string The HTML markup.
*
* @throws Exception\FormException If no fitting template was found.
*/
protected function renderSection(FormViewInterface $view, $section, array $variables = array())
{
$renderOnlyOnce = in_array($section, array('row', 'widget'));
if ($renderOnlyOnce && $view->isRendered()) { if ($renderOnlyOnce && $view->isRendered()) {
return ''; return '';
} }
// The cache key for storing the variables and types // The cache key for storing the variables and types
$mapKey = $uniqueBlockName = $view->getVar('full_block_name') . '_' . $section; $mapKey = $uniqueBlockName = $view->vars['full_block_name'] . '_' . $blockNameSuffix;
// In templates, we have to deal with two kinds of block hierarchies: // In templates, we have to deal with two kinds of block hierarchies:
// //
@ -252,25 +169,25 @@ class FormRenderer implements FormRendererInterface
// widget() function again to render the block for the parent type. // widget() function again to render the block for the parent type.
// //
// The second kind is implemented in the following blocks. // The second kind is implemented in the following blocks.
if (!isset($this->blockHierarchyMap[$mapKey])) { if (!isset($this->blockNameHierarchyMap[$mapKey])) {
// INITIAL CALL // INITIAL CALL
// Calculate the hierarchy of template blocks and start on // Calculate the hierarchy of template blocks and start on
// the bottom level of the hierarchy (= "_<id>_<section>" block) // the bottom level of the hierarchy (= "_<id>_<section>" block)
$blockHierarchy = array(); $blockNameHierarchy = array();
foreach ($view->getVar('types') as $type) { foreach ($view->vars['types'] as $type) {
$blockHierarchy[] = $type . '_' . $section; $blockNameHierarchy[] = $type . '_' . $blockNameSuffix;
} }
$blockHierarchy[] = $uniqueBlockName; $blockNameHierarchy[] = $uniqueBlockName;
$hierarchyLevel = count($blockHierarchy) - 1; $hierarchyLevel = count($blockNameHierarchy) - 1;
// The default variable scope contains all view variables, merged with // The default variable scope contains all view variables, merged with
// the variables passed explicitly to the helper // the variables passed explicitly to the helper
$scopeVariables = $view->getVars(); $scopeVariables = $view->vars;
} else { } else {
// RECURSIVE CALL // RECURSIVE CALL
// If a block recursively calls renderSection() again, resume rendering // If a block recursively calls renderSection() again, resume rendering
// using the parent type in the hierarchy. // using the parent type in the hierarchy.
$blockHierarchy = $this->blockHierarchyMap[$mapKey]; $blockNameHierarchy = $this->blockNameHierarchyMap[$mapKey];
$hierarchyLevel = $this->hierarchyLevelMap[$mapKey] - 1; $hierarchyLevel = $this->hierarchyLevelMap[$mapKey] - 1;
// Reuse the current scope and merge it with the explicitly passed variables // Reuse the current scope and merge it with the explicitly passed variables
@ -278,22 +195,22 @@ class FormRenderer implements FormRendererInterface
} }
// Load the resource where this block can be found // Load the resource where this block can be found
$resource = $this->engine->getResourceForBlockHierarchy($view, $blockHierarchy, $hierarchyLevel); $resource = $this->engine->getResourceForBlockNameHierarchy($view, $blockNameHierarchy, $hierarchyLevel);
// Update the current hierarchy level to the one at which the resource was // Update the current hierarchy level to the one at which the resource was
// found. For example, if looking for "choice_widget", but only a resource // found. For example, if looking for "choice_widget", but only a resource
// is found for its parent "form_widget", then the level is updated here // is found for its parent "form_widget", then the level is updated here
// to the parent level. // to the parent level.
$hierarchyLevel = $this->engine->getResourceHierarchyLevel($view, $blockHierarchy, $hierarchyLevel); $hierarchyLevel = $this->engine->getResourceHierarchyLevel($view, $blockNameHierarchy, $hierarchyLevel);
// The actually existing block name in $resource // The actually existing block name in $resource
$block = $blockHierarchy[$hierarchyLevel]; $blockName = $blockNameHierarchy[$hierarchyLevel];
// Escape if no resource exists for this block // Escape if no resource exists for this block
if (!$resource) { if (!$resource) {
throw new FormException(sprintf( throw new FormException(sprintf(
'Unable to render the form as none of the following blocks exist: "%s".', 'Unable to render the form as none of the following blocks exist: "%s".',
implode('", "', array_reverse($blockHierarchy)) implode('", "', array_reverse($blockNameHierarchy))
)); ));
} }
@ -318,7 +235,7 @@ class FormRenderer implements FormRendererInterface
// We need to store these values in maps (associative arrays) because within a // We need to store these values in maps (associative arrays) because within a
// call to widget() another call to widget() can be made, but for a different view // call to widget() another call to widget() can be made, but for a different view
// object. These nested calls should not override each other. // object. These nested calls should not override each other.
$this->blockHierarchyMap[$mapKey] = $blockHierarchy; $this->blockNameHierarchyMap[$mapKey] = $blockNameHierarchy;
$this->hierarchyLevelMap[$mapKey] = $hierarchyLevel; $this->hierarchyLevelMap[$mapKey] = $hierarchyLevel;
$this->variableMap[$mapKey] = $variables; $this->variableMap[$mapKey] = $variables;
@ -328,16 +245,16 @@ class FormRenderer implements FormRendererInterface
// //
// A stack is sufficient for this purpose, because renderBlock() always accesses // A stack is sufficient for this purpose, because renderBlock() always accesses
// the immediate next outer scope, which is always stored at the end of the stack. // the immediate next outer scope, which is always stored at the end of the stack.
$this->stack[] = array($view, $variables); $this->variableStack[] = $variables;
// Do the rendering // Do the rendering
$html = $this->engine->renderBlock($view, $resource, $block, $variables); $html = $this->engine->renderBlock($view, $resource, $blockName, $variables);
// Clear the stack // Clear the stack
array_pop($this->stack); array_pop($this->variableStack);
// Clear the maps // Clear the maps
unset($this->blockHierarchyMap[$mapKey]); unset($this->blockNameHierarchyMap[$mapKey]);
unset($this->hierarchyLevelMap[$mapKey]); unset($this->hierarchyLevelMap[$mapKey]);
unset($this->variableMap[$mapKey]); unset($this->variableMap[$mapKey]);
@ -347,4 +264,12 @@ class FormRenderer implements FormRendererInterface
return $html; return $html;
} }
/**
* {@inheritdoc}
*/
public function humanize($text)
{
return ucfirst(trim(strtolower(preg_replace('/[_\s]+/', ' ', $text))));
}
} }

View File

@ -21,11 +21,11 @@ interface FormRendererEngineInterface
/** /**
* Sets the theme(s) to be used for rendering a view and its children. * Sets the theme(s) to be used for rendering a view and its children.
* *
* @param FormViewInterface $view The view to assign the theme(s) to. * @param FormView $view The view to assign the theme(s) to.
* @param mixed $themes The theme(s). The type of these themes * @param mixed $themes The theme(s). The type of these themes
* is open to the implementation. * is open to the implementation.
*/ */
public function setTheme(FormViewInterface $view, $themes); public function setTheme(FormView $view, $themes);
/** /**
* Returns the resource for a block name. * Returns the resource for a block name.
@ -36,15 +36,15 @@ interface FormRendererEngineInterface
* The type of the resource is decided by the implementation. The resource * The type of the resource is decided by the implementation. The resource
* is later passed to {@link renderBlock()} by the rendering algorithm. * is later passed to {@link renderBlock()} by the rendering algorithm.
* *
* @param FormViewInterface $view The view for determining the used themes. * @param FormView $view The view for determining the used themes.
* First the themes attached directly to the * First the themes attached directly to the
* view with {@link setTheme()} are considered, * view with {@link setTheme()} are considered,
* then the ones of its parent etc. * then the ones of its parent etc.
* @param string $block The name of the block to render. * @param string $blockName The name of the block to render.
* *
* @return mixed The renderer resource or false, if none was found. * @return mixed The renderer resource or false, if none was found.
*/ */
public function getResourceForBlock(FormViewInterface $view, $block); public function getResourceForBlockName(FormView $view, $blockName);
/** /**
* Returns the resource for a block hierarchy. * Returns the resource for a block hierarchy.
@ -70,21 +70,23 @@ interface FormRendererEngineInterface
* The type of the resource is decided by the implementation. The resource * The type of the resource is decided by the implementation. The resource
* is later passed to {@link renderBlock()} by the rendering algorithm. * is later passed to {@link renderBlock()} by the rendering algorithm.
* *
* @param FormViewInterface $view The view for determining the used * @param FormView $view The view for determining the
* themes. First the themes attached * used themes. First the themes
* directly to the view with * attached directly to the view
* {@link setTheme()} are considered, * with {@link setTheme()} are
* then the ones of its parent etc. * considered, then the ones of
* @param array $blockHierarchy The block name hierarchy, with * its parent etc.
* the root block at the beginning. * @param array $blockNameHierarchy The block name hierarchy, with
* @param integer $hierarchyLevel The level in the hierarchy at * the root block at the beginning.
* which to start looking. Level 0 * @param integer $hierarchyLevel The level in the hierarchy at
* indicates the root block, i.e. * which to start looking. Level 0
* the first element of $blockHierarchy. * indicates the root block, i.e.
* the first element of
* $blockNameHierarchy.
* *
* @return mixed The renderer resource or false, if none was found. * @return mixed The renderer resource or false, if none was found.
*/ */
public function getResourceForBlockHierarchy(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel); public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, $hierarchyLevel);
/** /**
* Returns the hierarchy level at which a resource can be found. * Returns the hierarchy level at which a resource can be found.
@ -112,21 +114,23 @@ interface FormRendererEngineInterface
* The type of the resource is decided by the implementation. The resource * The type of the resource is decided by the implementation. The resource
* is later passed to {@link renderBlock()} by the rendering algorithm. * is later passed to {@link renderBlock()} by the rendering algorithm.
* *
* @param FormViewInterface $view The view for determining the used * @param FormView $view The view for determining the
* themes. First the themes attached * used themes. First the themes
* directly to the view with * attached directly to the view
* {@link setTheme()} are considered, * with {@link setTheme()} are
* then the ones of its parent etc. * considered, then the ones of
* @param array $blockHierarchy The block name hierarchy, with * its parent etc.
* the root block at the beginning. * @param array $blockNameHierarchy The block name hierarchy, with
* @param integer $hierarchyLevel The level in the hierarchy at * the root block at the beginning.
* which to start looking. Level 0 * @param integer $hierarchyLevel The level in the hierarchy at
* indicates the root block, i.e. * which to start looking. Level 0
* the first element of $blockHierarchy. * indicates the root block, i.e.
* the first element of
* $blockNameHierarchy.
* *
* @return integer|Boolean The hierarchy level or false, if no resource was found. * @return integer|Boolean The hierarchy level or false, if no resource was found.
*/ */
public function getResourceHierarchyLevel(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel); public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, $hierarchyLevel);
/** /**
* Renders a block in the given renderer resource. * Renders a block in the given renderer resource.
@ -135,12 +139,12 @@ interface FormRendererEngineInterface
* or {@link getResourceForBlockHierarchy()}. The type of the resource is * or {@link getResourceForBlockHierarchy()}. The type of the resource is
* decided by the implementation. * decided by the implementation.
* *
* @param FormViewInterface $view The view to render. * @param FormView $view The view to render.
* @param mixed $resource The renderer resource. * @param mixed $resource The renderer resource.
* @param string $block The name of the block to render. * @param string $blockName The name of the block to render.
* @param array $variables The variables to pass to the template. * @param array $variables The variables to pass to the template.
* *
* @return string The HTML markup. * @return string The HTML markup.
*/ */
public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array()); public function renderBlock(FormView $view, $resource, $blockName, array $variables = array());
} }

View File

@ -30,96 +30,40 @@ interface FormRendererInterface
/** /**
* Sets the theme(s) to be used for rendering a view and its children. * Sets the theme(s) to be used for rendering a view and its children.
* *
* @param FormViewInterface $view The view to assign the theme(s) to. * @param FormView $view The view to assign the theme(s) to.
* @param mixed $themes The theme(s). The type of these themes * @param mixed $themes The theme(s). The type of these themes
* is open to the implementation. * is open to the implementation.
*/ */
public function setTheme(FormViewInterface $view, $themes); public function setTheme(FormView $view, $themes);
/**
* Renders the HTML enctype in the form tag, if necessary.
*
* Example usage templates:
*
* <form action="..." method="post" <?php echo $renderer->renderEnctype($form) ?>>
*
* @param FormViewInterface $view The view for which to render the encoding type
*
* @return string The HTML markup
*/
public function renderEnctype(FormViewInterface $view);
/**
* Renders the entire row for a form field.
*
* A row typically contains the label, errors and widget of a field.
*
* @param FormViewInterface $view The view for which to render the row
* @param array $variables Additional variables passed to the template
*
* @return string The HTML markup
*/
public function renderRow(FormViewInterface $view, array $variables = array());
/**
* Renders views which have not already been rendered.
*
* @param FormViewInterface $view The parent view
* @param array $variables An array of variables
*
* @return string The HTML markup
*/
public function renderRest(FormViewInterface $view, array $variables = array());
/**
* Renders the HTML for a given view.
*
* Example usage:
*
* <?php echo $renderer->renderWidget($form) ?>
*
* You can pass options during the call:
*
* <?php echo $renderer->renderWidget($form, array('attr' => array('class' => 'foo'))) ?>
*
* <?php echo $renderer->renderWidget($form, array('separator' => '+++++)) ?>
*
* @param FormViewInterface $view The view for which to render the widget
* @param array $variables Additional variables passed to the template
*
* @return string The HTML markup
*/
public function renderWidget(FormViewInterface $view, array $variables = array());
/**
* Renders the errors of the given view.
*
* @param FormViewInterface $view The view to render the errors for
*
* @return string The HTML markup
*/
public function renderErrors(FormViewInterface $view);
/**
* Renders the label of the given view.
*
* @param FormViewInterface $view The view for which to render the label
* @param string $label The label
* @param array $variables Additional variables passed to the template
*
* @return string The HTML markup
*/
public function renderLabel(FormViewInterface $view, $label = null, array $variables = array());
/** /**
* Renders a named block of the form theme. * Renders a named block of the form theme.
* *
* @param string $block The name of the block. * @param FormView $view The view for which to render the block.
* @param array $variables The variables to pass to the template. * @param string $blockName The name of the block.
* @param array $variables The variables to pass to the template.
* *
* @return string The HTML markup * @return string The HTML markup
*/ */
public function renderBlock($block, array $variables = array()); public function renderBlock(FormView $view, $blockName, array $variables = array());
/**
* Searches and renders a block for a given name suffix.
*
* The block is searched by combining the block names stored in the
* form view with the given suffix. If a block name is found, that
* block is rendered.
*
* If this method is called recursively, the block search is continued
* where a block was found before.
*
* @param FormView $view The view for which to render the block.
* @param string $blockNameSuffix The suffix of the block name.
* @param array $variables The variables to pass to the template.
*
* @return string The HTML markup
*/
public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $variables = array());
/** /**
* Renders a CSRF token. * Renders a CSRF token.
@ -146,25 +90,6 @@ interface FormRendererInterface
*/ */
public function renderCsrfToken($intention); public function renderCsrfToken($intention);
/**
* Returns whether the given choice is a group.
*
* @param mixed $choice A choice
*
* @return Boolean Whether the choice is a group
*/
public function isChoiceGroup($choice);
/**
* Returns whether the given choice is selected.
*
* @param FormViewInterface $view The view of the choice field
* @param ChoiceView $choice The choice to check
*
* @return Boolean Whether the choice is selected
*/
public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice);
/** /**
* Makes a technical name human readable. * Makes a technical name human readable.
* *

View File

@ -39,11 +39,11 @@ interface FormTypeExtensionInterface
* *
* @see FormTypeInterface::buildView() * @see FormTypeInterface::buildView()
* *
* @param FormViewInterface $view The view * @param FormView $view The view
* @param FormInterface $form The form * @param FormInterface $form The form
* @param array $options The options * @param array $options The options
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options); public function buildView(FormView $view, FormInterface $form, array $options);
/** /**
* Finishes the view. * Finishes the view.
@ -53,11 +53,11 @@ interface FormTypeExtensionInterface
* *
* @see FormTypeInterface::finishView() * @see FormTypeInterface::finishView()
* *
* @param FormViewInterface $view The view * @param FormView $view The view
* @param FormInterface $form The form * @param FormInterface $form The form
* @param array $options The options * @param array $options The options
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options); public function finishView(FormView $view, FormInterface $form, array $options);
/** /**
* Overrides the default options from the extended type. * Overrides the default options from the extended type.

View File

@ -43,11 +43,11 @@ interface FormTypeInterface
* *
* @see FormTypeExtensionInterface::buildView() * @see FormTypeExtensionInterface::buildView()
* *
* @param FormViewInterface $view The view * @param FormView $view The view
* @param FormInterface $form The form * @param FormInterface $form The form
* @param array $options The options * @param array $options The options
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options); public function buildView(FormView $view, FormInterface $form, array $options);
/** /**
* Finishes the form view. * Finishes the form view.
@ -62,11 +62,11 @@ interface FormTypeInterface
* *
* @see FormTypeExtensionInterface::finishView() * @see FormTypeExtensionInterface::finishView()
* *
* @param FormViewInterface $view The view * @param FormView $view The view
* @param FormInterface $form The form * @param FormInterface $form The form
* @param array $options The options * @param array $options The options
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options); public function finishView(FormView $view, FormInterface $form, array $options);
/** /**
* Sets the default options for this type. * Sets the default options for this type.

View File

@ -14,18 +14,28 @@ namespace Symfony\Component\Form;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*/ */
class FormView implements \IteratorAggregate, FormViewInterface class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
{ {
private $name; /**
* The variables assigned to this view.
private $vars = array( * @var array
*/
public $vars = array(
'value' => null, 'value' => null,
'attr' => array(), 'attr' => array(),
); );
private $parent; /**
* The parent view.
* @var FormView
*/
public $parent;
private $children = array(); /**
* The child views.
* @var array
*/
public $children = array();
/** /**
* Is the form attached to this renderer rendered? * Is the form attached to this renderer rendered?
@ -38,23 +48,35 @@ class FormView implements \IteratorAggregate, FormViewInterface
*/ */
private $rendered = false; private $rendered = false;
public function __construct($name) public function __construct(FormView $parent = null)
{ {
$this->name = $name; $this->parent = $parent;
} }
/** /**
* {@inheritdoc} * Returns the name of the form.
*
* @return string The form name.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead which contains an
* entry named "name".
*/ */
public function getName() public function getName()
{ {
return $this->name; return $this->vars['name'];
} }
/** /**
* {@inheritdoc} * @param string $name
* @param mixed $value
*
* @return FormView The current view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/ */
public function setVar($name, $value) public function set($name, $value)
{ {
$this->vars[$name] = $value; $this->vars[$name] = $value;
@ -62,19 +84,30 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * @param $name
*
* @return Boolean
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/ */
public function hasVar($name) public function has($name)
{ {
return array_key_exists($name, $this->vars); return array_key_exists($name, $this->vars);
} }
/** /**
* {@inheritdoc} * @param $name
* @param $default
*
* @return mixed
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/ */
public function getVar($name, $default = null) public function get($name, $default = null)
{ {
if (false === $this->hasVar($name)) { if (false === $this->has($name)) {
return $default; return $default;
} }
@ -82,17 +115,23 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * @return array
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/ */
public function addVars(array $vars) public function all()
{ {
$this->vars = array_replace($this->vars, $vars); return $this->vars;
return $this;
} }
/** /**
* {@inheritdoc} * Returns the values of all view variables.
*
* @return array The values of all variables.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead.
*/ */
public function getVars() public function getVars()
{ {
@ -106,6 +145,10 @@ class FormView implements \IteratorAggregate, FormViewInterface
* @param string $value The value * @param string $value The value
* *
* @return FormView The current view * @return FormView The current view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link vars} instead which contains an
* entry named "attr".
*/ */
public function setAttribute($name, $value) public function setAttribute($name, $value)
{ {
@ -115,7 +158,9 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * Returns whether the view was already rendered.
*
* @return Boolean Whether this view's widget is rendered.
*/ */
public function isRendered() public function isRendered()
{ {
@ -139,7 +184,9 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * Marks the view as rendered.
*
* @return FormView The view object.
*/ */
public function setRendered() public function setRendered()
{ {
@ -149,9 +196,16 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * Sets the parent view.
*
* @param FormView $parent The parent view.
*
* @return FormView The view object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link parent} instead.
*/ */
public function setParent(FormViewInterface $parent = null) public function setParent(FormView $parent = null)
{ {
$this->parent = $parent; $this->parent = $parent;
@ -159,7 +213,12 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * Returns the parent view.
*
* @return FormView The parent view.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link parent} instead.
*/ */
public function getParent() public function getParent()
{ {
@ -167,7 +226,12 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * Returns whether this view has a parent.
*
* @return Boolean Whether this view has a parent
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link parent} instead.
*/ */
public function hasParent() public function hasParent()
{ {
@ -175,42 +239,47 @@ class FormView implements \IteratorAggregate, FormViewInterface
} }
/** /**
* {@inheritdoc} * Sets the children view.
*
* @param array $children The children as instances of FormView
*
* @return FormView The current view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link children} instead.
*/ */
public function add(FormViewInterface $child) public function setChildren(array $children)
{ {
$this->children[$child->getName()] = $child; $this->children = $children;
return $this; return $this;
} }
/** /**
* {@inheritdoc} * Returns the children.
*
* @return array The children as instances of FormView
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link children} instead.
*/ */
public function remove($name) public function getChildren()
{
unset($this->children[$name]);
return $this;
}
/**
* {@inheritdoc}
*/
public function all()
{ {
return $this->children; return $this->children;
} }
/** /**
* {@inheritdoc} * Returns a given child.
*
* @param string $name The name of the child
*
* @return FormView The child view
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Access
* the public property {@link children} instead.
*/ */
public function get($name) public function getChild($name)
{ {
if (!isset($this->children[$name])) {
throw new \InvalidArgumentException(sprintf('Child "%s" does not exist.', $name));
}
return $this->children[$name]; return $this->children[$name];
} }
@ -227,14 +296,6 @@ class FormView implements \IteratorAggregate, FormViewInterface
return count($this->children) > 0; return count($this->children) > 0;
} }
/**
* {@inheritdoc}
*/
public function has($name)
{
return isset($this->children[$name]);
}
/** /**
* Returns a child by name (implements \ArrayAccess). * Returns a child by name (implements \ArrayAccess).
* *
@ -244,7 +305,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
*/ */
public function offsetGet($name) public function offsetGet($name)
{ {
return $this->get($name); return $this->children[$name];
} }
/** /**

View File

@ -1,150 +0,0 @@
<?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;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
{
/**
* Returns the name of the form.
*
* @return string The form name.
*/
public function getName();
/**
* Returns whether the view was already rendered.
*
* @return Boolean Whether this view's widget is rendered.
*/
public function isRendered();
/**
* Marks the view as rendered.
*
* @return FormViewInterface The view object.
*/
public function setRendered();
/**
* Sets the parent view.
*
* @param FormViewInterface $parent The parent view.
*
* @return FormViewInterface The view object.
*/
public function setParent(FormViewInterface $parent = null);
/**
* Returns the parent view.
*
* @return FormViewInterface The parent view.
*/
public function getParent();
/**
* Returns whether this view has a parent.
*
* @return Boolean Whether this view has a parent
*/
public function hasParent();
/**
* Adds a child view.
*
* @param FormViewInterface $child The child view to add.
*
* @return FormViewInterface The view object.
*/
public function add(FormViewInterface $child);
/**
* Removes a child view.
*
* @param string $name The name of the removed child view.
*
* @return FormViewInterface The view object.
*/
public function remove($name);
/**
* Returns the children.
*
* @return array The children as instances of FormView
*/
public function all();
/**
* Returns a given child.
*
* @param string $name The name of the child
*
* @return FormViewInterface The child view
*/
public function get($name);
/**
* Returns whether this view has a given child.
*
* @param string $name The name of the child
*
* @return Boolean Whether the child with the given name exists
*/
public function has($name);
/**
* Sets a view variable.
*
* @param string $name The variable name.
* @param string $value The variable value.
*
* @return FormViewInterface The view object.
*/
public function setVar($name, $value);
/**
* Adds a list of view variables.
*
* @param array $values An array of variable names and values.
*
* @return FormViewInterface The view object.
*/
public function addVars(array $values);
/**
* Returns whether a view variable exists.
*
* @param string $name The variable name.
*
* @return Boolean Whether the variable exists.
*/
public function hasVar($name);
/**
* Returns the value of a view variable.
*
* @param string $name The variable name.
* @param mixed $default The value to return if the variable is not set.
*
* @return mixed The variable value.
*/
public function getVar($name, $default = null);
/**
* Returns the values of all view variables.
*
* @return array The values of all variables.
*/
public function getVars();
}

View File

@ -130,18 +130,17 @@ class ResolvedFormType implements ResolvedFormTypeInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createView(FormInterface $form, FormViewInterface $parent = null) public function createView(FormInterface $form, FormView $parent = null)
{ {
$options = $form->getConfig()->getOptions(); $options = $form->getConfig()->getOptions();
$view = new FormView($form->getConfig()->getName()); $view = new FormView($parent);
$view->setParent($parent);
$this->buildView($view, $form, $options); $this->buildView($view, $form, $options);
foreach ($form as $child) { foreach ($form as $name => $child) {
/* @var FormInterface $child */ /* @var FormInterface $child */
$view->add($child->createView($view)); $view->children[$name] = $child->createView($view);
} }
$this->finishView($view, $form, $options); $this->finishView($view, $form, $options);
@ -163,7 +162,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
} }
} }
private function buildView(FormViewInterface $view, FormInterface $form, array $options) private function buildView(FormView $view, FormInterface $form, array $options)
{ {
if (null !== $this->parent) { if (null !== $this->parent) {
$this->parent->buildView($view, $form, $options); $this->parent->buildView($view, $form, $options);
@ -177,7 +176,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
} }
} }
private function finishView(FormViewInterface $view, FormInterface $form, array $options) private function finishView(FormView $view, FormInterface $form, array $options)
{ {
if (null !== $this->parent) { if (null !== $this->parent) {
$this->parent->finishView($view, $form, $options); $this->parent->finishView($view, $form, $options);

View File

@ -62,9 +62,9 @@ interface ResolvedFormTypeInterface
* Creates a new form view for a form of this type. * Creates a new form view for a form of this type.
* *
* @param FormInterface $form The form to create a view for. * @param FormInterface $form The form to create a view for.
* @param FormViewInterface $parent The parent view or null. * @param FormView $parent The parent view or null.
* *
* @return FormViewInterface The created form view. * @return FormView The created form view.
*/ */
public function createView(FormInterface $form, FormViewInterface $parent = null); public function createView(FormInterface $form, FormView $parent = null);
} }

View File

@ -20,7 +20,7 @@ class CheckboxTypeTest extends TypeTestCase
$form = $this->factory->create('checkbox', null, array('value' => 'foobar')); $form = $this->factory->create('checkbox', null, array('value' => 'foobar'));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('foobar', $view->getVar('value')); $this->assertEquals('foobar', $view->vars['value']);
} }
public function testCheckedIfDataTrue() public function testCheckedIfDataTrue()
@ -29,7 +29,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->setData(true); $form->setData(true);
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('checked')); $this->assertTrue($view->vars['checked']);
} }
public function testCheckedIfDataTrueWithEmptyValue() public function testCheckedIfDataTrueWithEmptyValue()
@ -38,7 +38,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->setData(true); $form->setData(true);
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('checked')); $this->assertTrue($view->vars['checked']);
} }
public function testNotCheckedIfDataFalse() public function testNotCheckedIfDataFalse()
@ -47,7 +47,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->setData(false); $form->setData(false);
$view = $form->createView(); $view = $form->createView();
$this->assertFalse($view->getVar('checked')); $this->assertFalse($view->vars['checked']);
} }
public function testBindWithValueChecked() public function testBindWithValueChecked()
@ -127,7 +127,7 @@ class CheckboxTypeTest extends TypeTestCase
$form->setData($data); $form->setData($data);
$view = $form->createView(); $view = $form->createView();
$this->assertEquals($expected, $view->getVar('checked')); $this->assertEquals($expected, $view->vars['checked']);
} }
public function provideTransformedData() public function provideTransformedData()

View File

@ -537,7 +537,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('required')); $this->assertTrue($view->vars['required']);
} }
public function testPassNonRequiredToView() public function testPassNonRequiredToView()
@ -548,7 +548,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertFalse($view->getVar('required')); $this->assertFalse($view->vars['required']);
} }
public function testPassMultipleToView() public function testPassMultipleToView()
@ -559,7 +559,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('multiple')); $this->assertTrue($view->vars['multiple']);
} }
public function testPassExpandedToView() public function testPassExpandedToView()
@ -570,7 +570,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('expanded')); $this->assertTrue($view->vars['expanded']);
} }
public function testNotPassedEmptyValueToViewIsNull() public function testNotPassedEmptyValueToViewIsNull()
@ -581,7 +581,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('empty_value')); $this->assertNull($view->vars['empty_value']);
} }
public function testPassEmptyValueToViewIsEmpty() public function testPassEmptyValueToViewIsEmpty()
@ -593,7 +593,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEmpty($view->getVar('empty_value')); $this->assertEmpty($view->vars['empty_value']);
} }
/** /**
@ -610,7 +610,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals($viewValue, $view->getVar('empty_value')); $this->assertEquals($viewValue, $view->vars['empty_value']);
} }
/** /**
@ -627,7 +627,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('empty_value')); $this->assertNull($view->vars['empty_value']);
} }
public function getOptionsWithEmptyValue() public function getOptionsWithEmptyValue()
@ -658,7 +658,7 @@ class ChoiceTypeTest extends TypeTestCase
new ChoiceView('b', 'B'), new ChoiceView('b', 'B'),
new ChoiceView('c', 'C'), new ChoiceView('c', 'C'),
new ChoiceView('d', 'D'), new ChoiceView('d', 'D'),
), $view->getVar('choices')); ), $view->vars['choices']);
} }
public function testPassPreferredChoicesToView() public function testPassPreferredChoicesToView()
@ -673,11 +673,11 @@ class ChoiceTypeTest extends TypeTestCase
$this->assertEquals(array( $this->assertEquals(array(
0 => new ChoiceView('a', 'A'), 0 => new ChoiceView('a', 'A'),
2 => new ChoiceView('c', 'C'), 2 => new ChoiceView('c', 'C'),
), $view->getVar('choices')); ), $view->vars['choices']);
$this->assertEquals(array( $this->assertEquals(array(
1 => new ChoiceView('b', 'B'), 1 => new ChoiceView('b', 'B'),
3 => new ChoiceView('d', 'D'), 3 => new ChoiceView('d', 'D'),
), $view->getVar('preferred_choices')); ), $view->vars['preferred_choices']);
} }
public function testPassHierarchicalChoicesToView() public function testPassHierarchicalChoicesToView()
@ -696,7 +696,7 @@ class ChoiceTypeTest extends TypeTestCase
'Doctrine' => array( 'Doctrine' => array(
4 => new ChoiceView('e', 'Roman'), 4 => new ChoiceView('e', 'Roman'),
), ),
), $view->getVar('choices')); ), $view->vars['choices']);
$this->assertEquals(array( $this->assertEquals(array(
'Symfony' => array( 'Symfony' => array(
1 => new ChoiceView('b', 'Fabien'), 1 => new ChoiceView('b', 'Fabien'),
@ -704,7 +704,7 @@ class ChoiceTypeTest extends TypeTestCase
'Doctrine' => array( 'Doctrine' => array(
3 => new ChoiceView('d', 'Jon'), 3 => new ChoiceView('d', 'Jon'),
), ),
), $view->getVar('preferred_choices')); ), $view->vars['preferred_choices']);
} }
public function testAdjustFullNameForMultipleNonExpanded() public function testAdjustFullNameForMultipleNonExpanded()
@ -716,7 +716,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('name[]', $view->getVar('full_name')); $this->assertSame('name[]', $view->vars['full_name']);
} }
// https://github.com/symfony/symfony/issues/3298 // https://github.com/symfony/symfony/issues/3298

View File

@ -138,7 +138,7 @@ class CollectionTypeTest extends TypeTestCase
)) ))
; ;
$this->assertTrue($form->createView()->getVar('multipart')); $this->assertTrue($form->createView()->vars['multipart']);
} }
public function testGetDataDoesNotContainsProtypeNameBeforeDataAreSet() public function testGetDataDoesNotContainsProtypeNameBeforeDataAreSet()
@ -195,6 +195,6 @@ class CollectionTypeTest extends TypeTestCase
'prototype_name' => '__test__', 'prototype_name' => '__test__',
)); ));
$this->assertSame('__test__label__', $form->createView()->getVar('prototype')->getVar('label')); $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
} }
} }

View File

@ -21,7 +21,7 @@ class CountryTypeTest extends LocalizedTestCase
$form = $this->factory->create('country'); $form = $this->factory->create('country');
$view = $form->createView(); $view = $form->createView();
$choices = $view->getVar('choices'); $choices = $view->vars['choices'];
// Don't check objects for identity // Don't check objects for identity
$this->assertContains(new ChoiceView('DE', 'Deutschland'), $choices, '', false, false); $this->assertContains(new ChoiceView('DE', 'Deutschland'), $choices, '', false, false);
@ -35,10 +35,10 @@ class CountryTypeTest extends LocalizedTestCase
{ {
$form = $this->factory->create('country', 'country'); $form = $this->factory->create('country', 'country');
$view = $form->createView(); $view = $form->createView();
$choices = $view->getVar('choices'); $choices = $view->vars['choices'];
foreach ($choices as $choice) { foreach ($choices as $choice) {
if ('ZZ' === $choice->getValue()) { if ('ZZ' === $choice->value) {
$this->fail('Should not contain choice "ZZ"'); $this->fail('Should not contain choice "ZZ"');
} }
} }

View File

@ -238,7 +238,7 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('datetime', $view->getVar('type')); $this->assertEquals('datetime', $view->vars['type']);
} }
public function testPassDefaultEmptyValueToViewIfNotRequired() public function testPassDefaultEmptyValueToViewIfNotRequired()
@ -249,12 +249,12 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->get('date')->get('year')->getVar('empty_value')); $this->assertSame('', $view['date']['year']->vars['empty_value']);
$this->assertSame('', $view->get('date')->get('month')->getVar('empty_value')); $this->assertSame('', $view['date']['month']->vars['empty_value']);
$this->assertSame('', $view->get('date')->get('day')->getVar('empty_value')); $this->assertSame('', $view['date']['day']->vars['empty_value']);
$this->assertSame('', $view->get('time')->get('hour')->getVar('empty_value')); $this->assertSame('', $view['time']['hour']->vars['empty_value']);
$this->assertSame('', $view->get('time')->get('minute')->getVar('empty_value')); $this->assertSame('', $view['time']['minute']->vars['empty_value']);
$this->assertSame('', $view->get('time')->get('second')->getVar('empty_value')); $this->assertSame('', $view['time']['second']->vars['empty_value']);
} }
public function testPassNoEmptyValueToViewIfRequired() public function testPassNoEmptyValueToViewIfRequired()
@ -265,12 +265,12 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->get('date')->get('year')->getVar('empty_value')); $this->assertNull($view['date']['year']->vars['empty_value']);
$this->assertNull($view->get('date')->get('month')->getVar('empty_value')); $this->assertNull($view['date']['month']->vars['empty_value']);
$this->assertNull($view->get('date')->get('day')->getVar('empty_value')); $this->assertNull($view['date']['day']->vars['empty_value']);
$this->assertNull($view->get('time')->get('hour')->getVar('empty_value')); $this->assertNull($view['time']['hour']->vars['empty_value']);
$this->assertNull($view->get('time')->get('minute')->getVar('empty_value')); $this->assertNull($view['time']['minute']->vars['empty_value']);
$this->assertNull($view->get('time')->get('second')->getVar('empty_value')); $this->assertNull($view['time']['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsString() public function testPassEmptyValueAsString()
@ -281,12 +281,12 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty', $view->get('date')->get('year')->getVar('empty_value')); $this->assertSame('Empty', $view['date']['year']->vars['empty_value']);
$this->assertSame('Empty', $view->get('date')->get('month')->getVar('empty_value')); $this->assertSame('Empty', $view['date']['month']->vars['empty_value']);
$this->assertSame('Empty', $view->get('date')->get('day')->getVar('empty_value')); $this->assertSame('Empty', $view['date']['day']->vars['empty_value']);
$this->assertSame('Empty', $view->get('time')->get('hour')->getVar('empty_value')); $this->assertSame('Empty', $view['time']['hour']->vars['empty_value']);
$this->assertSame('Empty', $view->get('time')->get('minute')->getVar('empty_value')); $this->assertSame('Empty', $view['time']['minute']->vars['empty_value']);
$this->assertSame('Empty', $view->get('time')->get('second')->getVar('empty_value')); $this->assertSame('Empty', $view['time']['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsArray() public function testPassEmptyValueAsArray()
@ -304,12 +304,12 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty year', $view->get('date')->get('year')->getVar('empty_value')); $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']);
$this->assertSame('Empty month', $view->get('date')->get('month')->getVar('empty_value')); $this->assertSame('Empty month', $view['date']['month']->vars['empty_value']);
$this->assertSame('Empty day', $view->get('date')->get('day')->getVar('empty_value')); $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']);
$this->assertSame('Empty hour', $view->get('time')->get('hour')->getVar('empty_value')); $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']);
$this->assertSame('Empty minute', $view->get('time')->get('minute')->getVar('empty_value')); $this->assertSame('Empty minute', $view['time']['minute']->vars['empty_value']);
$this->assertSame('Empty second', $view->get('time')->get('second')->getVar('empty_value')); $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired()
@ -326,12 +326,12 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty year', $view->get('date')->get('year')->getVar('empty_value')); $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']);
$this->assertSame('', $view->get('date')->get('month')->getVar('empty_value')); $this->assertSame('', $view['date']['month']->vars['empty_value']);
$this->assertSame('Empty day', $view->get('date')->get('day')->getVar('empty_value')); $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']);
$this->assertSame('Empty hour', $view->get('time')->get('hour')->getVar('empty_value')); $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']);
$this->assertSame('', $view->get('time')->get('minute')->getVar('empty_value')); $this->assertSame('', $view['time']['minute']->vars['empty_value']);
$this->assertSame('Empty second', $view->get('time')->get('second')->getVar('empty_value')); $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsPartialArray_addNullIfRequired() public function testPassEmptyValueAsPartialArray_addNullIfRequired()
@ -348,12 +348,12 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty year', $view->get('date')->get('year')->getVar('empty_value')); $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']);
$this->assertNull($view->get('date')->get('month')->getVar('empty_value')); $this->assertNull($view['date']['month']->vars['empty_value']);
$this->assertSame('Empty day', $view->get('date')->get('day')->getVar('empty_value')); $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']);
$this->assertSame('Empty hour', $view->get('time')->get('hour')->getVar('empty_value')); $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']);
$this->assertNull($view->get('time')->get('minute')->getVar('empty_value')); $this->assertNull($view['time']['minute']->vars['empty_value']);
$this->assertSame('Empty second', $view->get('time')->get('second')->getVar('empty_value')); $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']);
} }
public function testPassHtml5TypeIfSingleTextAndHtml5Format() public function testPassHtml5TypeIfSingleTextAndHtml5Format()
@ -363,7 +363,7 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('datetime', $view->getVar('type')); $this->assertSame('datetime', $view->vars['type']);
} }
public function testDontPassHtml5TypeIfNotHtml5Format() public function testDontPassHtml5TypeIfNotHtml5Format()
@ -374,7 +374,7 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('datetime')); $this->assertFalse(isset($view->vars['type']));
} }
public function testDontPassHtml5TypeIfNotSingleText() public function testDontPassHtml5TypeIfNotSingleText()
@ -384,6 +384,6 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('type')); $this->assertFalse(isset($view->vars['type']));
} }
} }

View File

@ -357,7 +357,7 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('2010', '2010'), new ChoiceView('2010', '2010'),
new ChoiceView('2011', '2011'), new ChoiceView('2011', '2011'),
), $view->get('year')->getVar('choices')); ), $view['year']->vars['choices']);
} }
public function testMonthsOption() public function testMonthsOption()
@ -371,7 +371,7 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '06'), new ChoiceView('6', '06'),
new ChoiceView('7', '07'), new ChoiceView('7', '07'),
), $view->get('month')->getVar('choices')); ), $view['month']->vars['choices']);
} }
public function testMonthsOptionShortFormat() public function testMonthsOptionShortFormat()
@ -386,7 +386,7 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('1', 'Jän'), new ChoiceView('1', 'Jän'),
new ChoiceView('4', 'Apr') new ChoiceView('4', 'Apr')
), $view->get('month')->getVar('choices')); ), $view['month']->vars['choices']);
} }
public function testMonthsOptionLongFormat() public function testMonthsOptionLongFormat()
@ -401,7 +401,7 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('1', 'Jänner'), new ChoiceView('1', 'Jänner'),
new ChoiceView('4', 'April'), new ChoiceView('4', 'April'),
), $view->get('month')->getVar('choices')); ), $view['month']->vars['choices']);
} }
public function testMonthsOptionLongFormatWithDifferentTimezone() public function testMonthsOptionLongFormatWithDifferentTimezone()
@ -416,7 +416,7 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('1', 'Jänner'), new ChoiceView('1', 'Jänner'),
new ChoiceView('4', 'April'), new ChoiceView('4', 'April'),
), $view->get('month')->getVar('choices')); ), $view['month']->vars['choices']);
} }
public function testIsDayWithinRangeReturnsTrueIfWithin() public function testIsDayWithinRangeReturnsTrueIfWithin()
@ -430,7 +430,7 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '06'), new ChoiceView('6', '06'),
new ChoiceView('7', '07'), new ChoiceView('7', '07'),
), $view->get('day')->getVar('choices')); ), $view['day']->vars['choices']);
} }
public function testIsPartiallyFilledReturnsFalseIfSingleText() public function testIsPartiallyFilledReturnsFalseIfSingleText()
@ -510,7 +510,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date'); $form = $this->factory->create('date');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('{{ year }}-{{ month }}-{{ day }}', $view->getVar('date_pattern')); $this->assertSame('{{ year }}-{{ month }}-{{ day }}', $view->vars['date_pattern']);
} }
public function testPassDatePatternToViewDifferentFormat() public function testPassDatePatternToViewDifferentFormat()
@ -521,7 +521,7 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView(); $view = $form->createView();
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->getVar('date_pattern')); $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']);
} }
public function testPassDatePatternToViewDifferentPattern() public function testPassDatePatternToViewDifferentPattern()
@ -532,7 +532,7 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView(); $view = $form->createView();
$this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->getVar('date_pattern')); $this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->vars['date_pattern']);
} }
public function testDontPassDatePatternIfText() public function testDontPassDatePatternIfText()
@ -542,7 +542,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('date_pattern')); $this->assertFalse(isset($view->vars['date_pattern']));
} }
public function testPassWidgetToView() public function testPassWidgetToView()
@ -552,7 +552,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('single_text', $view->getVar('widget')); $this->assertSame('single_text', $view->vars['widget']);
} }
// Bug fix // Bug fix
@ -570,7 +570,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('date', $view->getVar('type')); $this->assertEquals('date', $view->vars['type']);
} }
public function testPassDefaultEmptyValueToViewIfNotRequired() public function testPassDefaultEmptyValueToViewIfNotRequired()
@ -580,9 +580,9 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->get('year')->getVar('empty_value')); $this->assertSame('', $view['year']->vars['empty_value']);
$this->assertSame('', $view->get('month')->getVar('empty_value')); $this->assertSame('', $view['month']->vars['empty_value']);
$this->assertSame('', $view->get('day')->getVar('empty_value')); $this->assertSame('', $view['day']->vars['empty_value']);
} }
public function testPassNoEmptyValueToViewIfRequired() public function testPassNoEmptyValueToViewIfRequired()
@ -592,9 +592,9 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->get('year')->getVar('empty_value')); $this->assertNull($view['year']->vars['empty_value']);
$this->assertNull($view->get('month')->getVar('empty_value')); $this->assertNull($view['month']->vars['empty_value']);
$this->assertNull($view->get('day')->getVar('empty_value')); $this->assertNull($view['day']->vars['empty_value']);
} }
public function testPassEmptyValueAsString() public function testPassEmptyValueAsString()
@ -604,9 +604,9 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty', $view->get('year')->getVar('empty_value')); $this->assertSame('Empty', $view['year']->vars['empty_value']);
$this->assertSame('Empty', $view->get('month')->getVar('empty_value')); $this->assertSame('Empty', $view['month']->vars['empty_value']);
$this->assertSame('Empty', $view->get('day')->getVar('empty_value')); $this->assertSame('Empty', $view['day']->vars['empty_value']);
} }
public function testPassEmptyValueAsArray() public function testPassEmptyValueAsArray()
@ -620,9 +620,9 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty year', $view->get('year')->getVar('empty_value')); $this->assertSame('Empty year', $view['year']->vars['empty_value']);
$this->assertSame('Empty month', $view->get('month')->getVar('empty_value')); $this->assertSame('Empty month', $view['month']->vars['empty_value']);
$this->assertSame('Empty day', $view->get('day')->getVar('empty_value')); $this->assertSame('Empty day', $view['day']->vars['empty_value']);
} }
public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired()
@ -636,9 +636,9 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty year', $view->get('year')->getVar('empty_value')); $this->assertSame('Empty year', $view['year']->vars['empty_value']);
$this->assertSame('', $view->get('month')->getVar('empty_value')); $this->assertSame('', $view['month']->vars['empty_value']);
$this->assertSame('Empty day', $view->get('day')->getVar('empty_value')); $this->assertSame('Empty day', $view['day']->vars['empty_value']);
} }
public function testPassEmptyValueAsPartialArray_addNullIfRequired() public function testPassEmptyValueAsPartialArray_addNullIfRequired()
@ -652,9 +652,9 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty year', $view->get('year')->getVar('empty_value')); $this->assertSame('Empty year', $view['year']->vars['empty_value']);
$this->assertNull($view->get('month')->getVar('empty_value')); $this->assertNull($view['month']->vars['empty_value']);
$this->assertSame('Empty day', $view->get('day')->getVar('empty_value')); $this->assertSame('Empty day', $view['day']->vars['empty_value']);
} }
public function testPassHtml5TypeIfSingleTextAndHtml5Format() public function testPassHtml5TypeIfSingleTextAndHtml5Format()
@ -664,7 +664,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('date', $view->getVar('type')); $this->assertSame('date', $view->vars['type']);
} }
public function testDontPassHtml5TypeIfNotHtml5Format() public function testDontPassHtml5TypeIfNotHtml5Format()
@ -675,7 +675,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('type')); $this->assertFalse(isset($view->vars['type']));
} }
public function testDontPassHtml5TypeIfNotSingleText() public function testDontPassHtml5TypeIfNotSingleText()
@ -685,7 +685,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->getVar('type')); $this->assertFalse(isset($view->vars['type']));
} }
public function provideCompoundWidgets() public function provideCompoundWidgets()
@ -705,9 +705,9 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'widget' => $widget, 'widget' => $widget,
)); ));
$form->get('year')->addError($error); $form['year']->addError($error);
$this->assertSame(array(), $form->get('year')->getErrors()); $this->assertSame(array(), $form['year']->getErrors());
$this->assertSame(array($error), $form->getErrors()); $this->assertSame(array($error), $form->getErrors());
} }
@ -720,9 +720,9 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'widget' => $widget, 'widget' => $widget,
)); ));
$form->get('month')->addError($error); $form['month']->addError($error);
$this->assertSame(array(), $form->get('month')->getErrors()); $this->assertSame(array(), $form['month']->getErrors());
$this->assertSame(array($error), $form->getErrors()); $this->assertSame(array($error), $form->getErrors());
} }
@ -735,9 +735,9 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array( $form = $this->factory->create('date', null, array(
'widget' => $widget, 'widget' => $widget,
)); ));
$form->get('day')->addError($error); $form['day']->addError($error);
$this->assertSame(array(), $form->get('day')->getErrors()); $this->assertSame(array(), $form['day']->getErrors());
$this->assertSame(array($error), $form->getErrors()); $this->assertSame(array($error), $form->getErrors());
} }
} }

View File

@ -23,7 +23,7 @@ class FileTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('', $view->getVar('value')); $this->assertEquals('', $view->vars['value']);
} }
private function createUploadedFileMock($name, $originalName, $valid) private function createUploadedFileMock($name, $originalName, $valid)

View File

@ -107,9 +107,9 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->createNamed('name', 'form'); $form = $this->factory->createNamed('name', 'form');
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('name', $view->getVar('id')); $this->assertEquals('name', $view->vars['id']);
$this->assertEquals('name', $view->getVar('name')); $this->assertEquals('name', $view->vars['name']);
$this->assertEquals('name', $view->getVar('full_name')); $this->assertEquals('name', $view->vars['full_name']);
} }
public function testStripLeadingUnderscoresAndDigitsFromId() public function testStripLeadingUnderscoresAndDigitsFromId()
@ -117,9 +117,9 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->createNamed('_09name', 'form'); $form = $this->factory->createNamed('_09name', 'form');
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('name', $view->getVar('id')); $this->assertEquals('name', $view->vars['id']);
$this->assertEquals('_09name', $view->getVar('name')); $this->assertEquals('_09name', $view->vars['name']);
$this->assertEquals('_09name', $view->getVar('full_name')); $this->assertEquals('_09name', $view->vars['full_name']);
} }
public function testPassIdAndNameToViewWithParent() public function testPassIdAndNameToViewWithParent()
@ -128,9 +128,9 @@ class FormTypeTest extends TypeTestCase
$parent->add($this->factory->createNamed('child', 'form')); $parent->add($this->factory->createNamed('child', 'form'));
$view = $parent->createView(); $view = $parent->createView();
$this->assertEquals('parent_child', $view['child']->getVar('id')); $this->assertEquals('parent_child', $view['child']->vars['id']);
$this->assertEquals('child', $view['child']->getVar('name')); $this->assertEquals('child', $view['child']->vars['name']);
$this->assertEquals('parent[child]', $view['child']->getVar('full_name')); $this->assertEquals('parent[child]', $view['child']->vars['full_name']);
} }
public function testPassIdAndNameToViewWithGrandParent() public function testPassIdAndNameToViewWithGrandParent()
@ -140,9 +140,9 @@ class FormTypeTest extends TypeTestCase
$parent['child']->add($this->factory->createNamed('grand_child', 'form')); $parent['child']->add($this->factory->createNamed('grand_child', 'form'));
$view = $parent->createView(); $view = $parent->createView();
$this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->getVar('id')); $this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->vars['id']);
$this->assertEquals('grand_child', $view['child']['grand_child']->getVar('name')); $this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']);
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->getVar('full_name')); $this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']);
} }
public function testNonReadOnlyFormWithReadOnlyParentBeingReadOnly() public function testNonReadOnlyFormWithReadOnlyParentBeingReadOnly()
@ -151,7 +151,7 @@ class FormTypeTest extends TypeTestCase
$child = $this->factory->createNamed('child', 'form'); $child = $this->factory->createNamed('child', 'form');
$view = $parent->add($child)->createView(); $view = $parent->add($child)->createView();
$this->assertTrue($view['child']->getVar('read_only')); $this->assertTrue($view['child']->vars['read_only']);
} }
public function testReadOnlyFormWithNonReadOnlyParentBeingReadOnly() public function testReadOnlyFormWithNonReadOnlyParentBeingReadOnly()
@ -160,7 +160,7 @@ class FormTypeTest extends TypeTestCase
$child = $this->factory->createNamed('child', 'form', null, array('read_only' => true)); $child = $this->factory->createNamed('child', 'form', null, array('read_only' => true));
$view = $parent->add($child)->createView(); $view = $parent->add($child)->createView();
$this->assertTrue($view['child']->getVar('read_only')); $this->assertTrue($view['child']->vars['read_only']);
} }
public function testNonReadOnlyFormWithNonReadOnlyParentBeingNonReadOnly() public function testNonReadOnlyFormWithNonReadOnlyParentBeingNonReadOnly()
@ -169,7 +169,7 @@ class FormTypeTest extends TypeTestCase
$child = $this->factory->createNamed('child', 'form'); $child = $this->factory->createNamed('child', 'form');
$view = $parent->add($child)->createView(); $view = $parent->add($child)->createView();
$this->assertFalse($view['child']->getVar('read_only')); $this->assertFalse($view['child']->vars['read_only']);
} }
public function testPassMaxLengthToView() public function testPassMaxLengthToView()
@ -177,7 +177,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->create('form', null, array('max_length' => 10)); $form = $this->factory->create('form', null, array('max_length' => 10));
$view = $form->createView(); $view = $form->createView();
$this->assertSame(10, $view->getVar('max_length')); $this->assertSame(10, $view->vars['max_length']);
} }
public function testPassTranslationDomainToView() public function testPassTranslationDomainToView()
@ -185,7 +185,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->create('form', null, array('translation_domain' => 'test')); $form = $this->factory->create('form', null, array('translation_domain' => 'test'));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('test', $view->getVar('translation_domain')); $this->assertSame('test', $view->vars['translation_domain']);
} }
public function testNonTranslationDomainFormWithTranslationDomainParentBeingTranslationDomain() public function testNonTranslationDomainFormWithTranslationDomainParentBeingTranslationDomain()
@ -194,7 +194,7 @@ class FormTypeTest extends TypeTestCase
$child = $this->factory->createNamed('child', 'form'); $child = $this->factory->createNamed('child', 'form');
$view = $parent->add($child)->createView(); $view = $parent->add($child)->createView();
$this->assertEquals('test', $view['child']->getVar('translation_domain')); $this->assertEquals('test', $view['child']->vars['translation_domain']);
} }
public function testTranslationDomainFormWithNonTranslationDomainParentBeingTranslationDomain() public function testTranslationDomainFormWithNonTranslationDomainParentBeingTranslationDomain()
@ -203,7 +203,7 @@ class FormTypeTest extends TypeTestCase
$child = $this->factory->createNamed('child', 'form', null, array('translation_domain' => 'test')); $child = $this->factory->createNamed('child', 'form', null, array('translation_domain' => 'test'));
$view = $parent->add($child)->createView(); $view = $parent->add($child)->createView();
$this->assertEquals('test', $view['child']->getVar('translation_domain')); $this->assertEquals('test', $view['child']->vars['translation_domain']);
} }
public function testNonTranlsationDomainFormWithNonTranslationDomainParentBeingTranslationDomainDefault() public function testNonTranlsationDomainFormWithNonTranslationDomainParentBeingTranslationDomainDefault()
@ -212,7 +212,7 @@ class FormTypeTest extends TypeTestCase
$child = $this->factory->createNamed('child', 'form'); $child = $this->factory->createNamed('child', 'form');
$view = $parent->add($child)->createView(); $view = $parent->add($child)->createView();
$this->assertEquals('messages', $view['child']->getVar('translation_domain')); $this->assertEquals('messages', $view['child']->vars['translation_domain']);
} }
public function testPassLabelToView() public function testPassLabelToView()
@ -220,7 +220,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->createNamed('__test___field', 'form', null, array('label' => 'My label')); $form = $this->factory->createNamed('__test___field', 'form', null, array('label' => 'My label'));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('My label', $view->getVar('label')); $this->assertSame('My label', $view->vars['label']);
} }
public function testDefaultTranslationDomain() public function testDefaultTranslationDomain()
@ -228,7 +228,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->create('form'); $form = $this->factory->create('form');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('messages', $view->getVar('translation_domain')); $this->assertSame('messages', $view->vars['translation_domain']);
} }
public function testBindWithEmptyDataCreatesObjectIfClassAvailable() public function testBindWithEmptyDataCreatesObjectIfClassAvailable()
@ -386,7 +386,7 @@ class FormTypeTest extends TypeTestCase
$this->assertFalse($form->isEmpty()); $this->assertFalse($form->isEmpty());
$this->assertSame($dataAsString, $view->getVar('value')); $this->assertSame($dataAsString, $view->vars['value']);
$this->assertSame($dataAsString, $form->getData()); $this->assertSame($dataAsString, $form->getData());
} }
@ -526,7 +526,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->create('form'); $form = $this->factory->create('form');
$view = $form->createView(); $view = $form->createView();
$this->assertFalse($view->getVar('multipart')); $this->assertFalse($view->vars['multipart']);
} }
public function testPassMultipartTrueIfAnyChildIsMultipartToView() public function testPassMultipartTrueIfAnyChildIsMultipartToView()
@ -536,7 +536,7 @@ class FormTypeTest extends TypeTestCase
$form->add($this->factory->create('file')); $form->add($this->factory->create('file'));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('multipart')); $this->assertTrue($view->vars['multipart']);
} }
public function testCreateViewDoNoMarkItAsRendered() public function testCreateViewDoNoMarkItAsRendered()
@ -622,7 +622,7 @@ class FormTypeTest extends TypeTestCase
{ {
$form = $this->factory->create('form'); $form = $this->factory->create('form');
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->getVar('valid')); $this->assertTrue($view->vars['valid']);
} }
public function testViewNotValidBound() public function testViewNotValidBound()
@ -631,7 +631,7 @@ class FormTypeTest extends TypeTestCase
$form->bind(array()); $form->bind(array());
$form->addError(new FormError('An error')); $form->addError(new FormError('An error'));
$view = $form->createView(); $view = $form->createView();
$this->assertFalse($view->getVar('valid')); $this->assertFalse($view->vars['valid']);
} }
public function testDataOptionSupersedesSetDataCalls() public function testDataOptionSupersedesSetDataCalls()

View File

@ -21,7 +21,7 @@ class LanguageTypeTest extends LocalizedTestCase
$form = $this->factory->create('language'); $form = $this->factory->create('language');
$view = $form->createView(); $view = $form->createView();
$choices = $view->getVar('choices'); $choices = $view->vars['choices'];
$this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false); $this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_GB', 'Britisches Englisch'), $choices, '', false, false); $this->assertContains(new ChoiceView('en_GB', 'Britisches Englisch'), $choices, '', false, false);
@ -34,7 +34,7 @@ class LanguageTypeTest extends LocalizedTestCase
{ {
$form = $this->factory->create('language', 'language'); $form = $this->factory->create('language', 'language');
$view = $form->createView(); $view = $form->createView();
$choices = $view->getVar('choices'); $choices = $view->vars['choices'];
$this->assertNotContains(new ChoiceView('mul', 'Mehrsprachig'), $choices, '', false, false); $this->assertNotContains(new ChoiceView('mul', 'Mehrsprachig'), $choices, '', false, false);
} }

View File

@ -21,7 +21,7 @@ class LocaleTypeTest extends LocalizedTestCase
$form = $this->factory->create('locale'); $form = $this->factory->create('locale');
$view = $form->createView(); $view = $form->createView();
$choices = $view->getVar('choices'); $choices = $view->vars['choices'];
$this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false); $this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_GB', 'Englisch (Vereinigtes Königreich)'), $choices, '', false, false); $this->assertContains(new ChoiceView('en_GB', 'Englisch (Vereinigtes Königreich)'), $choices, '', false, false);

View File

@ -20,7 +20,7 @@ class MoneyTypeTest extends LocalizedTestCase
$form = $this->factory->create('money'); $form = $this->factory->create('money');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('{{ widget }} €', $view->getVar('money_pattern')); $this->assertSame('{{ widget }} €', $view->vars['money_pattern']);
} }
public function testMoneyPatternWorksForYen() public function testMoneyPatternWorksForYen()
@ -29,6 +29,6 @@ class MoneyTypeTest extends LocalizedTestCase
$form = $this->factory->create('money', null, array('currency' => 'JPY')); $form = $this->factory->create('money', null, array('currency' => 'JPY'));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue((Boolean) strstr($view->getVar('money_pattern'), '¥')); $this->assertTrue((Boolean) strstr($view->vars['money_pattern'], '¥'));
} }
} }

View File

@ -26,7 +26,7 @@ class NumberTypeTest extends LocalizedTestCase
$form->setData('12345.67890'); $form->setData('12345.67890');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('12345,679', $view->getVar('value')); $this->assertSame('12345,679', $view->vars['value']);
} }
public function testDefaultFormattingWithGrouping() public function testDefaultFormattingWithGrouping()
@ -35,7 +35,7 @@ class NumberTypeTest extends LocalizedTestCase
$form->setData('12345.67890'); $form->setData('12345.67890');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('12.345,679', $view->getVar('value')); $this->assertSame('12.345,679', $view->vars['value']);
} }
public function testDefaultFormattingWithPrecision() public function testDefaultFormattingWithPrecision()
@ -44,7 +44,7 @@ class NumberTypeTest extends LocalizedTestCase
$form->setData('12345.67890'); $form->setData('12345.67890');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('12345,68', $view->getVar('value')); $this->assertSame('12345,68', $view->vars['value']);
} }
public function testDefaultFormattingWithRounding() public function testDefaultFormattingWithRounding()
@ -53,6 +53,6 @@ class NumberTypeTest extends LocalizedTestCase
$form->setData('12345.54321'); $form->setData('12345.54321');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('12346', $view->getVar('value')); $this->assertSame('12346', $view->vars['value']);
} }
} }

View File

@ -19,7 +19,7 @@ class PasswordTypeTest extends TypeTestCase
$form->setData('pAs5w0rd'); $form->setData('pAs5w0rd');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->getVar('value')); $this->assertSame('', $view->vars['value']);
} }
public function testEmptyIfBound() public function testEmptyIfBound()
@ -28,7 +28,7 @@ class PasswordTypeTest extends TypeTestCase
$form->bind('pAs5w0rd'); $form->bind('pAs5w0rd');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->getVar('value')); $this->assertSame('', $view->vars['value']);
} }
public function testNotEmptyIfBoundAndNotAlwaysEmpty() public function testNotEmptyIfBoundAndNotAlwaysEmpty()
@ -37,6 +37,6 @@ class PasswordTypeTest extends TypeTestCase
$form->bind('pAs5w0rd'); $form->bind('pAs5w0rd');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('pAs5w0rd', $view->getVar('value')); $this->assertSame('pAs5w0rd', $view->vars['value']);
} }
} }

View File

@ -246,7 +246,7 @@ class TimeTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '06'), new ChoiceView('6', '06'),
new ChoiceView('7', '07'), new ChoiceView('7', '07'),
), $view->get('hour')->getVar('choices')); ), $view['hour']->vars['choices']);
} }
public function testIsMinuteWithinRange_returnsTrueIfWithin() public function testIsMinuteWithinRange_returnsTrueIfWithin()
@ -260,7 +260,7 @@ class TimeTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '06'), new ChoiceView('6', '06'),
new ChoiceView('7', '07'), new ChoiceView('7', '07'),
), $view->get('minute')->getVar('choices')); ), $view['minute']->vars['choices']);
} }
public function testIsSecondWithinRange_returnsTrueIfWithin() public function testIsSecondWithinRange_returnsTrueIfWithin()
@ -275,7 +275,7 @@ class TimeTypeTest extends LocalizedTestCase
$this->assertEquals(array( $this->assertEquals(array(
new ChoiceView('6', '06'), new ChoiceView('6', '06'),
new ChoiceView('7', '07'), new ChoiceView('7', '07'),
), $view->get('second')->getVar('choices')); ), $view['second']->vars['choices']);
} }
public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty() public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty()
@ -415,7 +415,7 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('time', $view->getVar('type')); $this->assertEquals('time', $view->vars['type']);
} }
public function testPassDefaultEmptyValueToViewIfNotRequired() public function testPassDefaultEmptyValueToViewIfNotRequired()
@ -426,9 +426,9 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->get('hour')->getVar('empty_value')); $this->assertSame('', $view['hour']->vars['empty_value']);
$this->assertSame('', $view->get('minute')->getVar('empty_value')); $this->assertSame('', $view['minute']->vars['empty_value']);
$this->assertSame('', $view->get('second')->getVar('empty_value')); $this->assertSame('', $view['second']->vars['empty_value']);
} }
public function testPassNoEmptyValueToViewIfRequired() public function testPassNoEmptyValueToViewIfRequired()
@ -439,9 +439,9 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->get('hour')->getVar('empty_value')); $this->assertNull($view['hour']->vars['empty_value']);
$this->assertNull($view->get('minute')->getVar('empty_value')); $this->assertNull($view['minute']->vars['empty_value']);
$this->assertNull($view->get('second')->getVar('empty_value')); $this->assertNull($view['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsString() public function testPassEmptyValueAsString()
@ -452,9 +452,9 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty', $view->get('hour')->getVar('empty_value')); $this->assertSame('Empty', $view['hour']->vars['empty_value']);
$this->assertSame('Empty', $view->get('minute')->getVar('empty_value')); $this->assertSame('Empty', $view['minute']->vars['empty_value']);
$this->assertSame('Empty', $view->get('second')->getVar('empty_value')); $this->assertSame('Empty', $view['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsArray() public function testPassEmptyValueAsArray()
@ -469,9 +469,9 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty hour', $view->get('hour')->getVar('empty_value')); $this->assertSame('Empty hour', $view['hour']->vars['empty_value']);
$this->assertSame('Empty minute', $view->get('minute')->getVar('empty_value')); $this->assertSame('Empty minute', $view['minute']->vars['empty_value']);
$this->assertSame('Empty second', $view->get('second')->getVar('empty_value')); $this->assertSame('Empty second', $view['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired()
@ -486,9 +486,9 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty hour', $view->get('hour')->getVar('empty_value')); $this->assertSame('Empty hour', $view['hour']->vars['empty_value']);
$this->assertSame('', $view->get('minute')->getVar('empty_value')); $this->assertSame('', $view['minute']->vars['empty_value']);
$this->assertSame('Empty second', $view->get('second')->getVar('empty_value')); $this->assertSame('Empty second', $view['second']->vars['empty_value']);
} }
public function testPassEmptyValueAsPartialArray_addNullIfRequired() public function testPassEmptyValueAsPartialArray_addNullIfRequired()
@ -503,9 +503,9 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Empty hour', $view->get('hour')->getVar('empty_value')); $this->assertSame('Empty hour', $view['hour']->vars['empty_value']);
$this->assertNull($view->get('minute')->getVar('empty_value')); $this->assertNull($view['minute']->vars['empty_value']);
$this->assertSame('Empty second', $view->get('second')->getVar('empty_value')); $this->assertSame('Empty second', $view['second']->vars['empty_value']);
} }
public function provideCompoundWidgets() public function provideCompoundWidgets()
@ -525,9 +525,9 @@ class TimeTypeTest extends LocalizedTestCase
$form = $this->factory->create('time', null, array( $form = $this->factory->create('time', null, array(
'widget' => $widget, 'widget' => $widget,
)); ));
$form->get('hour')->addError($error); $form['hour']->addError($error);
$this->assertSame(array(), $form->get('hour')->getErrors()); $this->assertSame(array(), $form['hour']->getErrors());
$this->assertSame(array($error), $form->getErrors()); $this->assertSame(array($error), $form->getErrors());
} }
@ -540,9 +540,9 @@ class TimeTypeTest extends LocalizedTestCase
$form = $this->factory->create('time', null, array( $form = $this->factory->create('time', null, array(
'widget' => $widget, 'widget' => $widget,
)); ));
$form->get('minute')->addError($error); $form['minute']->addError($error);
$this->assertSame(array(), $form->get('minute')->getErrors()); $this->assertSame(array(), $form['minute']->getErrors());
$this->assertSame(array($error), $form->getErrors()); $this->assertSame(array($error), $form->getErrors());
} }
@ -556,9 +556,9 @@ class TimeTypeTest extends LocalizedTestCase
'widget' => $widget, 'widget' => $widget,
'with_seconds' => true, 'with_seconds' => true,
)); ));
$form->get('second')->addError($error); $form['second']->addError($error);
$this->assertSame(array(), $form->get('second')->getErrors()); $this->assertSame(array(), $form['second']->getErrors());
$this->assertSame(array($error), $form->getErrors()); $this->assertSame(array($error), $form->getErrors());
} }
} }

View File

@ -19,7 +19,7 @@ class TimezoneTypeTest extends TypeTestCase
{ {
$form = $this->factory->create('timezone'); $form = $this->factory->create('timezone');
$view = $form->createView(); $view = $form->createView();
$choices = $view->getVar('choices'); $choices = $view->vars['choices'];
$this->assertArrayHasKey('Africa', $choices); $this->assertArrayHasKey('Africa', $choices);
$this->assertContains(new ChoiceView('Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false); $this->assertContains(new ChoiceView('Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);

View File

@ -65,7 +65,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertTrue($view->has('csrf')); $this->assertTrue(isset($view['csrf']));
} }
public function testNoCsrfProtectionByDefaultIfCompoundButNotRoot() public function testNoCsrfProtectionByDefaultIfCompoundButNotRoot()
@ -79,10 +79,10 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
) )
->getForm() ->getForm()
->createView() ->get('form')
->get('form'); ->createView();
$this->assertFalse($view->has('csrf')); $this->assertFalse(isset($view['csrf']));
} }
public function testNoCsrfProtectionByDefaultIfRootButNotCompound() public function testNoCsrfProtectionByDefaultIfRootButNotCompound()
@ -94,7 +94,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertFalse($view->has('csrf')); $this->assertFalse(isset($view['csrf']));
} }
public function testCsrfProtectionCanBeDisabled() public function testCsrfProtectionCanBeDisabled()
@ -107,7 +107,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertFalse($view->has('csrf')); $this->assertFalse(isset($view['csrf']));
} }
public function testGenerateCsrfToken() public function testGenerateCsrfToken()
@ -126,7 +126,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertEquals('token', $view->get('csrf')->getVar('value')); $this->assertEquals('token', $view['csrf']->vars['value']);
} }
public function provideBoolean() public function provideBoolean()
@ -250,9 +250,9 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'allow_add' => true, 'allow_add' => true,
)) ))
->createView() ->createView()
->getVar('prototype'); ->vars['prototype'];
$this->assertFalse($prototypeView->has('csrf')); $this->assertFalse(isset($prototypeView['csrf']));
$this->assertCount(1, $prototypeView); $this->assertCount(1, $prototypeView);
} }
} }

View File

@ -1,105 +0,0 @@
<?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;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class FormRendererTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $engine;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $csrfProvider;
/**
* @var FormRenderer
*/
private $renderer;
protected function setUp()
{
$this->engine = $this->getMock('Symfony\Component\Form\FormRendererEngineInterface');
$this->csrfProvider = $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface');
$this->renderer = new FormRenderer($this->engine, $this->csrfProvider);
}
public function isChoiceGroupProvider()
{
return array(
array(false, 0),
array(false, '0'),
array(false, '1'),
array(false, 1),
array(false, ''),
array(false, null),
array(false, true),
array(true, array()),
);
}
/**
* @dataProvider isChoiceGroupProvider
*/
public function testIsChoiceGroup($expected, $value)
{
$this->assertSame($expected, $this->renderer->isChoiceGroup($value));
}
public function testIsChoiceGroupPart2()
{
$this->assertTrue($this->renderer->isChoiceGroup(new \SplFixedArray(1)));
}
public function isChoiceSelectedProvider()
{
// The commented cases should not be necessary anymore, because the
// choice lists should assure that both values passed here are always
// strings
return array(
// array(true, 0, 0),
array(true, '0', '0'),
array(true, '1', '1'),
// array(true, false, 0),
// array(true, true, 1),
array(true, '', ''),
// array(true, null, ''),
array(true, '1.23', '1.23'),
array(true, 'foo', 'foo'),
array(true, 'foo10', 'foo10'),
array(true, 'foo', array(1, 'foo', 'foo10')),
array(false, 10, array(1, 'foo', 'foo10')),
array(false, 0, array(1, 'foo', 'foo10')),
);
}
/**
* @dataProvider isChoiceSelectedProvider
*/
public function testIsChoiceSelected($expected, $choice, $value)
{
$view = new FormView('name');
$view->setVar('value', $value);
$choice = new ChoiceView($choice, $choice . ' label');
$this->assertSame($expected, $this->renderer->isChoiceSelected($view, $choice));
}
}

View File

@ -1,16 +0,0 @@
<?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\Tests;
interface FormViewInterface extends \Iterator, \Symfony\Component\Form\FormViewInterface
{
}

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\ResolvedFormType; use Symfony\Component\Form\ResolvedFormType;
use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormViewInterface;
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormConfig; use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\Form; use Symfony\Component\Form\Form;
@ -171,7 +170,7 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
$i = 0; $i = 0;
$assertIndexAndNbOfChildViews = function ($index, $nbOfChildViews) use (&$i, $test) { $assertIndexAndNbOfChildViews = function ($index, $nbOfChildViews) use (&$i, $test) {
return function (FormViewInterface $view) use (&$i, $test, $index, $nbOfChildViews) { return function (FormView $view) use (&$i, $test, $index, $nbOfChildViews) {
/* @var \PHPUnit_Framework_TestCase $test */ /* @var \PHPUnit_Framework_TestCase $test */
$test->assertEquals($index, $i, 'Executed at index ' . $index); $test->assertEquals($index, $i, 'Executed at index ' . $index);
$test->assertCount($nbOfChildViews, $view); $test->assertCount($nbOfChildViews, $view);
@ -242,10 +241,10 @@ class ResolvedFormTypeTest extends \PHPUnit_Framework_TestCase
->with($this->anything(), $form, $options) ->with($this->anything(), $form, $options)
->will($this->returnCallback($assertIndexAndNbOfChildViews(11, 2))); ->will($this->returnCallback($assertIndexAndNbOfChildViews(11, 2)));
$parentView = new FormView('parent'); $parentView = new FormView();
$view = $resolvedType->createView($form, $parentView); $view = $resolvedType->createView($form, $parentView);
$this->assertSame($parentView, $view->getParent()); $this->assertSame($parentView, $view->parent);
} }
/** /**

View File

@ -582,7 +582,7 @@ class SimpleFormTest extends AbstractFormTest
public function testCreateView() public function testCreateView()
{ {
$type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface'); $type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface');
$view = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); $view = $this->getMock('Symfony\Component\Form\FormView');
$form = $this->getBuilder()->setType($type)->getForm(); $form = $this->getBuilder()->setType($type)->getForm();
$type->expects($this->once()) $type->expects($this->once())
@ -596,9 +596,9 @@ class SimpleFormTest extends AbstractFormTest
public function testCreateViewWithParent() public function testCreateViewWithParent()
{ {
$type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface'); $type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface');
$view = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); $view = $this->getMock('Symfony\Component\Form\FormView');
$parentForm = $this->getMock('Symfony\Component\Form\Tests\FormInterface'); $parentForm = $this->getMock('Symfony\Component\Form\Tests\FormInterface');
$parentView = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); $parentView = $this->getMock('Symfony\Component\Form\FormView');
$form = $this->getBuilder()->setType($type)->getForm(); $form = $this->getBuilder()->setType($type)->getForm();
$form->setParent($parentForm); $form->setParent($parentForm);
@ -617,8 +617,8 @@ class SimpleFormTest extends AbstractFormTest
public function testCreateViewWithExplicitParent() public function testCreateViewWithExplicitParent()
{ {
$type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface'); $type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface');
$view = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); $view = $this->getMock('Symfony\Component\Form\FormView');
$parentView = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); $parentView = $this->getMock('Symfony\Component\Form\FormView');
$form = $this->getBuilder()->setType($type)->getForm(); $form = $this->getBuilder()->setType($type)->getForm();
$type->expects($this->once()) $type->expects($this->once())

Some files were not shown because too many files have changed in this diff Show More