[Form] Consolidated FormInterface, FormBuilderInterface and FormViewInterface

This commit is contained in:
Bernhard Schussek 2012-05-24 14:24:28 +02:00
parent 8e128fc644
commit 98a7c0cf5f
41 changed files with 361 additions and 264 deletions

View File

@ -468,9 +468,8 @@
* `getAttribute` * `getAttribute`
* `hasAttribute` * `hasAttribute`
* `getClientData` * `getClientData`
* `getChildren`
The method `getClientData` has a new equivalent that is named `getViewData`. * `hasChildren`
You can access all other methods on the `FormConfigInterface` object instead.
Before: Before:
@ -484,6 +483,24 @@
$form->getConfig()->getErrorBubbling(); $form->getConfig()->getErrorBubbling();
``` ```
The method `getClientData` has a new equivalent that is named `getViewData`.
You can access all other methods on the `FormConfigInterface` object instead.
Instead of `getChildren` and `hasChildren`, you should now use `all` and
`count` instead.
Before:
```
if ($form->hasChildren()) {
```
After:
```
if (count($form) > 0) {
```
* The option "validation_constraint" is deprecated and will be removed * The option "validation_constraint" is deprecated and will be removed
in Symfony 2.3. You should use the option "constraints" instead, in Symfony 2.3. You should use the option "constraints" instead,
where you can pass one or more constraints for a form. where you can pass one or more constraints for a form.
@ -717,6 +734,34 @@
$form = $factory->createNamed('firstName', 'text'); $form = $factory->createNamed('firstName', 'text');
``` ```
* 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 method `hasChildren` was deprecated. You should use `count` instead.
Before:
```
$view->set('help', 'A text longer than six characters');
```
After:
```
$view->setVar('help', 'A text longer than six characters');
```
### Validator ### Validator
* The methods `setMessage()`, `getMessageTemplate()` and * The methods `setMessage()`, `getMessageTemplate()` and

View File

@ -115,7 +115,7 @@ class EntityTypeTest extends TypeTestCase
'property' => 'name' 'property' => 'name'
)); ));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
} }
public function testSetDataToUninitializedEntityWithNonRequiredToString() public function testSetDataToUninitializedEntityWithNonRequiredToString()
@ -131,7 +131,7 @@ class EntityTypeTest extends TypeTestCase
'required' => false, 'required' => false,
)); ));
$this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
} }
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder() public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
@ -150,7 +150,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()->get('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('choices'));
} }
/** /**
@ -494,7 +494,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()->get('choices')); $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->getVar('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());
@ -524,7 +524,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()->get('choices')); ), $field->createView()->getVar('choices'));
} }
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier() public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()

View File

@ -98,7 +98,7 @@ class FormExtension extends \Twig_Extension
public function isChoiceSelected(FormView $view, ChoiceView $choice) public function isChoiceSelected(FormView $view, ChoiceView $choice)
{ {
return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value')); return FormUtil::isChoiceSelected($choice->getValue(), $view->getVar('value'));
} }
/** /**
@ -228,7 +228,7 @@ class FormExtension extends \Twig_Extension
} }
} }
$custom = '_'.$view->get('id'); $custom = '_'.$view->getVar('id');
$rendering = $custom.$section; $rendering = $custom.$section;
$blocks = $this->getBlocks($view); $blocks = $this->getBlocks($view);
@ -237,11 +237,11 @@ class FormExtension extends \Twig_Extension
$types = $this->varStack[$rendering]['types']; $types = $this->varStack[$rendering]['types'];
$this->varStack[$rendering]['variables'] = array_replace_recursive($this->varStack[$rendering]['variables'], $variables); $this->varStack[$rendering]['variables'] = array_replace_recursive($this->varStack[$rendering]['variables'], $variables);
} else { } else {
$types = $view->get('types'); $types = $view->getVar('types');
$types[] = $custom; $types[] = $custom;
$typeIndex = count($types) - 1; $typeIndex = count($types) - 1;
$this->varStack[$rendering] = array( $this->varStack[$rendering] = array(
'variables' => array_replace_recursive($view->all(), $variables), 'variables' => array_replace_recursive($view->getVars(), $variables),
'types' => $types, 'types' => $types,
); );
} }

View File

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

View File

@ -66,7 +66,7 @@ class FormHelper extends Helper
public function isChoiceSelected(FormView $view, ChoiceView $choice) public function isChoiceSelected(FormView $view, ChoiceView $choice)
{ {
return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value')); return FormUtil::isChoiceSelected($choice->getValue(), $view->getVar('value'));
} }
/** /**
@ -79,7 +79,7 @@ class FormHelper extends Helper
*/ */
public function setTheme(FormView $view, $themes) public function setTheme(FormView $view, $themes)
{ {
$this->themes[$view->get('id')] = (array) $themes; $this->themes[$view->getVar('id')] = (array) $themes;
$this->templates = array(); $this->templates = array();
} }
@ -237,7 +237,7 @@ class FormHelper extends Helper
$template = null; $template = null;
$custom = '_'.$view->get('id'); $custom = '_'.$view->getVar('id');
$rendering = $custom.$section; $rendering = $custom.$section;
if (isset($this->varStack[$rendering])) { if (isset($this->varStack[$rendering])) {
@ -245,10 +245,10 @@ class FormHelper extends Helper
$types = $this->varStack[$rendering]['types']; $types = $this->varStack[$rendering]['types'];
$variables = array_replace_recursive($this->varStack[$rendering]['variables'], $variables); $variables = array_replace_recursive($this->varStack[$rendering]['variables'], $variables);
} else { } else {
$types = $view->get('types'); $types = $view->getVar('types');
$types[] = $custom; $types[] = $custom;
$typeIndex = count($types) - 1; $typeIndex = count($types) - 1;
$variables = array_replace_recursive($view->all(), $variables); $variables = array_replace_recursive($view->getVars(), $variables);
$this->varStack[$rendering]['types'] = $types; $this->varStack[$rendering]['types'] = $types;
} }
@ -330,7 +330,7 @@ class FormHelper extends Helper
protected function lookupTemplate(FormView $view, $block) protected function lookupTemplate(FormView $view, $block)
{ {
$file = $block.'.html.php'; $file = $block.'.html.php';
$id = $view->get('id'); $id = $view->getVar('id');
if (!isset($this->templates[$id][$block])) { if (!isset($this->templates[$id][$block])) {
$template = false; $template = false;

View File

@ -133,3 +133,8 @@ 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 `hasChildren` in Form and FormBuilder in favor of `count`
* FormBuilder now implements \IteratorAggregate

View File

@ -35,10 +35,10 @@ class CheckboxType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view $view->setVars(array(
->set('value', $options['value']) 'value' => $options['value'],
->set('checked', null !== $form->getViewData()) 'checked' => null !== $form->getViewData(),
; ));
} }
/** /**

View File

@ -75,20 +75,20 @@ class ChoiceType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view $view->setVars(array(
->set('multiple', $options['multiple']) 'multiple' => $options['multiple'],
->set('expanded', $options['expanded']) 'expanded' => $options['expanded'],
->set('preferred_choices', $options['choice_list']->getPreferredViews()) 'preferred_choices' => $options['choice_list']->getPreferredViews(),
->set('choices', $options['choice_list']->getRemainingViews()) 'choices' => $options['choice_list']->getRemainingViews(),
->set('separator', '-------------------') 'separator' => '-------------------',
->set('empty_value', $options['empty_value']) '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->set('full_name', $view->get('full_name').'[]'); $view->setVar('full_name', $view->getVar('full_name').'[]');
} }
} }
@ -99,15 +99,15 @@ class ChoiceType extends AbstractType
{ {
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->get('full_name'); $childName = $view->getVar('full_name');
// Checkboxes should append "[]" to allow multiple selection // Checkboxes should append "[]" to allow multiple selection
if ($options['multiple']) { if ($options['multiple']) {
$childName .= '[]'; $childName .= '[]';
} }
foreach ($view->getChildren() as $childView) { foreach ($view as $childView) {
$childView->set('full_name', $childName); $childView->setVar('full_name', $childName);
} }
} }
} }

View File

@ -48,13 +48,13 @@ class CollectionType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view $view->setVars(array(
->set('allow_add', $options['allow_add']) 'allow_add' => $options['allow_add'],
->set('allow_delete', $options['allow_delete']) 'allow_delete' => $options['allow_delete'],
; ));
if ($form->getConfig()->hasAttribute('prototype')) { if ($form->getConfig()->hasAttribute('prototype')) {
$view->set('prototype', $form->getConfig()->getAttribute('prototype')->createView($view)); $view->setVar('prototype', $form->getConfig()->getAttribute('prototype')->createView($view));
} }
} }
@ -63,8 +63,8 @@ class CollectionType extends AbstractType
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormViewInterface $view, FormInterface $form, array $options)
{ {
if ($form->getConfig()->hasAttribute('prototype') && $view->get('prototype')->get('multipart')) { if ($form->getConfig()->hasAttribute('prototype') && $view->getVar('prototype')->getVar('multipart')) {
$view->set('multipart', true); $view->setVar('multipart', true);
} }
} }

View File

@ -118,10 +118,10 @@ class DateTimeType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view->set('widget', $options['widget']); $view->setVar('widget', $options['widget']);
if ('single_text' === $options['widget']) { if ('single_text' === $options['widget']) {
$view->set('type', 'datetime'); $view->setVar('type', 'datetime');
} }
} }

View File

@ -138,10 +138,10 @@ class DateType extends AbstractType
*/ */
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view->set('widget', $options['widget']); $view->setVar('widget', $options['widget']);
if ('single_text' === $options['widget']) { if ('single_text' === $options['widget']) {
$view->set('type', 'date'); $view->setVar('type', 'date');
} }
if ($view->hasChildren()) { if ($view->hasChildren()) {
@ -156,7 +156,7 @@ class DateType extends AbstractType
$pattern = '{{ year }}-{{ month }}-{{ day }}'; $pattern = '{{ year }}-{{ month }}-{{ day }}';
} }
$view->set('date_pattern', $pattern); $view->setVar('date_pattern', $pattern);
} }
} }

View File

@ -23,10 +23,10 @@ class FileType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view $view->setVars(array(
->set('type', 'file') 'type' => 'file',
->set('value', '') 'value' => '',
; ));
} }
/** /**
@ -35,7 +35,7 @@ class FileType extends AbstractType
public function finishView(FormViewInterface $view, FormInterface $form, array $options) public function finishView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view $view
->set('multipart', true) ->setVar('multipart', true)
; ;
} }

View File

@ -64,8 +64,8 @@ class FormType extends AbstractType
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.');
} }
if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) { if ('' !== ($parentFullName = $view->getParent()->getVar('full_name'))) {
$id = sprintf('%s_%s', $view->getParent()->get('id'), $name); $id = sprintf('%s_%s', $view->getParent()->getVar('id'), $name);
$fullName = sprintf('%s[%s]', $parentFullName, $name); $fullName = sprintf('%s[%s]', $parentFullName, $name);
} else { } else {
$id = $name; $id = $name;
@ -73,7 +73,7 @@ class FormType extends AbstractType
} }
// Complex fields are read-only if themselves or their parent is. // Complex fields are read-only if themselves or their parent is.
$readOnly = $readOnly || $view->getParent()->get('read_only'); $readOnly = $readOnly || $view->getParent()->getVar('read_only');
} else { } else {
$id = $name; $id = $name;
$fullName = $name; $fullName = $name;
@ -89,28 +89,28 @@ class FormType extends AbstractType
$types[] = $type->getName(); $types[] = $type->getName();
} }
$view $view->setVars(array(
->set('form', $view) 'form' => $view,
->set('id', $id) 'id' => $id,
->set('name', $name) 'name' => $name,
->set('full_name', $fullName) 'full_name' => $fullName,
->set('read_only', $readOnly) 'read_only' => $readOnly,
->set('errors', $form->getErrors()) 'errors' => $form->getErrors(),
->set('valid', $form->isBound() ? $form->isValid() : true) 'valid' => $form->isBound() ? $form->isValid() : true,
->set('value', $form->getViewData()) 'value' => $form->getViewData(),
->set('disabled', $form->isDisabled()) 'disabled' => $form->isDisabled(),
->set('required', $form->isRequired()) 'required' => $form->isRequired(),
->set('max_length', $options['max_length']) 'max_length' => $options['max_length'],
->set('pattern', $options['pattern']) 'pattern' => $options['pattern'],
->set('size', null) 'size' => null,
->set('label', $options['label'] ?: $this->humanize($form->getName())) 'label' => $options['label'] ?: $this->humanize($form->getName()),
->set('multipart', false) 'multipart' => false,
->set('attr', $options['attr']) 'attr' => $options['attr'],
->set('label_attr', $options['label_attr']) 'label_attr' => $options['label_attr'],
->set('single_control', $options['single_control']) 'single_control' => $options['single_control'],
->set('types', $types) 'types' => $types,
->set('translation_domain', $options['translation_domain']) 'translation_domain' => $options['translation_domain'],
; ));
} }
/** /**
@ -120,14 +120,14 @@ class FormType extends AbstractType
{ {
$multipart = false; $multipart = false;
foreach ($view->getChildren() as $child) { foreach ($view as $child) {
if ($child->get('multipart')) { if ($child->getVar('multipart')) {
$multipart = true; $multipart = true;
break; break;
} }
} }
$view->set('multipart', $multipart); $view->setVar('multipart', $multipart);
} }
/** /**

View File

@ -42,7 +42,7 @@ class MoneyType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view->set('money_pattern', self::getPattern($options['currency'])); $view->setVar('money_pattern', self::getPattern($options['currency']));
} }
/** /**

View File

@ -25,7 +25,7 @@ class PasswordType extends AbstractType
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
if ($options['always_empty'] || !$form->isBound()) { if ($options['always_empty'] || !$form->isBound()) {
$view->set('value', ''); $view->setVar('value', '');
} }
} }

View File

@ -22,7 +22,7 @@ class TextareaType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view->set('pattern', null); $view->setVar('pattern', null);
} }
/** /**

View File

@ -115,13 +115,13 @@ class TimeType extends AbstractType
*/ */
public function buildView(FormViewInterface $view, FormInterface $form, array $options) public function buildView(FormViewInterface $view, FormInterface $form, array $options)
{ {
$view $view->setVars(array(
->set('widget', $options['widget']) 'widget' => $options['widget'],
->set('with_seconds', $options['with_seconds']) 'with_seconds' => $options['with_seconds'],
; ));
if ('single_text' === $options['widget']) { if ('single_text' === $options['widget']) {
$view->set('type', 'time'); $view->setVar('type', 'time');
} }
} }

View File

@ -69,7 +69,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
'property_path' => false, 'property_path' => false,
)); ));
$view->addChild($csrfForm->createView($view)); $view->add($csrfForm->createView($view));
} }
} }

View File

@ -279,7 +279,7 @@ class ViolationMapper implements ViolationMapperInterface
{ {
$this->scope = $form; $this->scope = $form;
$this->children = new \RecursiveIteratorIterator( $this->children = new \RecursiveIteratorIterator(
new VirtualFormAwareIterator($form->getChildren()) new VirtualFormAwareIterator($form->all())
); );
foreach ($form->getConfig()->getAttribute('error_mapping') as $propertyPath => $targetPath) { foreach ($form->getConfig()->getAttribute('error_mapping') as $propertyPath => $targetPath) {
// Dot rules are considered at the very end // Dot rules are considered at the very end

View File

@ -797,20 +797,34 @@ class Form implements \IteratorAggregate, FormInterface
return $this->config->getViewTransformers(); return $this->config->getViewTransformers();
} }
/**
* {@inheritdoc}
*/
public function all()
{
return $this->children;
}
/** /**
* Returns all children in this group. * Returns all children in this group.
* *
* @return array * @return array
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link all()} instead.
*/ */
public function getChildren() public function getChildren()
{ {
return $this->children; return $this->all();
} }
/** /**
* Returns whether the form has children. * Returns whether the form has children.
* *
* @return Boolean * @return Boolean
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link count()} instead.
*/ */
public function hasChildren() public function hasChildren()
{ {
@ -969,7 +983,7 @@ class Form implements \IteratorAggregate, FormInterface
} }
foreach ($this->children as $child) { foreach ($this->children as $child) {
$view->addChild($child->createView($view)); $view->add($child->createView($view));
} }
foreach ($types as $type) { foreach ($types as $type) {

View File

@ -22,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
* *
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*/ */
class FormBuilder extends FormConfig implements FormBuilderInterface class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderInterface
{ {
/** /**
* The form factory. * The form factory.
@ -186,6 +186,14 @@ class FormBuilder extends FormConfig implements FormBuilderInterface
return $this->children; return $this->children;
} }
/**
* {@inheritdoc}
*/
public function count()
{
return count($this->children);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -225,6 +233,14 @@ class FormBuilder extends FormConfig implements FormBuilderInterface
return $this; return $this;
} }
/**
* {@inheritdoc}
*/
public function hasParent()
{
return null !== $this->parent;
}
/** /**
* Converts an unresolved child into a {@link FormBuilder} instance. * Converts an unresolved child into a {@link FormBuilder} instance.
* *
@ -253,4 +269,12 @@ class FormBuilder extends FormConfig implements FormBuilderInterface
$this->unresolvedChildren = array(); $this->unresolvedChildren = array();
} }
/**
* {@inheritdoc}
*/
public function getIterator()
{
return new \ArrayIterator($this->children);
}
} }

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*/ */
interface FormBuilderInterface extends FormConfigEditorInterface interface FormBuilderInterface extends FormConfigEditorInterface, \Traversable, \Countable
{ {
/** /**
* Adds a new field to this group. A field must have a unique name within * Adds a new field to this group. A field must have a unique name within
@ -91,13 +91,6 @@ interface FormBuilderInterface extends FormConfigEditorInterface
*/ */
function getForm(); function getForm();
/**
* Returns the parent builder.
*
* @return FormBuilderInterface The parent builder
*/
function getParent();
/** /**
* Sets the parent builder. * Sets the parent builder.
* *
@ -106,4 +99,18 @@ interface FormBuilderInterface extends FormConfigEditorInterface
* @return FormBuilderInterface The builder object. * @return FormBuilderInterface The builder object.
*/ */
function setParent(FormBuilderInterface $parent = null); function setParent(FormBuilderInterface $parent = null);
/**
* Returns the parent builder.
*
* @return FormBuilderInterface The parent builder
*/
function getParent();
/**
* Returns whether the builder has a parent.
*
* @return Boolean
*/
function hasParent();
} }

View File

@ -82,14 +82,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* *
* @return array An array of FormInterface instances * @return array An array of FormInterface instances
*/ */
function getChildren(); function all();
/**
* Return whether the form has children.
*
* @return Boolean
*/
function hasChildren();
/** /**
* Returns all errors. * Returns all errors.

View File

@ -54,7 +54,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function set($name, $value) public function setVar($name, $value)
{ {
$this->vars[$name] = $value; $this->vars[$name] = $value;
@ -64,7 +64,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function has($name) public function hasVar($name)
{ {
return array_key_exists($name, $this->vars); return array_key_exists($name, $this->vars);
} }
@ -72,9 +72,9 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function get($name, $default = null) public function getVar($name, $default = null)
{ {
if (false === $this->has($name)) { if (false === $this->hasVar($name)) {
return $default; return $default;
} }
@ -84,19 +84,19 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function all() public function setVars(array $vars)
{ {
return $this->vars; $this->vars = array_replace($this->vars, $vars);
return $this;
} }
/** /**
* Alias of all so it is possible to do `form.vars.foo` * {@inheritdoc}
*
* @return array
*/ */
public function getVars() public function getVars()
{ {
return $this->all(); return $this->vars;
} }
/** /**
@ -177,7 +177,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function addChild(FormViewInterface $child) public function add(FormViewInterface $child)
{ {
$this->children[$child->getName()] = $child; $this->children[$child->getName()] = $child;
@ -187,7 +187,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function removeChild($name) public function remove($name)
{ {
unset($this->children[$name]); unset($this->children[$name]);
@ -197,7 +197,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getChildren() public function all()
{ {
return $this->children; return $this->children;
} }
@ -205,13 +205,22 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getChild($name) public function get($name)
{ {
if (!isset($this->children[$name])) {
throw new \InvalidArgumentException(sprintf('Child "%s" does not exist.', $name));
}
return $this->children[$name]; return $this->children[$name];
} }
/** /**
* {@inheritdoc} * Returns whether this view has any children.
*
* @return Boolean Whether the view has children.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link count()} instead.
*/ */
public function hasChildren() public function hasChildren()
{ {
@ -221,7 +230,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function hasChild($name) public function has($name)
{ {
return isset($this->children[$name]); return isset($this->children[$name]);
} }
@ -235,7 +244,7 @@ class FormView implements \IteratorAggregate, FormViewInterface
*/ */
public function offsetGet($name) public function offsetGet($name)
{ {
return $this->getChild($name); return $this->get($name);
} }
/** /**

View File

@ -23,42 +23,6 @@ interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
*/ */
function getName(); function getName();
/**
* Sets a view variable.
*
* @param string $name The variable name.
* @param string $value The variable value.
*
* @return FormViewInterface The view object.
*/
function set($name, $value);
/**
* Returns whether a view variable exists.
*
* @param string $name The variable name.
*
* @return Boolean Whether the variable exists.
*/
function has($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.
*/
function get($name, $default = null);
/**
* Returns the values of all view variables.
*
* @return array The values of all variables.
*/
function all();
/** /**
* Returns whether the view was already rendered. * Returns whether the view was already rendered.
* *
@ -103,7 +67,7 @@ interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
* *
* @return FormViewInterface The view object. * @return FormViewInterface The view object.
*/ */
function addChild(FormViewInterface $child); function add(FormViewInterface $child);
/** /**
* Removes a child view. * Removes a child view.
@ -112,14 +76,14 @@ interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
* *
* @return FormViewInterface The view object. * @return FormViewInterface The view object.
*/ */
function removeChild($name); function remove($name);
/** /**
* Returns the children. * Returns the children.
* *
* @return array The children as instances of FormView * @return array The children as instances of FormView
*/ */
function getChildren(); function all();
/** /**
* Returns a given child. * Returns a given child.
@ -128,14 +92,7 @@ interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
* *
* @return FormViewInterface The child view * @return FormViewInterface The child view
*/ */
function getChild($name); function get($name);
/**
* Returns whether this view has children.
*
* @return Boolean Whether this view has children
*/
function hasChildren();
/** /**
* Returns whether this view has a given child. * Returns whether this view has a given child.
@ -144,5 +101,50 @@ interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
* *
* @return Boolean Whether the child with the given name exists * @return Boolean Whether the child with the given name exists
*/ */
function hasChild($name); function has($name);
/**
* Sets a view variable.
*
* @param string $name The variable name.
* @param string $value The variable value.
*
* @return FormViewInterface The view object.
*/
function setVar($name, $value);
/**
* Sets a list of view variables.
*
* @param array $values An array of variable names and values.
*
* @return FormViewInterface The view object.
*/
function setVars(array $values);
/**
* Returns whether a view variable exists.
*
* @param string $name The variable name.
*
* @return Boolean Whether the variable exists.
*/
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.
*/
function getVar($name, $default = null);
/**
* Returns the values of all view variables.
*
* @return array The values of all variables.
*/
function getVars();
} }

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->get('value')); $this->assertEquals('foobar', $view->getVar('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->get('checked')); $this->assertTrue($view->getVar('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->get('checked')); $this->assertTrue($view->getVar('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->get('checked')); $this->assertFalse($view->getVar('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->get('checked')); $this->assertEquals($expected, $view->getVar('checked'));
} }
public function provideTransformedData() public function provideTransformedData()

View File

@ -538,7 +538,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->get('required')); $this->assertTrue($view->getVar('required'));
} }
public function testPassNonRequiredToView() public function testPassNonRequiredToView()
@ -549,7 +549,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertFalse($view->get('required')); $this->assertFalse($view->getVar('required'));
} }
public function testPassMultipleToView() public function testPassMultipleToView()
@ -560,7 +560,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->get('multiple')); $this->assertTrue($view->getVar('multiple'));
} }
public function testPassExpandedToView() public function testPassExpandedToView()
@ -571,7 +571,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->get('expanded')); $this->assertTrue($view->getVar('expanded'));
} }
public function testNotPassedEmptyValueToViewIsNull() public function testNotPassedEmptyValueToViewIsNull()
@ -582,7 +582,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->get('empty_value')); $this->assertNull($view->getVar('empty_value'));
} }
public function testPassEmptyValueToViewIsEmpty() public function testPassEmptyValueToViewIsEmpty()
@ -594,7 +594,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEmpty($view->get('empty_value')); $this->assertEmpty($view->getVar('empty_value'));
} }
/** /**
@ -611,7 +611,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals($viewValue, $view->get('empty_value')); $this->assertEquals($viewValue, $view->getVar('empty_value'));
} }
public function getOptionsWithEmptyValue() public function getOptionsWithEmptyValue()
@ -642,7 +642,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->get('choices')); ), $view->getVar('choices'));
} }
public function testPassPreferredChoicesToView() public function testPassPreferredChoicesToView()
@ -657,11 +657,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->get('choices')); ), $view->getVar('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->get('preferred_choices')); ), $view->getVar('preferred_choices'));
} }
public function testPassHierarchicalChoicesToView() public function testPassHierarchicalChoicesToView()
@ -680,7 +680,7 @@ class ChoiceTypeTest extends TypeTestCase
'Doctrine' => array( 'Doctrine' => array(
4 => new ChoiceView('e', 'Roman'), 4 => new ChoiceView('e', 'Roman'),
), ),
), $view->get('choices')); ), $view->getVar('choices'));
$this->assertEquals(array( $this->assertEquals(array(
'Symfony' => array( 'Symfony' => array(
1 => new ChoiceView('b', 'Fabien'), 1 => new ChoiceView('b', 'Fabien'),
@ -688,7 +688,7 @@ class ChoiceTypeTest extends TypeTestCase
'Doctrine' => array( 'Doctrine' => array(
3 => new ChoiceView('d', 'Jon'), 3 => new ChoiceView('d', 'Jon'),
), ),
), $view->get('preferred_choices')); ), $view->getVar('preferred_choices'));
} }
public function testAdjustFullNameForMultipleNonExpanded() public function testAdjustFullNameForMultipleNonExpanded()
@ -700,7 +700,7 @@ class ChoiceTypeTest extends TypeTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('name[]', $view->get('full_name')); $this->assertSame('name[]', $view->getVar('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()->get('multipart')); $this->assertTrue($form->createView()->getVar('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()->get('prototype')->get('label')); $this->assertSame('__test__label__', $form->createView()->getVar('prototype')->getVar('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->get('choices'); $choices = $view->getVar('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,7 +35,7 @@ class CountryTypeTest extends LocalizedTestCase
{ {
$form = $this->factory->create('country', 'country'); $form = $this->factory->create('country', 'country');
$view = $form->createView(); $view = $form->createView();
$choices = $view->get('choices'); $choices = $view->getVar('choices');
foreach ($choices as $choice) { foreach ($choices as $choice) {
if ('ZZ' === $choice->getValue()) { if ('ZZ' === $choice->getValue()) {

View File

@ -241,6 +241,6 @@ class DateTimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('datetime', $view->get('type')); $this->assertEquals('datetime', $view->getVar('type'));
} }
} }

View File

@ -327,7 +327,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->getChild('year')->get('choices')); ), $view->get('year')->getVar('choices'));
} }
public function testMonthsOption() public function testMonthsOption()
@ -341,7 +341,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->getChild('month')->get('choices')); ), $view->get('month')->getVar('choices'));
} }
public function testMonthsOptionNumericIfFormatContainsNoMonth() public function testMonthsOptionNumericIfFormatContainsNoMonth()
@ -356,7 +356,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->getChild('month')->get('choices')); ), $view->get('month')->getVar('choices'));
} }
public function testMonthsOptionShortFormat() public function testMonthsOptionShortFormat()
@ -371,7 +371,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->getChild('month')->get('choices')); ), $view->get('month')->getVar('choices'));
} }
public function testMonthsOptionLongFormat() public function testMonthsOptionLongFormat()
@ -386,7 +386,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->getChild('month')->get('choices')); ), $view->get('month')->getVar('choices'));
} }
public function testMonthsOptionLongFormatWithDifferentTimezone() public function testMonthsOptionLongFormatWithDifferentTimezone()
@ -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->getChild('month')->get('choices')); ), $view->get('month')->getVar('choices'));
} }
public function testIsDayWithinRangeReturnsTrueIfWithin() public function testIsDayWithinRangeReturnsTrueIfWithin()
@ -415,7 +415,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->getChild('day')->get('choices')); ), $view->get('day')->getVar('choices'));
} }
public function testIsPartiallyFilledReturnsFalseIfSingleText() public function testIsPartiallyFilledReturnsFalseIfSingleText()
@ -495,7 +495,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date'); $form = $this->factory->create('date');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->get('date_pattern')); $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->getVar('date_pattern'));
} }
public function testPassDatePatternToViewDifferentPattern() public function testPassDatePatternToViewDifferentPattern()
@ -506,7 +506,7 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView(); $view = $form->createView();
$this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->get('date_pattern')); $this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->getVar('date_pattern'));
} }
public function testDontPassDatePatternIfText() public function testDontPassDatePatternIfText()
@ -516,7 +516,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertNull($view->get('date_pattern')); $this->assertNull($view->getVar('date_pattern'));
} }
public function testPassWidgetToView() public function testPassWidgetToView()
@ -526,7 +526,7 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertSame('single_text', $view->get('widget')); $this->assertSame('single_text', $view->getVar('widget'));
} }
// Bug fix // Bug fix
@ -544,6 +544,6 @@ class DateTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('date', $view->get('type')); $this->assertEquals('date', $view->getVar('type'));
} }
} }

View File

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

View File

@ -105,9 +105,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->get('id')); $this->assertEquals('name', $view->getVar('id'));
$this->assertEquals('name', $view->get('name')); $this->assertEquals('name', $view->getVar('name'));
$this->assertEquals('name', $view->get('full_name')); $this->assertEquals('name', $view->getVar('full_name'));
} }
public function testStripLeadingUnderscoresAndDigitsFromId() public function testStripLeadingUnderscoresAndDigitsFromId()
@ -115,9 +115,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->get('id')); $this->assertEquals('name', $view->getVar('id'));
$this->assertEquals('_09name', $view->get('name')); $this->assertEquals('_09name', $view->getVar('name'));
$this->assertEquals('_09name', $view->get('full_name')); $this->assertEquals('_09name', $view->getVar('full_name'));
} }
public function testPassIdAndNameToViewWithParent() public function testPassIdAndNameToViewWithParent()
@ -126,9 +126,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']->get('id')); $this->assertEquals('parent_child', $view['child']->getVar('id'));
$this->assertEquals('child', $view['child']->get('name')); $this->assertEquals('child', $view['child']->getVar('name'));
$this->assertEquals('parent[child]', $view['child']->get('full_name')); $this->assertEquals('parent[child]', $view['child']->getVar('full_name'));
} }
public function testPassIdAndNameToViewWithGrandParent() public function testPassIdAndNameToViewWithGrandParent()
@ -138,9 +138,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']->get('id')); $this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->getVar('id'));
$this->assertEquals('grand_child', $view['child']['grand_child']->get('name')); $this->assertEquals('grand_child', $view['child']['grand_child']->getVar('name'));
$this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->get('full_name')); $this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->getVar('full_name'));
} }
public function testNonReadOnlyFormWithReadOnlyParentBeingReadOnly() public function testNonReadOnlyFormWithReadOnlyParentBeingReadOnly()
@ -149,7 +149,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']->get('read_only')); $this->assertTrue($view['child']->getVar('read_only'));
} }
public function testReadOnlyFormWithNonReadOnlyParentBeingReadOnly() public function testReadOnlyFormWithNonReadOnlyParentBeingReadOnly()
@ -158,7 +158,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']->get('read_only')); $this->assertTrue($view['child']->getVar('read_only'));
} }
public function testNonReadOnlyFormWithNonReadOnlyParentBeingNonReadOnly() public function testNonReadOnlyFormWithNonReadOnlyParentBeingNonReadOnly()
@ -167,7 +167,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']->get('read_only')); $this->assertFalse($view['child']->getVar('read_only'));
} }
public function testPassMaxLengthToView() public function testPassMaxLengthToView()
@ -175,7 +175,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->get('max_length')); $this->assertSame(10, $view->getVar('max_length'));
} }
public function testPassTranslationDomainToView() public function testPassTranslationDomainToView()
@ -183,7 +183,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->get('translation_domain')); $this->assertSame('test', $view->getVar('translation_domain'));
} }
public function testPassDefaultLabelToView() public function testPassDefaultLabelToView()
@ -191,7 +191,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->createNamed('__test___field', 'form'); $form = $this->factory->createNamed('__test___field', 'form');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('Test field', $view->get('label')); $this->assertSame('Test field', $view->getVar('label'));
} }
public function testPassLabelToView() public function testPassLabelToView()
@ -199,7 +199,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->get('label')); $this->assertSame('My label', $view->getVar('label'));
} }
public function testDefaultTranslationDomain() public function testDefaultTranslationDomain()
@ -207,7 +207,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->get('translation_domain')); $this->assertSame('messages', $view->getVar('translation_domain'));
} }
public function testBindWithEmptyDataCreatesObjectIfClassAvailable() public function testBindWithEmptyDataCreatesObjectIfClassAvailable()
@ -351,7 +351,7 @@ class FormTypeTest extends TypeTestCase
$this->assertFalse($form->isEmpty()); $this->assertFalse($form->isEmpty());
$this->assertSame('0', $view->get('value')); $this->assertSame('0', $view->getVar('value'));
$this->assertSame('0', $form->getData()); $this->assertSame('0', $form->getData());
$form = $this->factory->create('form', null, array('data' => '0')); $form = $this->factory->create('form', null, array('data' => '0'));
@ -359,7 +359,7 @@ class FormTypeTest extends TypeTestCase
$this->assertFalse($form->isEmpty()); $this->assertFalse($form->isEmpty());
$this->assertSame('0', $view->get('value')); $this->assertSame('0', $view->getVar('value'));
$this->assertSame('0', $form->getData()); $this->assertSame('0', $form->getData());
$form = $this->factory->create('form', null, array('data' => '00000')); $form = $this->factory->create('form', null, array('data' => '00000'));
@ -367,7 +367,7 @@ class FormTypeTest extends TypeTestCase
$this->assertFalse($form->isEmpty()); $this->assertFalse($form->isEmpty());
$this->assertSame('00000', $view->get('value')); $this->assertSame('00000', $view->getVar('value'));
$this->assertSame('00000', $form->getData()); $this->assertSame('00000', $form->getData());
} }
@ -507,7 +507,7 @@ class FormTypeTest extends TypeTestCase
$form = $this->factory->create('form'); $form = $this->factory->create('form');
$view = $form->createView(); $view = $form->createView();
$this->assertFalse($view->get('multipart')); $this->assertFalse($view->getVar('multipart'));
} }
public function testPassMultipartTrueIfAnyChildIsMultipartToView() public function testPassMultipartTrueIfAnyChildIsMultipartToView()
@ -517,7 +517,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->get('multipart')); $this->assertTrue($view->getVar('multipart'));
} }
public function testCreateViewDoNoMarkItAsRendered() public function testCreateViewDoNoMarkItAsRendered()
@ -603,7 +603,7 @@ class FormTypeTest extends TypeTestCase
{ {
$form = $this->factory->create('form'); $form = $this->factory->create('form');
$view = $form->createView(); $view = $form->createView();
$this->assertTrue($view->get('valid')); $this->assertTrue($view->getVar('valid'));
} }
public function testViewNotValidBound() public function testViewNotValidBound()
@ -612,6 +612,6 @@ 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->get('valid')); $this->assertFalse($view->getVar('valid'));
} }
} }

View File

@ -21,8 +21,7 @@ class LanguageTypeTest extends LocalizedTestCase
$form = $this->factory->create('language'); $form = $this->factory->create('language');
$view = $form->createView(); $view = $form->createView();
$choices = $view->get('choices'); $choices = $view->getVar('choices');
$labels = $view->get('choice_labels');
$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);
@ -35,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->get('choices'); $choices = $view->getVar('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->get('choices'); $choices = $view->getVar('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->get('money_pattern')); $this->assertSame('{{ widget }} €', $view->getVar('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->get('money_pattern'), '¥')); $this->assertTrue((Boolean) strstr($view->getVar('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->get('value')); $this->assertSame('12345,679', $view->getVar('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->get('value')); $this->assertSame('12.345,679', $view->getVar('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->get('value')); $this->assertSame('12345,68', $view->getVar('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->get('value')); $this->assertSame('12346', $view->getVar('value'));
} }
} }

View File

@ -20,7 +20,7 @@ class PasswordTypeTest extends TypeTestCase
$form->setData('pAs5w0rd'); $form->setData('pAs5w0rd');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->get('value')); $this->assertSame('', $view->getVar('value'));
} }
public function testEmptyIfBound() public function testEmptyIfBound()
@ -29,7 +29,7 @@ class PasswordTypeTest extends TypeTestCase
$form->bind('pAs5w0rd'); $form->bind('pAs5w0rd');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('', $view->get('value')); $this->assertSame('', $view->getVar('value'));
} }
public function testNotEmptyIfBoundAndNotAlwaysEmpty() public function testNotEmptyIfBoundAndNotAlwaysEmpty()
@ -38,6 +38,6 @@ class PasswordTypeTest extends TypeTestCase
$form->bind('pAs5w0rd'); $form->bind('pAs5w0rd');
$view = $form->createView(); $view = $form->createView();
$this->assertSame('pAs5w0rd', $view->get('value')); $this->assertSame('pAs5w0rd', $view->getVar('value'));
} }
} }

View File

@ -245,7 +245,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->getChild('hour')->get('choices')); ), $view->get('hour')->getVar('choices'));
} }
public function testIsMinuteWithinRange_returnsTrueIfWithin() public function testIsMinuteWithinRange_returnsTrueIfWithin()
@ -259,7 +259,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->getChild('minute')->get('choices')); ), $view->get('minute')->getVar('choices'));
} }
public function testIsSecondWithinRange_returnsTrueIfWithin() public function testIsSecondWithinRange_returnsTrueIfWithin()
@ -274,7 +274,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->getChild('second')->get('choices')); ), $view->get('second')->getVar('choices'));
} }
public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty() public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty()
@ -414,6 +414,6 @@ class TimeTypeTest extends LocalizedTestCase
)); ));
$view = $form->createView(); $view = $form->createView();
$this->assertEquals('time', $view->get('type')); $this->assertEquals('time', $view->getVar('type'));
} }
} }

View File

@ -19,8 +19,7 @@ class TimezoneTypeTest extends TypeTestCase
{ {
$form = $this->factory->create('timezone'); $form = $this->factory->create('timezone');
$view = $form->createView(); $view = $form->createView();
$choices = $view->get('choices'); $choices = $view->getVar('choices');
$labels = $view->get('choice_labels');
$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->hasChild('csrf')); $this->assertTrue($view->has('csrf'));
} }
public function testNoCsrfProtectionByDefaultIfNotSingleControlButNotRoot() public function testNoCsrfProtectionByDefaultIfNotSingleControlButNotRoot()
@ -80,9 +80,9 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
) )
->getForm() ->getForm()
->createView() ->createView()
->getChild('form'); ->get('form');
$this->assertFalse($view->hasChild('csrf')); $this->assertFalse($view->has('csrf'));
} }
public function testNoCsrfProtectionByDefaultIfRootButSingleControl() public function testNoCsrfProtectionByDefaultIfRootButSingleControl()
@ -94,7 +94,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertFalse($view->hasChild('csrf')); $this->assertFalse($view->has('csrf'));
} }
public function testCsrfProtectionCanBeDisabled() public function testCsrfProtectionCanBeDisabled()
@ -107,7 +107,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertFalse($view->hasChild('csrf')); $this->assertFalse($view->has('csrf'));
} }
public function testGenerateCsrfToken() public function testGenerateCsrfToken()
@ -126,7 +126,7 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
)) ))
->createView(); ->createView();
$this->assertEquals('token', $view->getChild('csrf')->get('value')); $this->assertEquals('token', $view->get('csrf')->getVar('value'));
} }
public function provideBoolean() public function provideBoolean()
@ -246,9 +246,9 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
'allow_add' => true, 'allow_add' => true,
)) ))
->createView() ->createView()
->get('prototype'); ->getVar('prototype');
$this->assertFalse($prototypeView->hasChild('csrf')); $this->assertFalse($prototypeView->has('csrf'));
$this->assertCount(1, $prototypeView); $this->assertCount(1, $prototypeView);
} }
} }