From d072f35ea0166004b6407d510ec9f484f8eef78a Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 14:57:09 +0200 Subject: [PATCH 1/9] [Form] The properties of FormView are now accessed directly in order to increase performance (PHP +200ms, Twig +150ms) --- .../Tests/Form/Type/EntityTypeTest.php | 10 +- .../Bridge/Twig/Extension/FormExtension.php | 2 +- .../Bridge/Twig/Form/TwigRendererEngine.php | 18 +- .../views/Form/form_enctype.html.php | 2 +- .../views/Form/form_widget_compound.html.php | 2 +- .../FormTable/form_widget_compound.html.php | 2 +- .../Templating/Helper/FormHelper.php | 32 ++-- .../Component/Form/AbstractRendererEngine.php | 26 +-- src/Symfony/Component/Form/AbstractType.php | 4 +- .../Component/Form/AbstractTypeExtension.php | 4 +- src/Symfony/Component/Form/CHANGELOG.md | 4 +- .../Form/Extension/Core/Type/CheckboxType.php | 6 +- .../Form/Extension/Core/Type/ChoiceType.php | 16 +- .../Extension/Core/Type/CollectionType.php | 14 +- .../Form/Extension/Core/Type/DateTimeType.php | 8 +- .../Form/Extension/Core/Type/DateType.php | 10 +- .../Form/Extension/Core/Type/FileType.php | 10 +- .../Form/Extension/Core/Type/FormType.php | 28 ++- .../Form/Extension/Core/Type/MoneyType.php | 6 +- .../Form/Extension/Core/Type/PasswordType.php | 6 +- .../Form/Extension/Core/Type/TextareaType.php | 6 +- .../Form/Extension/Core/Type/TimeType.php | 8 +- .../Csrf/Type/FormTypeCsrfExtension.php | 8 +- .../Templating/TemplatingRendererEngine.php | 16 +- src/Symfony/Component/Form/Form.php | 2 +- src/Symfony/Component/Form/FormInterface.php | 6 +- src/Symfony/Component/Form/FormRenderer.php | 28 +-- .../Form/FormRendererEngineInterface.php | 20 +-- .../Component/Form/FormRendererInterface.php | 32 ++-- .../Form/FormTypeExtensionInterface.php | 8 +- .../Component/Form/FormTypeInterface.php | 8 +- src/Symfony/Component/Form/FormView.php | 170 +++++++----------- .../Component/Form/FormViewInterface.php | 150 ---------------- .../Component/Form/ResolvedFormType.php | 13 +- .../Form/ResolvedFormTypeInterface.php | 6 +- .../Extension/Core/Type/CheckboxTypeTest.php | 10 +- .../Extension/Core/Type/ChoiceTypeTest.php | 28 +-- .../Core/Type/CollectionTypeTest.php | 4 +- .../Extension/Core/Type/CountryTypeTest.php | 4 +- .../Extension/Core/Type/DateTimeTypeTest.php | 80 ++++----- .../Extension/Core/Type/DateTypeTest.php | 78 ++++---- .../Extension/Core/Type/FileTypeTest.php | 2 +- .../Extension/Core/Type/FormTypeTest.php | 54 +++--- .../Extension/Core/Type/LanguageTypeTest.php | 4 +- .../Extension/Core/Type/LocaleTypeTest.php | 2 +- .../Extension/Core/Type/MoneyTypeTest.php | 4 +- .../Extension/Core/Type/NumberTypeTest.php | 8 +- .../Extension/Core/Type/PasswordTypeTest.php | 6 +- .../Extension/Core/Type/TimeTypeTest.php | 56 +++--- .../Extension/Core/Type/TimezoneTypeTest.php | 2 +- .../Csrf/Type/FormTypeCsrfExtensionTest.php | 18 +- .../Component/Form/Tests/FormRendererTest.php | 4 +- .../Form/Tests/FormViewInterface.php | 16 -- .../Form/Tests/ResolvedFormTypeTest.php | 7 +- .../Component/Form/Tests/SimpleFormTest.php | 10 +- 55 files changed, 438 insertions(+), 650 deletions(-) delete mode 100644 src/Symfony/Component/Form/FormViewInterface.php delete mode 100644 src/Symfony/Component/Form/Tests/FormViewInterface.php diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index aa17c4eca3603..9bf5358af4e47 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -124,7 +124,7 @@ public function testSetDataToUninitializedEntityWithNonRequired() '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() @@ -140,7 +140,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredToString() '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() @@ -159,7 +159,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder() '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 @@ public function testOverrideChoices() $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->assertSame($entity2, $field->getData()); $this->assertSame('2', $field->getClientData()); @@ -533,7 +533,7 @@ public function testGroupByChoices() 'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), 'Group2' => array(3 => new ChoiceView('3', 'Baz')), '4' => new ChoiceView('4', 'Boo!') - ), $field->createView()->getVar('choices')); + ), $field->createView()->vars['choices']); } public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier() diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index f07a8a486b7c3..f7206bd5f80cc 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -13,7 +13,7 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\Form\TwigRendererInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; /** diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php index 22d3688f4520d..df907cb9716b5 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -12,7 +12,7 @@ namespace Symfony\Bridge\Twig\Form; use Symfony\Component\Form\AbstractRendererEngine; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; /** * @author Bernhard Schussek @@ -40,9 +40,9 @@ public function setEnvironment(\Twig_Environment $environment) /** * {@inheritdoc} */ - public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array()) + public function renderBlock(FormView $view, $resource, $block, array $variables = array()) { - $cacheKey = $view->getVar(self::CACHE_KEY_VAR); + $cacheKey = $view->vars[self::CACHE_KEY_VAR]; $context = $this->environment->mergeGlobals($variables); @@ -71,12 +71,12 @@ public function renderBlock(FormViewInterface $view, $resource, $block, array $v * @see getResourceForBlock() * * @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. * * @return Boolean True if the resource could be loaded, false otherwise. */ - protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block) + protected function loadResourceForBlock($cacheKey, FormView $view, $block) { // The caller guarantees that $this->resources[$cacheKey][$block] is // not set, but it doesn't have to check whether $this->resources[$cacheKey] @@ -105,7 +105,7 @@ protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $blo } // 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) { $this->loadResourcesFromTheme($cacheKey, $this->defaultThemes[$i]); // CONTINUE LOADING (see doc comment) @@ -113,11 +113,11 @@ protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $blo } // Proceed with the themes of the parent view - if ($view->hasParent()) { - $parentCacheKey = $view->getParent()->getVar(self::CACHE_KEY_VAR); + if ($view->parent) { + $parentCacheKey = $view->parent->vars[self::CACHE_KEY_VAR]; if (!isset($this->resources[$parentCacheKey])) { - $this->loadResourceForBlock($parentCacheKey, $view->getParent(), $block); + $this->loadResourceForBlock($parentCacheKey, $view->parent, $block); } // EAGER CACHE POPULATION (see doc comment) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_enctype.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_enctype.html.php index 5a5e4b19faf61..36eba3c9e8e7a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_enctype.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_enctype.html.php @@ -1 +1 @@ -getVar('multipart')): ?>enctype="multipart/form-data" +vars['multipart']): ?>enctype="multipart/form-data" diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php index 6124d2f35946c..34a65bd542238 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php @@ -1,5 +1,5 @@
block('widget_container_attributes') ?>> - hasParent() && $errors): ?> + parent && $errors): ?> errors($form) ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_widget_compound.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_widget_compound.html.php index d4d0d08ee4c6a..86808af324a7f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_widget_compound.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_widget_compound.html.php @@ -1,5 +1,5 @@ block('widget_container_attributes') ?>> - hasParent()): ?> + parent): ?> errors($form) ?> block('form_rows') ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index b82f6efb11129..15eed3b9153f0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -13,7 +13,7 @@ use Symfony\Component\Templating\Helper\Helper; use Symfony\Component\Form\FormRendererInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; @@ -54,7 +54,7 @@ public function isChoiceGroup($label) return $this->renderer->isChoiceGroup($label); } - public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice) + public function isChoiceSelected(FormView $view, ChoiceView $choice) { return $this->renderer->isChoiceSelected($view, $choice); } @@ -64,10 +64,10 @@ public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice) * * The theme format is ":". * - * @param FormViewInterface $view A FormViewInterface instance + * @param FormView $view A FormView instance * @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); } @@ -79,11 +79,11 @@ public function setTheme(FormViewInterface $view, $themes) * *
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 */ - public function enctype(FormViewInterface $view) + public function enctype(FormView $view) { return $this->renderer->renderEnctype($view); } @@ -101,12 +101,12 @@ public function enctype(FormViewInterface $view) * * 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 * * @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); } @@ -114,12 +114,12 @@ public function widget(FormViewInterface $view, array $variables = array()) /** * 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 * * @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); } @@ -127,13 +127,13 @@ public function row(FormViewInterface $view, array $variables = array()) /** * 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 array $variables Additional variables passed to the template * * @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); } @@ -141,11 +141,11 @@ public function label(FormViewInterface $view, $label = null, array $variables = /** * 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 */ - public function errors(FormViewInterface $view) + public function errors(FormView $view) { return $this->renderer->renderErrors($view); } @@ -153,12 +153,12 @@ public function errors(FormViewInterface $view) /** * 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 * * @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); } diff --git a/src/Symfony/Component/Form/AbstractRendererEngine.php b/src/Symfony/Component/Form/AbstractRendererEngine.php index f3b403689bc03..371f4a0f1fbb6 100644 --- a/src/Symfony/Component/Form/AbstractRendererEngine.php +++ b/src/Symfony/Component/Form/AbstractRendererEngine.php @@ -19,7 +19,7 @@ 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'; @@ -57,9 +57,9 @@ public function __construct(array $defaultThemes = array()) /** * {@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 $this->themes[$cacheKey] = is_array($themes) ? $themes : array($themes); @@ -74,9 +74,9 @@ public function setTheme(FormViewInterface $view, $themes) /** * {@inheritdoc} */ - public function getResourceForBlock(FormViewInterface $view, $block) + public function getResourceForBlock(FormView $view, $block) { - $cacheKey = $view->getVar(self::CACHE_KEY_VAR); + $cacheKey = $view->vars[self::CACHE_KEY_VAR]; if (!isset($this->resources[$cacheKey][$block])) { $this->loadResourceForBlock($cacheKey, $view, $block); @@ -88,9 +88,9 @@ public function getResourceForBlock(FormViewInterface $view, $block) /** * {@inheritdoc} */ - public function getResourceForBlockHierarchy(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel) + public function getResourceForBlockHierarchy(FormView $view, array $blockHierarchy, $hierarchyLevel) { - $cacheKey = $view->getVar(self::CACHE_KEY_VAR); + $cacheKey = $view->vars[self::CACHE_KEY_VAR]; $block = $blockHierarchy[$hierarchyLevel]; if (!isset($this->resources[$cacheKey][$block])) { @@ -103,9 +103,9 @@ public function getResourceForBlockHierarchy(FormViewInterface $view, array $blo /** * {@inheritdoc} */ - public function getResourceHierarchyLevel(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel) + public function getResourceHierarchyLevel(FormView $view, array $blockHierarchy, $hierarchyLevel) { - $cacheKey = $view->getVar(self::CACHE_KEY_VAR); + $cacheKey = $view->vars[self::CACHE_KEY_VAR]; $block = $blockHierarchy[$hierarchyLevel]; if (!isset($this->resources[$cacheKey][$block])) { @@ -128,12 +128,12 @@ public function getResourceHierarchyLevel(FormViewInterface $view, array $blockH * @see getResourceForBlock() * * @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. * * @return Boolean True if the resource could be loaded, false otherwise. */ - abstract protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block); + abstract protected function loadResourceForBlock($cacheKey, FormView $view, $block); /** * Loads the cache with the resource for a specific level of a block hierarchy. @@ -142,7 +142,7 @@ abstract protected function loadResourceForBlock($cacheKey, FormViewInterface $v * * @param string $cacheKey The cache key used for storing the * resource. - * @param FormViewInterface $view The form view for finding the applying + * @param FormView $view The form view for finding the applying * themes. * @param array $blockHierarchy The block hierarchy, with the most * specific block name at the end. @@ -151,7 +151,7 @@ abstract protected function loadResourceForBlock($cacheKey, FormViewInterface $v * * @return Boolean True if the resource could be loaded, false otherwise. */ - private function loadResourceForBlockHierarchy($cacheKey, FormViewInterface $view, array $blockHierarchy, $hierarchyLevel) + private function loadResourceForBlockHierarchy($cacheKey, FormView $view, array $blockHierarchy, $hierarchyLevel) { $block = $blockHierarchy[$hierarchyLevel]; diff --git a/src/Symfony/Component/Form/AbstractType.php b/src/Symfony/Component/Form/AbstractType.php index 42b24e3650b63..21d0c58105c22 100644 --- a/src/Symfony/Component/Form/AbstractType.php +++ b/src/Symfony/Component/Form/AbstractType.php @@ -36,14 +36,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function buildView(FormViewInterface $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options) { } /** * {@inheritdoc} */ - public function finishView(FormViewInterface $view, FormInterface $form, array $options) + public function finishView(FormView $view, FormInterface $form, array $options) { } diff --git a/src/Symfony/Component/Form/AbstractTypeExtension.php b/src/Symfony/Component/Form/AbstractTypeExtension.php index b946bf4b97040..080b546b2d8c1 100644 --- a/src/Symfony/Component/Form/AbstractTypeExtension.php +++ b/src/Symfony/Component/Form/AbstractTypeExtension.php @@ -28,14 +28,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function buildView(FormViewInterface $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options) { } /** * {@inheritdoc} */ - public function finishView(FormViewInterface $view, FormInterface $form, array $options) + public function finishView(FormView $view, FormInterface $form, array $options) { } diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 279a2badbf611..e155a897f4d7e 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -113,9 +113,9 @@ CHANGELOG * deprecated the methods `getDefaultOptions` and `getAllowedOptionValues` in FormTypeInterface and FormTypeExtensionInterface * options passed during construction can now be accessed from FormConfigInterface - * added FormBuilderInterface, FormViewInterface and FormConfigEditorInterface + * added FormBuilderInterface, FormView and FormConfigEditorInterface * [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now - receive FormBuilderInterface and FormViewInterface instead of FormBuilder and + receive FormBuilderInterface and FormView instead of FormBuilder and FormView * [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in FormTypeInterface and FormTypeExtensionInterface diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php b/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php index 3feb6bd3ad3af..8d489d6db0cdd 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\BooleanToStringTransformer; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class CheckboxType extends AbstractType @@ -33,9 +33,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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'], 'checked' => null !== $form->getViewData(), )); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index bcda8d25595b2..3eedb5f6ef5de 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -14,7 +14,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; 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\Extension\Core\ChoiceList\ChoiceList; use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; @@ -79,9 +79,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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'], 'expanded' => $options['expanded'], 'preferred_choices' => $options['choice_list']->getPreferredViews(), @@ -93,25 +93,25 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o // Check if the choices already contain the empty value // Only add the empty value option if this is not the case 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']) { // 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 // POST request. - $view->setVar('full_name', $view->getVar('full_name').'[]'); + $view->vars['full_name'] = $view->vars['full_name'].'[]'; } } /** * {@inheritdoc} */ - public function finishView(FormViewInterface $view, FormInterface $form, array $options) + public function finishView(FormView $view, FormInterface $form, array $options) { if ($options['expanded']) { // 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 if ($options['multiple']) { @@ -119,7 +119,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $ } foreach ($view as $childView) { - $childView->setVar('full_name', $childName); + $childView->vars['full_name'] = $childName; } } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index cc88d3a686d97..4bd096a5811a0 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener; use Symfony\Component\OptionsResolver\Options; @@ -47,25 +47,25 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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_delete' => $options['allow_delete'], )); if ($form->getConfig()->hasAttribute('prototype')) { - $view->setVar('prototype', $form->getConfig()->getAttribute('prototype')->createView($view)); + $view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view); } } /** * {@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')) { - $view->setVar('multipart', true); + if ($form->getConfig()->hasAttribute('prototype') && $view->vars['prototype']->vars['multipart']) { + $view->vars['multipart'] = true; } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php index fd35f573ef7e8..e023fe72910e9 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php @@ -15,7 +15,7 @@ use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Form\ReversedTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; @@ -174,15 +174,15 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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 // * the widget is set to "single_text" // * the format matches the one expected by HTML5 if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) { - $view->setVar('type', 'datetime'); + $view->vars['type'] = 'datetime'; } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index ea1b091348eb1..5fbd8211b507d 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormBuilderInterface; 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\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; @@ -124,15 +124,15 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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 // * the widget is set to "single_text" // * the format matches the one expected by HTML5 if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) { - $view->setVar('type', 'date'); + $view->vars['type'] = 'date'; } if ($form->getConfig()->hasAttribute('formatter')) { @@ -147,7 +147,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $ $pattern = '{{ year }}-{{ month }}-{{ day }}'; } - $view->setVar('date_pattern', $pattern); + $view->vars['date_pattern'] = $pattern; } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index 373c5fcdbcf64..de74a90ed0662 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class FileType extends AbstractType @@ -21,9 +21,9 @@ class FileType extends AbstractType /** * {@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', 'value' => '', )); @@ -32,10 +32,10 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o /** * {@inheritdoc} */ - public function finishView(FormViewInterface $view, FormInterface $form, array $options) + public function finishView(FormView $view, FormInterface $form, array $options) { $view - ->setVar('multipart', true) + ->vars['multipart'] = true ; } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 0f7f9a2332ac9..724830ee405bd 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -16,7 +16,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; 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\TrimListener; use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; @@ -56,24 +56,22 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function buildView(FormViewInterface $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options) { $name = $form->getName(); $blockName = $options['block_name'] ?: $form->getName(); $readOnly = $options['read_only']; $translationDomain = $options['translation_domain']; - if ($view->hasParent()) { + if ($view->parent) { if ('' === $name) { throw new FormException('Form node with empty name can be used only as root form node.'); } - $parentView = $view->getParent(); - - if ('' !== ($parentFullName = $parentView->getVar('full_name'))) { - $id = sprintf('%s_%s', $parentView->getVar('id'), $name); + if ('' !== ($parentFullName = $view->parent->vars['full_name'])) { + $id = sprintf('%s_%s', $view->parent->vars['id'], $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 { $id = $name; $fullName = $name; @@ -82,11 +80,11 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o // Complex fields are read-only if they themselves or their parents are. if (!$readOnly) { - $readOnly = $parentView->getVar('read_only'); + $readOnly = $view->parent->vars['read_only']; } if (!$translationDomain) { - $translationDomain = $parentView->getVar('translation_domain'); + $translationDomain = $view->parent->vars['translation_domain']; } } else { $id = $name; @@ -108,7 +106,7 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o $translationDomain = 'messages'; } - $view->addVars(array( + $view->vars = array_replace($view->vars, array( 'form' => $view, 'id' => $id, 'name' => $name, @@ -136,18 +134,18 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o /** * {@inheritdoc} */ - public function finishView(FormViewInterface $view, FormInterface $form, array $options) + public function finishView(FormView $view, FormInterface $form, array $options) { $multipart = false; - foreach ($view as $child) { - if ($child->getVar('multipart')) { + foreach ($view->children as $child) { + if ($child->vars['multipart']) { $multipart = true; break; } } - $view->setVar('multipart', $multipart); + $view->vars['multipart'] = $multipart; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php index 4722b37e9b2cb..d4e557fe6f8d5 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class MoneyType extends AbstractType @@ -40,9 +40,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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']); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php b/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php index ac6a3c925ea47..14ece2ac50eaf 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php @@ -13,7 +13,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class PasswordType extends AbstractType @@ -21,10 +21,10 @@ class PasswordType extends AbstractType /** * {@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()) { - $view->setVar('value', ''); + $view->vars['value'] = ''; } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php b/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php index 31fe05813239d..0e749b155433a 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; class TextareaType extends AbstractType @@ -20,9 +20,9 @@ class TextareaType extends AbstractType /** * {@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; } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php index 99617ddf400fb..12f2ffd6b334d 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/TimeType.php @@ -18,7 +18,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; 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\OptionsResolverInterface; @@ -109,15 +109,15 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@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'], 'with_seconds' => $options['with_seconds'], )); if ('single_text' === $options['widget']) { - $view->setVar('type', 'time'); + $view->vars['type'] = 'time'; } } diff --git a/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php b/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php index c7eb63ada48ec..5d25007699289 100644 --- a/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php +++ b/src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; @@ -59,9 +59,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) * @param FormView $view The form view * @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'); $data = $options['csrf_provider']->generateCsrfToken($options['intention']); @@ -69,7 +69,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $ 'mapped' => false, )); - $view->add($csrfForm->createView($view)); + $view->children[$options['csrf_field_name']] = $csrfForm->createView($view); } } diff --git a/src/Symfony/Component/Form/Extension/Templating/TemplatingRendererEngine.php b/src/Symfony/Component/Form/Extension/Templating/TemplatingRendererEngine.php index 00f76e106dc4b..3ea3765f7b0f9 100644 --- a/src/Symfony/Component/Form/Extension/Templating/TemplatingRendererEngine.php +++ b/src/Symfony/Component/Form/Extension/Templating/TemplatingRendererEngine.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form\Extension\Templating; use Symfony\Component\Form\AbstractRendererEngine; -use Symfony\Component\Form\FormViewInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\Templating\EngineInterface; /** @@ -35,7 +35,7 @@ public function __construct(EngineInterface $engine, array $defaultThemes = arra /** * {@inheritdoc} */ - public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array()) + public function renderBlock(FormView $view, $resource, $block, array $variables = array()) { return trim($this->engine->render($resource, $variables)); } @@ -49,12 +49,12 @@ public function renderBlock(FormViewInterface $view, $resource, $block, array $v * @see getResourceForBlock() * * @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. * * @return Boolean True if the resource could be loaded, false otherwise. */ - protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $block) + protected function loadResourceForBlock($cacheKey, FormView $view, $block) { // 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. @@ -71,7 +71,7 @@ protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $blo } // 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) { if ($this->loadResourceFromTheme($cacheKey, $block, $this->defaultThemes[$i])) { return true; @@ -81,11 +81,11 @@ protected function loadResourceForBlock($cacheKey, FormViewInterface $view, $blo // If we did not find anything in the themes of the current view, proceed // with the themes of the parent view - if ($view->hasParent()) { - $parentCacheKey = $view->getParent()->getVar(self::CACHE_KEY_VAR); + if ($view->parent) { + $parentCacheKey = $view->parent->vars[self::CACHE_KEY_VAR]; if (!isset($this->resources[$parentCacheKey][$block])) { - $this->loadResourceForBlock($parentCacheKey, $view->getParent(), $block); + $this->loadResourceForBlock($parentCacheKey, $view->parent, $block); } // If a template exists in the parent themes, cache that template diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index a2383948e7dd2..760665ff4e94e 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -948,7 +948,7 @@ public function count() /** * {@inheritdoc} */ - public function createView(FormViewInterface $parent = null) + public function createView(FormView $parent = null) { if (null === $parent && $this->parent) { $parent = $this->parent->createView(); diff --git a/src/Symfony/Component/Form/FormInterface.php b/src/Symfony/Component/Form/FormInterface.php index b6dd1c1b98389..2f78d155d96e7 100644 --- a/src/Symfony/Component/Form/FormInterface.php +++ b/src/Symfony/Component/Form/FormInterface.php @@ -238,9 +238,9 @@ public function isRoot(); /** * 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); } diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index 738c01f17b740..08aa5a5ec9e49 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -69,7 +69,7 @@ public function getEngine() /** * {@inheritdoc} */ - public function setTheme(FormViewInterface $view, $themes) + public function setTheme(FormView $view, $themes) { $this->engine->setTheme($view, $themes); } @@ -77,7 +77,7 @@ public function setTheme(FormViewInterface $view, $themes) /** * {@inheritdoc} */ - public function renderEnctype(FormViewInterface $view) + public function renderEnctype(FormView $view) { return $this->renderSection($view, 'enctype'); } @@ -85,7 +85,7 @@ public function renderEnctype(FormViewInterface $view) /** * {@inheritdoc} */ - public function renderRow(FormViewInterface $view, array $variables = array()) + public function renderRow(FormView $view, array $variables = array()) { return $this->renderSection($view, 'row', $variables); } @@ -93,7 +93,7 @@ public function renderRow(FormViewInterface $view, array $variables = array()) /** * {@inheritdoc} */ - public function renderRest(FormViewInterface $view, array $variables = array()) + public function renderRest(FormView $view, array $variables = array()) { return $this->renderSection($view, 'rest', $variables); } @@ -101,7 +101,7 @@ public function renderRest(FormViewInterface $view, array $variables = array()) /** * {@inheritdoc} */ - public function renderWidget(FormViewInterface $view, array $variables = array()) + public function renderWidget(FormView $view, array $variables = array()) { return $this->renderSection($view, 'widget', $variables); } @@ -109,7 +109,7 @@ public function renderWidget(FormViewInterface $view, array $variables = array() /** * {@inheritdoc} */ - public function renderErrors(FormViewInterface $view) + public function renderErrors(FormView $view) { return $this->renderSection($view, 'errors'); } @@ -117,7 +117,7 @@ public function renderErrors(FormViewInterface $view) /** * {@inheritdoc} */ - public function renderLabel(FormViewInterface $view, $label = null, array $variables = array()) + public function renderLabel(FormView $view, $label = null, array $variables = array()) { if ($label !== null) { $variables += array('label' => $label); @@ -183,9 +183,9 @@ public function isChoiceGroup($choice) /** * {@inheritdoc} */ - public function isChoiceSelected(FormViewInterface $view, ChoiceView $choice) + public function isChoiceSelected(FormView $view, ChoiceView $choice) { - $value = $view->getVar('value'); + $value = $view->vars['value']; $choiceValue = $choice->getValue(); if (is_array($value)) { @@ -206,7 +206,7 @@ public function humanize($text) /** * Renders the given section of a form view. * - * @param FormViewInterface $view The form view. + * @param FormView $view The form view. * @param string $section The name of the section to render. * @param array $variables The variables to pass to the template. * @@ -214,7 +214,7 @@ public function humanize($text) * * @throws Exception\FormException If no fitting template was found. */ - protected function renderSection(FormViewInterface $view, $section, array $variables = array()) + protected function renderSection(FormView $view, $section, array $variables = array()) { $renderOnlyOnce = in_array($section, array('row', 'widget')); @@ -223,7 +223,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia } // The cache key for storing the variables and types - $mapKey = $uniqueBlockName = $view->getVar('full_block_name') . '_' . $section; + $mapKey = $uniqueBlockName = $view->vars['full_block_name'] . '_' . $section; // In templates, we have to deal with two kinds of block hierarchies: // @@ -257,7 +257,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia // Calculate the hierarchy of template blocks and start on // the bottom level of the hierarchy (= "__
" block) $blockHierarchy = array(); - foreach ($view->getVar('types') as $type) { + foreach ($view->vars['types'] as $type) { $blockHierarchy[] = $type . '_' . $section; } $blockHierarchy[] = $uniqueBlockName; @@ -265,7 +265,7 @@ protected function renderSection(FormViewInterface $view, $section, array $varia // The default variable scope contains all view variables, merged with // the variables passed explicitly to the helper - $scopeVariables = $view->getVars(); + $scopeVariables = $view->vars; } else { // RECURSIVE CALL // If a block recursively calls renderSection() again, resume rendering diff --git a/src/Symfony/Component/Form/FormRendererEngineInterface.php b/src/Symfony/Component/Form/FormRendererEngineInterface.php index aca8f75fb603e..a91704afa63c3 100644 --- a/src/Symfony/Component/Form/FormRendererEngineInterface.php +++ b/src/Symfony/Component/Form/FormRendererEngineInterface.php @@ -21,11 +21,11 @@ interface FormRendererEngineInterface /** * 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 * is open to the implementation. */ - public function setTheme(FormViewInterface $view, $themes); + public function setTheme(FormView $view, $themes); /** * Returns the resource for a block name. @@ -36,7 +36,7 @@ public function setTheme(FormViewInterface $view, $themes); * The type of the resource is decided by the implementation. The resource * 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 * view with {@link setTheme()} are considered, * then the ones of its parent etc. @@ -44,7 +44,7 @@ public function setTheme(FormViewInterface $view, $themes); * * @return mixed The renderer resource or false, if none was found. */ - public function getResourceForBlock(FormViewInterface $view, $block); + public function getResourceForBlock(FormView $view, $block); /** * Returns the resource for a block hierarchy. @@ -70,7 +70,7 @@ public function getResourceForBlock(FormViewInterface $view, $block); * The type of the resource is decided by the implementation. The resource * 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 used * themes. First the themes attached * directly to the view with * {@link setTheme()} are considered, @@ -84,7 +84,7 @@ public function getResourceForBlock(FormViewInterface $view, $block); * * @return mixed The renderer resource or false, if none was found. */ - public function getResourceForBlockHierarchy(FormViewInterface $view, array $blockHierarchy, $hierarchyLevel); + public function getResourceForBlockHierarchy(FormView $view, array $blockHierarchy, $hierarchyLevel); /** * Returns the hierarchy level at which a resource can be found. @@ -112,7 +112,7 @@ public function getResourceForBlockHierarchy(FormViewInterface $view, array $blo * The type of the resource is decided by the implementation. The resource * 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 used * themes. First the themes attached * directly to the view with * {@link setTheme()} are considered, @@ -126,7 +126,7 @@ public function getResourceForBlockHierarchy(FormViewInterface $view, array $blo * * @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 $blockHierarchy, $hierarchyLevel); /** * Renders a block in the given renderer resource. @@ -135,12 +135,12 @@ public function getResourceHierarchyLevel(FormViewInterface $view, array $blockH * or {@link getResourceForBlockHierarchy()}. The type of the resource is * 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 string $block The name of the block to render. * @param array $variables The variables to pass to the template. * * @return string The HTML markup. */ - public function renderBlock(FormViewInterface $view, $resource, $block, array $variables = array()); + public function renderBlock(FormView $view, $resource, $block, array $variables = array()); } diff --git a/src/Symfony/Component/Form/FormRendererInterface.php b/src/Symfony/Component/Form/FormRendererInterface.php index 1da338a3fd8b1..8ef742561649e 100644 --- a/src/Symfony/Component/Form/FormRendererInterface.php +++ b/src/Symfony/Component/Form/FormRendererInterface.php @@ -30,11 +30,11 @@ public function getEngine(); /** * 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 * 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. @@ -43,33 +43,33 @@ public function setTheme(FormViewInterface $view, $themes); * * renderEnctype($form) ?>> * - * @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 */ - public function renderEnctype(FormViewInterface $view); + public function renderEnctype(FormView $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 FormView $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()); + public function renderRow(FormView $view, array $variables = array()); /** * 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 * * @return string The HTML markup */ - public function renderRest(FormViewInterface $view, array $variables = array()); + public function renderRest(FormView $view, array $variables = array()); /** * Renders the HTML for a given view. @@ -84,32 +84,32 @@ public function renderRest(FormViewInterface $view, array $variables = array()); * * renderWidget($form, 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 * * @return string The HTML markup */ - public function renderWidget(FormViewInterface $view, array $variables = array()); + public function renderWidget(FormView $view, array $variables = array()); /** * 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 */ - public function renderErrors(FormViewInterface $view); + public function renderErrors(FormView $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 array $variables Additional variables passed to the template * * @return string The HTML markup */ - public function renderLabel(FormViewInterface $view, $label = null, array $variables = array()); + public function renderLabel(FormView $view, $label = null, array $variables = array()); /** * Renders a named block of the form theme. @@ -158,12 +158,12 @@ public function isChoiceGroup($choice); /** * Returns whether the given choice is selected. * - * @param FormViewInterface $view The view of the choice field + * @param FormView $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); + public function isChoiceSelected(FormView $view, ChoiceView $choice); /** * Makes a technical name human readable. diff --git a/src/Symfony/Component/Form/FormTypeExtensionInterface.php b/src/Symfony/Component/Form/FormTypeExtensionInterface.php index 2cbfc28f9b1a2..9866b28b64a6e 100644 --- a/src/Symfony/Component/Form/FormTypeExtensionInterface.php +++ b/src/Symfony/Component/Form/FormTypeExtensionInterface.php @@ -39,11 +39,11 @@ public function buildForm(FormBuilderInterface $builder, array $options); * * @see FormTypeInterface::buildView() * - * @param FormViewInterface $view The view + * @param FormView $view The view * @param FormInterface $form The form * @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. @@ -53,11 +53,11 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o * * @see FormTypeInterface::finishView() * - * @param FormViewInterface $view The view + * @param FormView $view The view * @param FormInterface $form The form * @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. diff --git a/src/Symfony/Component/Form/FormTypeInterface.php b/src/Symfony/Component/Form/FormTypeInterface.php index 00e96dd25b2a5..ef2846a83afd7 100644 --- a/src/Symfony/Component/Form/FormTypeInterface.php +++ b/src/Symfony/Component/Form/FormTypeInterface.php @@ -43,11 +43,11 @@ public function buildForm(FormBuilderInterface $builder, array $options); * * @see FormTypeExtensionInterface::buildView() * - * @param FormViewInterface $view The view + * @param FormView $view The view * @param FormInterface $form The form * @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. @@ -62,11 +62,11 @@ public function buildView(FormViewInterface $view, FormInterface $form, array $o * * @see FormTypeExtensionInterface::finishView() * - * @param FormViewInterface $view The view + * @param FormView $view The view * @param FormInterface $form The form * @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. diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index ad0ac4d2b2487..b0a73775b2252 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -14,18 +14,28 @@ /** * @author Bernhard Schussek */ -class FormView implements \IteratorAggregate, FormViewInterface +class FormView implements \ArrayAccess, \IteratorAggregate, \Countable { - private $name; - - private $vars = array( + /** + * The variables assigned to this view. + * @var array + */ + public $vars = array( 'value' => null, '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? @@ -38,61 +48,32 @@ class FormView implements \IteratorAggregate, FormViewInterface */ 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() { - return $this->name; - } - - /** - * {@inheritdoc} - */ - public function setVar($name, $value) - { - $this->vars[$name] = $value; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function hasVar($name) - { - return array_key_exists($name, $this->vars); + return $this->vars['name']; } /** - * {@inheritdoc} - */ - public function getVar($name, $default = null) - { - if (false === $this->hasVar($name)) { - return $default; - } - - return $this->vars[$name]; - } - - /** - * {@inheritdoc} - */ - public function addVars(array $vars) - { - $this->vars = array_replace($this->vars, $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() { @@ -106,6 +87,10 @@ public function getVars() * @param string $value The 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 which contains an + * entry named "attr". */ public function setAttribute($name, $value) { @@ -115,7 +100,9 @@ public function setAttribute($name, $value) } /** - * {@inheritdoc} + * Returns whether the view was already rendered. + * + * @return Boolean Whether this view's widget is rendered. */ public function isRendered() { @@ -139,7 +126,9 @@ public function isRendered() } /** - * {@inheritdoc} + * Marks the view as rendered. + * + * @return FormView The view object. */ public function setRendered() { @@ -149,9 +138,16 @@ public function setRendered() } /** - * {@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; @@ -159,7 +155,12 @@ public function setParent(FormViewInterface $parent = null) } /** - * {@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() { @@ -167,53 +168,18 @@ public function getParent() } /** - * {@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() { return null !== $this->parent; } - /** - * {@inheritdoc} - */ - public function add(FormViewInterface $child) - { - $this->children[$child->getName()] = $child; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function remove($name) - { - unset($this->children[$name]); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function all() - { - return $this->children; - } - - /** - * {@inheritdoc} - */ - public function get($name) - { - if (!isset($this->children[$name])) { - throw new \InvalidArgumentException(sprintf('Child "%s" does not exist.', $name)); - } - - return $this->children[$name]; - } - /** * Returns whether this view has any children. * @@ -227,14 +193,6 @@ public function hasChildren() return count($this->children) > 0; } - /** - * {@inheritdoc} - */ - public function has($name) - { - return isset($this->children[$name]); - } - /** * Returns a child by name (implements \ArrayAccess). * @@ -244,7 +202,7 @@ public function has($name) */ public function offsetGet($name) { - return $this->get($name); + return $this->children[$name]; } /** diff --git a/src/Symfony/Component/Form/FormViewInterface.php b/src/Symfony/Component/Form/FormViewInterface.php deleted file mode 100644 index bee156f62a0ac..0000000000000 --- a/src/Symfony/Component/Form/FormViewInterface.php +++ /dev/null @@ -1,150 +0,0 @@ - - * - * 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 - */ -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(); -} diff --git a/src/Symfony/Component/Form/ResolvedFormType.php b/src/Symfony/Component/Form/ResolvedFormType.php index 3a85679e266d9..8bbd7ae3a2497 100644 --- a/src/Symfony/Component/Form/ResolvedFormType.php +++ b/src/Symfony/Component/Form/ResolvedFormType.php @@ -130,18 +130,17 @@ public function createBuilder(FormFactoryInterface $factory, $name, array $optio /** * {@inheritdoc} */ - public function createView(FormInterface $form, FormViewInterface $parent = null) + public function createView(FormInterface $form, FormView $parent = null) { $options = $form->getConfig()->getOptions(); - $view = new FormView($form->getConfig()->getName()); - $view->setParent($parent); + $view = new FormView($parent); $this->buildView($view, $form, $options); - foreach ($form as $child) { + foreach ($form as $name => $child) { /* @var FormInterface $child */ - $view->add($child->createView($view)); + $view->children[$name] = $child->createView($view); } $this->finishView($view, $form, $options); @@ -163,7 +162,7 @@ private function buildForm(FormBuilderInterface $builder, array $options) } } - private function buildView(FormViewInterface $view, FormInterface $form, array $options) + private function buildView(FormView $view, FormInterface $form, array $options) { if (null !== $this->parent) { $this->parent->buildView($view, $form, $options); @@ -177,7 +176,7 @@ private function buildView(FormViewInterface $view, FormInterface $form, array $ } } - private function finishView(FormViewInterface $view, FormInterface $form, array $options) + private function finishView(FormView $view, FormInterface $form, array $options) { if (null !== $this->parent) { $this->parent->finishView($view, $form, $options); diff --git a/src/Symfony/Component/Form/ResolvedFormTypeInterface.php b/src/Symfony/Component/Form/ResolvedFormTypeInterface.php index 06209815441b5..cb9787c00aedb 100644 --- a/src/Symfony/Component/Form/ResolvedFormTypeInterface.php +++ b/src/Symfony/Component/Form/ResolvedFormTypeInterface.php @@ -62,9 +62,9 @@ public function createBuilder(FormFactoryInterface $factory, $name, array $optio * Creates a new form view for a form of this type. * * @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); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php index 1fd366ef54275..16a71d8f20002 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php @@ -20,7 +20,7 @@ public function testPassValueToView() $form = $this->factory->create('checkbox', null, array('value' => 'foobar')); $view = $form->createView(); - $this->assertEquals('foobar', $view->getVar('value')); + $this->assertEquals('foobar', $view->vars['value']); } public function testCheckedIfDataTrue() @@ -29,7 +29,7 @@ public function testCheckedIfDataTrue() $form->setData(true); $view = $form->createView(); - $this->assertTrue($view->getVar('checked')); + $this->assertTrue($view->vars['checked']); } public function testCheckedIfDataTrueWithEmptyValue() @@ -38,7 +38,7 @@ public function testCheckedIfDataTrueWithEmptyValue() $form->setData(true); $view = $form->createView(); - $this->assertTrue($view->getVar('checked')); + $this->assertTrue($view->vars['checked']); } public function testNotCheckedIfDataFalse() @@ -47,7 +47,7 @@ public function testNotCheckedIfDataFalse() $form->setData(false); $view = $form->createView(); - $this->assertFalse($view->getVar('checked')); + $this->assertFalse($view->vars['checked']); } public function testBindWithValueChecked() @@ -127,7 +127,7 @@ function ($value) { $form->setData($data); $view = $form->createView(); - $this->assertEquals($expected, $view->getVar('checked')); + $this->assertEquals($expected, $view->vars['checked']); } public function provideTransformedData() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 74f17b690d9dd..7b3490cb83a4d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -537,7 +537,7 @@ public function testPassRequiredToView() )); $view = $form->createView(); - $this->assertTrue($view->getVar('required')); + $this->assertTrue($view->vars['required']); } public function testPassNonRequiredToView() @@ -548,7 +548,7 @@ public function testPassNonRequiredToView() )); $view = $form->createView(); - $this->assertFalse($view->getVar('required')); + $this->assertFalse($view->vars['required']); } public function testPassMultipleToView() @@ -559,7 +559,7 @@ public function testPassMultipleToView() )); $view = $form->createView(); - $this->assertTrue($view->getVar('multiple')); + $this->assertTrue($view->vars['multiple']); } public function testPassExpandedToView() @@ -570,7 +570,7 @@ public function testPassExpandedToView() )); $view = $form->createView(); - $this->assertTrue($view->getVar('expanded')); + $this->assertTrue($view->vars['expanded']); } public function testNotPassedEmptyValueToViewIsNull() @@ -581,7 +581,7 @@ public function testNotPassedEmptyValueToViewIsNull() )); $view = $form->createView(); - $this->assertNull($view->getVar('empty_value')); + $this->assertNull($view->vars['empty_value']); } public function testPassEmptyValueToViewIsEmpty() @@ -593,7 +593,7 @@ public function testPassEmptyValueToViewIsEmpty() )); $view = $form->createView(); - $this->assertEmpty($view->getVar('empty_value')); + $this->assertEmpty($view->vars['empty_value']); } /** @@ -610,7 +610,7 @@ public function testPassEmptyValueToView($multiple, $expanded, $required, $empty )); $view = $form->createView(); - $this->assertEquals($viewValue, $view->getVar('empty_value')); + $this->assertEquals($viewValue, $view->vars['empty_value']); } /** @@ -627,7 +627,7 @@ public function testDontPassEmptyValueIfContainedInChoices($multiple, $expanded, )); $view = $form->createView(); - $this->assertNull($view->getVar('empty_value')); + $this->assertNull($view->vars['empty_value']); } public function getOptionsWithEmptyValue() @@ -658,7 +658,7 @@ public function testPassChoicesToView() new ChoiceView('b', 'B'), new ChoiceView('c', 'C'), new ChoiceView('d', 'D'), - ), $view->getVar('choices')); + ), $view->vars['choices']); } public function testPassPreferredChoicesToView() @@ -673,11 +673,11 @@ public function testPassPreferredChoicesToView() $this->assertEquals(array( 0 => new ChoiceView('a', 'A'), 2 => new ChoiceView('c', 'C'), - ), $view->getVar('choices')); + ), $view->vars['choices']); $this->assertEquals(array( 1 => new ChoiceView('b', 'B'), 3 => new ChoiceView('d', 'D'), - ), $view->getVar('preferred_choices')); + ), $view->vars['preferred_choices']); } public function testPassHierarchicalChoicesToView() @@ -696,7 +696,7 @@ public function testPassHierarchicalChoicesToView() 'Doctrine' => array( 4 => new ChoiceView('e', 'Roman'), ), - ), $view->getVar('choices')); + ), $view->vars['choices']); $this->assertEquals(array( 'Symfony' => array( 1 => new ChoiceView('b', 'Fabien'), @@ -704,7 +704,7 @@ public function testPassHierarchicalChoicesToView() 'Doctrine' => array( 3 => new ChoiceView('d', 'Jon'), ), - ), $view->getVar('preferred_choices')); + ), $view->vars['preferred_choices']); } public function testAdjustFullNameForMultipleNonExpanded() @@ -716,7 +716,7 @@ public function testAdjustFullNameForMultipleNonExpanded() )); $view = $form->createView(); - $this->assertSame('name[]', $view->getVar('full_name')); + $this->assertSame('name[]', $view->vars['full_name']); } // https://github.com/symfony/symfony/issues/3298 diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index 2ad120297c1eb..aa79fa060efc7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -138,7 +138,7 @@ public function testPrototypeMultipartPropagation() )) ; - $this->assertTrue($form->createView()->getVar('multipart')); + $this->assertTrue($form->createView()->vars['multipart']); } public function testGetDataDoesNotContainsProtypeNameBeforeDataAreSet() @@ -195,6 +195,6 @@ public function testPrototypeDefaultLabel() 'prototype_name' => '__test__', )); - $this->assertSame('__test__label__', $form->createView()->getVar('prototype')->getVar('label')); + $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index 4ad3598417519..298d9118f74a9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -21,7 +21,7 @@ public function testCountriesAreSelectable() $form = $this->factory->create('country'); $view = $form->createView(); - $choices = $view->getVar('choices'); + $choices = $view->vars['choices']; // Don't check objects for identity $this->assertContains(new ChoiceView('DE', 'Deutschland'), $choices, '', false, false); @@ -35,7 +35,7 @@ public function testUnknownCountryIsNotIncluded() { $form = $this->factory->create('country', 'country'); $view = $form->createView(); - $choices = $view->getVar('choices'); + $choices = $view->vars['choices']; foreach ($choices as $choice) { if ('ZZ' === $choice->getValue()) { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index a7d5f8b563b54..4c0174de08e69 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -238,7 +238,7 @@ public function testSingleTextWidgetShouldUseTheRightInputType() )); $view = $form->createView(); - $this->assertEquals('datetime', $view->getVar('type')); + $this->assertEquals('datetime', $view->vars['type']); } public function testPassDefaultEmptyValueToViewIfNotRequired() @@ -249,12 +249,12 @@ public function testPassDefaultEmptyValueToViewIfNotRequired() )); $view = $form->createView(); - $this->assertSame('', $view->get('date')->get('year')->getVar('empty_value')); - $this->assertSame('', $view->get('date')->get('month')->getVar('empty_value')); - $this->assertSame('', $view->get('date')->get('day')->getVar('empty_value')); - $this->assertSame('', $view->get('time')->get('hour')->getVar('empty_value')); - $this->assertSame('', $view->get('time')->get('minute')->getVar('empty_value')); - $this->assertSame('', $view->get('time')->get('second')->getVar('empty_value')); + $this->assertSame('', $view['date']['year']->vars['empty_value']); + $this->assertSame('', $view['date']['month']->vars['empty_value']); + $this->assertSame('', $view['date']['day']->vars['empty_value']); + $this->assertSame('', $view['time']['hour']->vars['empty_value']); + $this->assertSame('', $view['time']['minute']->vars['empty_value']); + $this->assertSame('', $view['time']['second']->vars['empty_value']); } public function testPassNoEmptyValueToViewIfRequired() @@ -265,12 +265,12 @@ public function testPassNoEmptyValueToViewIfRequired() )); $view = $form->createView(); - $this->assertNull($view->get('date')->get('year')->getVar('empty_value')); - $this->assertNull($view->get('date')->get('month')->getVar('empty_value')); - $this->assertNull($view->get('date')->get('day')->getVar('empty_value')); - $this->assertNull($view->get('time')->get('hour')->getVar('empty_value')); - $this->assertNull($view->get('time')->get('minute')->getVar('empty_value')); - $this->assertNull($view->get('time')->get('second')->getVar('empty_value')); + $this->assertNull($view['date']['year']->vars['empty_value']); + $this->assertNull($view['date']['month']->vars['empty_value']); + $this->assertNull($view['date']['day']->vars['empty_value']); + $this->assertNull($view['time']['hour']->vars['empty_value']); + $this->assertNull($view['time']['minute']->vars['empty_value']); + $this->assertNull($view['time']['second']->vars['empty_value']); } public function testPassEmptyValueAsString() @@ -281,12 +281,12 @@ public function testPassEmptyValueAsString() )); $view = $form->createView(); - $this->assertSame('Empty', $view->get('date')->get('year')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('date')->get('month')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('date')->get('day')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('time')->get('hour')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('time')->get('minute')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('time')->get('second')->getVar('empty_value')); + $this->assertSame('Empty', $view['date']['year']->vars['empty_value']); + $this->assertSame('Empty', $view['date']['month']->vars['empty_value']); + $this->assertSame('Empty', $view['date']['day']->vars['empty_value']); + $this->assertSame('Empty', $view['time']['hour']->vars['empty_value']); + $this->assertSame('Empty', $view['time']['minute']->vars['empty_value']); + $this->assertSame('Empty', $view['time']['second']->vars['empty_value']); } public function testPassEmptyValueAsArray() @@ -304,12 +304,12 @@ public function testPassEmptyValueAsArray() )); $view = $form->createView(); - $this->assertSame('Empty year', $view->get('date')->get('year')->getVar('empty_value')); - $this->assertSame('Empty month', $view->get('date')->get('month')->getVar('empty_value')); - $this->assertSame('Empty day', $view->get('date')->get('day')->getVar('empty_value')); - $this->assertSame('Empty hour', $view->get('time')->get('hour')->getVar('empty_value')); - $this->assertSame('Empty minute', $view->get('time')->get('minute')->getVar('empty_value')); - $this->assertSame('Empty second', $view->get('time')->get('second')->getVar('empty_value')); + $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']); + $this->assertSame('Empty month', $view['date']['month']->vars['empty_value']); + $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']); + $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']); + $this->assertSame('Empty minute', $view['time']['minute']->vars['empty_value']); + $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']); } public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() @@ -326,12 +326,12 @@ public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() )); $view = $form->createView(); - $this->assertSame('Empty year', $view->get('date')->get('year')->getVar('empty_value')); - $this->assertSame('', $view->get('date')->get('month')->getVar('empty_value')); - $this->assertSame('Empty day', $view->get('date')->get('day')->getVar('empty_value')); - $this->assertSame('Empty hour', $view->get('time')->get('hour')->getVar('empty_value')); - $this->assertSame('', $view->get('time')->get('minute')->getVar('empty_value')); - $this->assertSame('Empty second', $view->get('time')->get('second')->getVar('empty_value')); + $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']); + $this->assertSame('', $view['date']['month']->vars['empty_value']); + $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']); + $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']); + $this->assertSame('', $view['time']['minute']->vars['empty_value']); + $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']); } public function testPassEmptyValueAsPartialArray_addNullIfRequired() @@ -348,12 +348,12 @@ public function testPassEmptyValueAsPartialArray_addNullIfRequired() )); $view = $form->createView(); - $this->assertSame('Empty year', $view->get('date')->get('year')->getVar('empty_value')); - $this->assertNull($view->get('date')->get('month')->getVar('empty_value')); - $this->assertSame('Empty day', $view->get('date')->get('day')->getVar('empty_value')); - $this->assertSame('Empty hour', $view->get('time')->get('hour')->getVar('empty_value')); - $this->assertNull($view->get('time')->get('minute')->getVar('empty_value')); - $this->assertSame('Empty second', $view->get('time')->get('second')->getVar('empty_value')); + $this->assertSame('Empty year', $view['date']['year']->vars['empty_value']); + $this->assertNull($view['date']['month']->vars['empty_value']); + $this->assertSame('Empty day', $view['date']['day']->vars['empty_value']); + $this->assertSame('Empty hour', $view['time']['hour']->vars['empty_value']); + $this->assertNull($view['time']['minute']->vars['empty_value']); + $this->assertSame('Empty second', $view['time']['second']->vars['empty_value']); } public function testPassHtml5TypeIfSingleTextAndHtml5Format() @@ -363,7 +363,7 @@ public function testPassHtml5TypeIfSingleTextAndHtml5Format() )); $view = $form->createView(); - $this->assertSame('datetime', $view->getVar('type')); + $this->assertSame('datetime', $view->vars['type']); } public function testDontPassHtml5TypeIfNotHtml5Format() @@ -374,7 +374,7 @@ public function testDontPassHtml5TypeIfNotHtml5Format() )); $view = $form->createView(); - $this->assertNull($view->getVar('datetime')); + $this->assertFalse(isset($view->vars['type'])); } public function testDontPassHtml5TypeIfNotSingleText() @@ -384,6 +384,6 @@ public function testDontPassHtml5TypeIfNotSingleText() )); $view = $form->createView(); - $this->assertNull($view->getVar('type')); + $this->assertFalse(isset($view->vars['type'])); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index b618902b04da1..158d416949799 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -357,7 +357,7 @@ public function testYearsOption() $this->assertEquals(array( new ChoiceView('2010', '2010'), new ChoiceView('2011', '2011'), - ), $view->get('year')->getVar('choices')); + ), $view['year']->vars['choices']); } public function testMonthsOption() @@ -371,7 +371,7 @@ public function testMonthsOption() $this->assertEquals(array( new ChoiceView('6', '06'), new ChoiceView('7', '07'), - ), $view->get('month')->getVar('choices')); + ), $view['month']->vars['choices']); } public function testMonthsOptionShortFormat() @@ -386,7 +386,7 @@ public function testMonthsOptionShortFormat() $this->assertEquals(array( new ChoiceView('1', 'Jän'), new ChoiceView('4', 'Apr') - ), $view->get('month')->getVar('choices')); + ), $view['month']->vars['choices']); } public function testMonthsOptionLongFormat() @@ -401,7 +401,7 @@ public function testMonthsOptionLongFormat() $this->assertEquals(array( new ChoiceView('1', 'Jänner'), new ChoiceView('4', 'April'), - ), $view->get('month')->getVar('choices')); + ), $view['month']->vars['choices']); } public function testMonthsOptionLongFormatWithDifferentTimezone() @@ -416,7 +416,7 @@ public function testMonthsOptionLongFormatWithDifferentTimezone() $this->assertEquals(array( new ChoiceView('1', 'Jänner'), new ChoiceView('4', 'April'), - ), $view->get('month')->getVar('choices')); + ), $view['month']->vars['choices']); } public function testIsDayWithinRangeReturnsTrueIfWithin() @@ -430,7 +430,7 @@ public function testIsDayWithinRangeReturnsTrueIfWithin() $this->assertEquals(array( new ChoiceView('6', '06'), new ChoiceView('7', '07'), - ), $view->get('day')->getVar('choices')); + ), $view['day']->vars['choices']); } public function testIsPartiallyFilledReturnsFalseIfSingleText() @@ -510,7 +510,7 @@ public function testPassDatePatternToView() $form = $this->factory->create('date'); $view = $form->createView(); - $this->assertSame('{{ year }}-{{ month }}-{{ day }}', $view->getVar('date_pattern')); + $this->assertSame('{{ year }}-{{ month }}-{{ day }}', $view->vars['date_pattern']); } public function testPassDatePatternToViewDifferentFormat() @@ -521,7 +521,7 @@ public function testPassDatePatternToViewDifferentFormat() $view = $form->createView(); - $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->getVar('date_pattern')); + $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']); } public function testPassDatePatternToViewDifferentPattern() @@ -532,7 +532,7 @@ public function testPassDatePatternToViewDifferentPattern() $view = $form->createView(); - $this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->getVar('date_pattern')); + $this->assertSame('{{ month }}*{{ year }}*{{ day }}', $view->vars['date_pattern']); } public function testDontPassDatePatternIfText() @@ -542,7 +542,7 @@ public function testDontPassDatePatternIfText() )); $view = $form->createView(); - $this->assertNull($view->getVar('date_pattern')); + $this->assertFalse(isset($view->vars['date_pattern'])); } public function testPassWidgetToView() @@ -552,7 +552,7 @@ public function testPassWidgetToView() )); $view = $form->createView(); - $this->assertSame('single_text', $view->getVar('widget')); + $this->assertSame('single_text', $view->vars['widget']); } // Bug fix @@ -570,7 +570,7 @@ public function testSingleTextWidgetShouldUseTheRightInputType() )); $view = $form->createView(); - $this->assertEquals('date', $view->getVar('type')); + $this->assertEquals('date', $view->vars['type']); } public function testPassDefaultEmptyValueToViewIfNotRequired() @@ -580,9 +580,9 @@ public function testPassDefaultEmptyValueToViewIfNotRequired() )); $view = $form->createView(); - $this->assertSame('', $view->get('year')->getVar('empty_value')); - $this->assertSame('', $view->get('month')->getVar('empty_value')); - $this->assertSame('', $view->get('day')->getVar('empty_value')); + $this->assertSame('', $view['year']->vars['empty_value']); + $this->assertSame('', $view['month']->vars['empty_value']); + $this->assertSame('', $view['day']->vars['empty_value']); } public function testPassNoEmptyValueToViewIfRequired() @@ -592,9 +592,9 @@ public function testPassNoEmptyValueToViewIfRequired() )); $view = $form->createView(); - $this->assertNull($view->get('year')->getVar('empty_value')); - $this->assertNull($view->get('month')->getVar('empty_value')); - $this->assertNull($view->get('day')->getVar('empty_value')); + $this->assertNull($view['year']->vars['empty_value']); + $this->assertNull($view['month']->vars['empty_value']); + $this->assertNull($view['day']->vars['empty_value']); } public function testPassEmptyValueAsString() @@ -604,9 +604,9 @@ public function testPassEmptyValueAsString() )); $view = $form->createView(); - $this->assertSame('Empty', $view->get('year')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('month')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('day')->getVar('empty_value')); + $this->assertSame('Empty', $view['year']->vars['empty_value']); + $this->assertSame('Empty', $view['month']->vars['empty_value']); + $this->assertSame('Empty', $view['day']->vars['empty_value']); } public function testPassEmptyValueAsArray() @@ -620,9 +620,9 @@ public function testPassEmptyValueAsArray() )); $view = $form->createView(); - $this->assertSame('Empty year', $view->get('year')->getVar('empty_value')); - $this->assertSame('Empty month', $view->get('month')->getVar('empty_value')); - $this->assertSame('Empty day', $view->get('day')->getVar('empty_value')); + $this->assertSame('Empty year', $view['year']->vars['empty_value']); + $this->assertSame('Empty month', $view['month']->vars['empty_value']); + $this->assertSame('Empty day', $view['day']->vars['empty_value']); } public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() @@ -636,9 +636,9 @@ public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() )); $view = $form->createView(); - $this->assertSame('Empty year', $view->get('year')->getVar('empty_value')); - $this->assertSame('', $view->get('month')->getVar('empty_value')); - $this->assertSame('Empty day', $view->get('day')->getVar('empty_value')); + $this->assertSame('Empty year', $view['year']->vars['empty_value']); + $this->assertSame('', $view['month']->vars['empty_value']); + $this->assertSame('Empty day', $view['day']->vars['empty_value']); } public function testPassEmptyValueAsPartialArray_addNullIfRequired() @@ -652,9 +652,9 @@ public function testPassEmptyValueAsPartialArray_addNullIfRequired() )); $view = $form->createView(); - $this->assertSame('Empty year', $view->get('year')->getVar('empty_value')); - $this->assertNull($view->get('month')->getVar('empty_value')); - $this->assertSame('Empty day', $view->get('day')->getVar('empty_value')); + $this->assertSame('Empty year', $view['year']->vars['empty_value']); + $this->assertNull($view['month']->vars['empty_value']); + $this->assertSame('Empty day', $view['day']->vars['empty_value']); } public function testPassHtml5TypeIfSingleTextAndHtml5Format() @@ -664,7 +664,7 @@ public function testPassHtml5TypeIfSingleTextAndHtml5Format() )); $view = $form->createView(); - $this->assertSame('date', $view->getVar('type')); + $this->assertSame('date', $view->vars['type']); } public function testDontPassHtml5TypeIfNotHtml5Format() @@ -675,7 +675,7 @@ public function testDontPassHtml5TypeIfNotHtml5Format() )); $view = $form->createView(); - $this->assertNull($view->getVar('type')); + $this->assertFalse(isset($view->vars['type'])); } public function testDontPassHtml5TypeIfNotSingleText() @@ -685,7 +685,7 @@ public function testDontPassHtml5TypeIfNotSingleText() )); $view = $form->createView(); - $this->assertNull($view->getVar('type')); + $this->assertFalse(isset($view->vars['type'])); } public function provideCompoundWidgets() @@ -705,9 +705,9 @@ public function testYearErrorsBubbleUp($widget) $form = $this->factory->create('date', null, array( '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()); } @@ -720,9 +720,9 @@ public function testMonthErrorsBubbleUp($widget) $form = $this->factory->create('date', null, array( '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()); } @@ -735,9 +735,9 @@ public function testDayErrorsBubbleUp($widget) $form = $this->factory->create('date', null, array( '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()); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php index d98513072fcbb..dbd098b68d99e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php @@ -23,7 +23,7 @@ public function testDontPassValueToView() )); $view = $form->createView(); - $this->assertEquals('', $view->getVar('value')); + $this->assertEquals('', $view->vars['value']); } private function createUploadedFileMock($name, $originalName, $valid) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 81e96c6944045..8fe84a65a29b9 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -107,9 +107,9 @@ public function testPassIdAndNameToView() $form = $this->factory->createNamed('name', 'form'); $view = $form->createView(); - $this->assertEquals('name', $view->getVar('id')); - $this->assertEquals('name', $view->getVar('name')); - $this->assertEquals('name', $view->getVar('full_name')); + $this->assertEquals('name', $view->vars['id']); + $this->assertEquals('name', $view->vars['name']); + $this->assertEquals('name', $view->vars['full_name']); } public function testStripLeadingUnderscoresAndDigitsFromId() @@ -117,9 +117,9 @@ public function testStripLeadingUnderscoresAndDigitsFromId() $form = $this->factory->createNamed('_09name', 'form'); $view = $form->createView(); - $this->assertEquals('name', $view->getVar('id')); - $this->assertEquals('_09name', $view->getVar('name')); - $this->assertEquals('_09name', $view->getVar('full_name')); + $this->assertEquals('name', $view->vars['id']); + $this->assertEquals('_09name', $view->vars['name']); + $this->assertEquals('_09name', $view->vars['full_name']); } public function testPassIdAndNameToViewWithParent() @@ -128,9 +128,9 @@ public function testPassIdAndNameToViewWithParent() $parent->add($this->factory->createNamed('child', 'form')); $view = $parent->createView(); - $this->assertEquals('parent_child', $view['child']->getVar('id')); - $this->assertEquals('child', $view['child']->getVar('name')); - $this->assertEquals('parent[child]', $view['child']->getVar('full_name')); + $this->assertEquals('parent_child', $view['child']->vars['id']); + $this->assertEquals('child', $view['child']->vars['name']); + $this->assertEquals('parent[child]', $view['child']->vars['full_name']); } public function testPassIdAndNameToViewWithGrandParent() @@ -140,9 +140,9 @@ public function testPassIdAndNameToViewWithGrandParent() $parent['child']->add($this->factory->createNamed('grand_child', 'form')); $view = $parent->createView(); - $this->assertEquals('parent_child_grand_child', $view['child']['grand_child']->getVar('id')); - $this->assertEquals('grand_child', $view['child']['grand_child']->getVar('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['id']); + $this->assertEquals('grand_child', $view['child']['grand_child']->vars['name']); + $this->assertEquals('parent[child][grand_child]', $view['child']['grand_child']->vars['full_name']); } public function testNonReadOnlyFormWithReadOnlyParentBeingReadOnly() @@ -151,7 +151,7 @@ public function testNonReadOnlyFormWithReadOnlyParentBeingReadOnly() $child = $this->factory->createNamed('child', 'form'); $view = $parent->add($child)->createView(); - $this->assertTrue($view['child']->getVar('read_only')); + $this->assertTrue($view['child']->vars['read_only']); } public function testReadOnlyFormWithNonReadOnlyParentBeingReadOnly() @@ -160,7 +160,7 @@ public function testReadOnlyFormWithNonReadOnlyParentBeingReadOnly() $child = $this->factory->createNamed('child', 'form', null, array('read_only' => true)); $view = $parent->add($child)->createView(); - $this->assertTrue($view['child']->getVar('read_only')); + $this->assertTrue($view['child']->vars['read_only']); } public function testNonReadOnlyFormWithNonReadOnlyParentBeingNonReadOnly() @@ -169,7 +169,7 @@ public function testNonReadOnlyFormWithNonReadOnlyParentBeingNonReadOnly() $child = $this->factory->createNamed('child', 'form'); $view = $parent->add($child)->createView(); - $this->assertFalse($view['child']->getVar('read_only')); + $this->assertFalse($view['child']->vars['read_only']); } public function testPassMaxLengthToView() @@ -177,7 +177,7 @@ public function testPassMaxLengthToView() $form = $this->factory->create('form', null, array('max_length' => 10)); $view = $form->createView(); - $this->assertSame(10, $view->getVar('max_length')); + $this->assertSame(10, $view->vars['max_length']); } public function testPassTranslationDomainToView() @@ -185,7 +185,7 @@ public function testPassTranslationDomainToView() $form = $this->factory->create('form', null, array('translation_domain' => 'test')); $view = $form->createView(); - $this->assertSame('test', $view->getVar('translation_domain')); + $this->assertSame('test', $view->vars['translation_domain']); } public function testNonTranslationDomainFormWithTranslationDomainParentBeingTranslationDomain() @@ -194,7 +194,7 @@ public function testNonTranslationDomainFormWithTranslationDomainParentBeingTran $child = $this->factory->createNamed('child', 'form'); $view = $parent->add($child)->createView(); - $this->assertEquals('test', $view['child']->getVar('translation_domain')); + $this->assertEquals('test', $view['child']->vars['translation_domain']); } public function testTranslationDomainFormWithNonTranslationDomainParentBeingTranslationDomain() @@ -203,7 +203,7 @@ public function testTranslationDomainFormWithNonTranslationDomainParentBeingTran $child = $this->factory->createNamed('child', 'form', null, array('translation_domain' => 'test')); $view = $parent->add($child)->createView(); - $this->assertEquals('test', $view['child']->getVar('translation_domain')); + $this->assertEquals('test', $view['child']->vars['translation_domain']); } public function testNonTranlsationDomainFormWithNonTranslationDomainParentBeingTranslationDomainDefault() @@ -212,7 +212,7 @@ public function testNonTranlsationDomainFormWithNonTranslationDomainParentBeingT $child = $this->factory->createNamed('child', 'form'); $view = $parent->add($child)->createView(); - $this->assertEquals('messages', $view['child']->getVar('translation_domain')); + $this->assertEquals('messages', $view['child']->vars['translation_domain']); } public function testPassLabelToView() @@ -220,7 +220,7 @@ public function testPassLabelToView() $form = $this->factory->createNamed('__test___field', 'form', null, array('label' => 'My label')); $view = $form->createView(); - $this->assertSame('My label', $view->getVar('label')); + $this->assertSame('My label', $view->vars['label']); } public function testDefaultTranslationDomain() @@ -228,7 +228,7 @@ public function testDefaultTranslationDomain() $form = $this->factory->create('form'); $view = $form->createView(); - $this->assertSame('messages', $view->getVar('translation_domain')); + $this->assertSame('messages', $view->vars['translation_domain']); } public function testBindWithEmptyDataCreatesObjectIfClassAvailable() @@ -386,7 +386,7 @@ public function testSetDataThroughParamsWithZero($data, $dataAsString) $this->assertFalse($form->isEmpty()); - $this->assertSame($dataAsString, $view->getVar('value')); + $this->assertSame($dataAsString, $view->vars['value']); $this->assertSame($dataAsString, $form->getData()); } @@ -526,7 +526,7 @@ public function testPassMultipartFalseToView() $form = $this->factory->create('form'); $view = $form->createView(); - $this->assertFalse($view->getVar('multipart')); + $this->assertFalse($view->vars['multipart']); } public function testPassMultipartTrueIfAnyChildIsMultipartToView() @@ -536,7 +536,7 @@ public function testPassMultipartTrueIfAnyChildIsMultipartToView() $form->add($this->factory->create('file')); $view = $form->createView(); - $this->assertTrue($view->getVar('multipart')); + $this->assertTrue($view->vars['multipart']); } public function testCreateViewDoNoMarkItAsRendered() @@ -622,7 +622,7 @@ public function testViewValidUnbound() { $form = $this->factory->create('form'); $view = $form->createView(); - $this->assertTrue($view->getVar('valid')); + $this->assertTrue($view->vars['valid']); } public function testViewNotValidBound() @@ -631,7 +631,7 @@ public function testViewNotValidBound() $form->bind(array()); $form->addError(new FormError('An error')); $view = $form->createView(); - $this->assertFalse($view->getVar('valid')); + $this->assertFalse($view->vars['valid']); } public function testDataOptionSupersedesSetDataCalls() diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php index 53417086b8b39..399ae6e5f5764 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php @@ -21,7 +21,7 @@ public function testCountriesAreSelectable() $form = $this->factory->create('language'); $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_GB', 'Britisches Englisch'), $choices, '', false, false); @@ -34,7 +34,7 @@ public function testMultipleLanguagesIsNotIncluded() { $form = $this->factory->create('language', 'language'); $view = $form->createView(); - $choices = $view->getVar('choices'); + $choices = $view->vars['choices']; $this->assertNotContains(new ChoiceView('mul', 'Mehrsprachig'), $choices, '', false, false); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php index 2e523a5df1407..4c2e195f0b506 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php @@ -21,7 +21,7 @@ public function testLocalesAreSelectable() $form = $this->factory->create('locale'); $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_GB', 'Englisch (Vereinigtes Königreich)'), $choices, '', false, false); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php index 42f982642ab63..005c7131ada06 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php @@ -20,7 +20,7 @@ public function testPassMoneyPatternToView() $form = $this->factory->create('money'); $view = $form->createView(); - $this->assertSame('{{ widget }} €', $view->getVar('money_pattern')); + $this->assertSame('{{ widget }} €', $view->vars['money_pattern']); } public function testMoneyPatternWorksForYen() @@ -29,6 +29,6 @@ public function testMoneyPatternWorksForYen() $form = $this->factory->create('money', null, array('currency' => 'JPY')); $view = $form->createView(); - $this->assertTrue((Boolean) strstr($view->getVar('money_pattern'), '¥')); + $this->assertTrue((Boolean) strstr($view->vars['money_pattern'], '¥')); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php index ab3f56155c50d..a282190520417 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php @@ -26,7 +26,7 @@ public function testDefaultFormatting() $form->setData('12345.67890'); $view = $form->createView(); - $this->assertSame('12345,679', $view->getVar('value')); + $this->assertSame('12345,679', $view->vars['value']); } public function testDefaultFormattingWithGrouping() @@ -35,7 +35,7 @@ public function testDefaultFormattingWithGrouping() $form->setData('12345.67890'); $view = $form->createView(); - $this->assertSame('12.345,679', $view->getVar('value')); + $this->assertSame('12.345,679', $view->vars['value']); } public function testDefaultFormattingWithPrecision() @@ -44,7 +44,7 @@ public function testDefaultFormattingWithPrecision() $form->setData('12345.67890'); $view = $form->createView(); - $this->assertSame('12345,68', $view->getVar('value')); + $this->assertSame('12345,68', $view->vars['value']); } public function testDefaultFormattingWithRounding() @@ -53,6 +53,6 @@ public function testDefaultFormattingWithRounding() $form->setData('12345.54321'); $view = $form->createView(); - $this->assertSame('12346', $view->getVar('value')); + $this->assertSame('12346', $view->vars['value']); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php index 7db1e843d5143..96f141096859a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php @@ -19,7 +19,7 @@ public function testEmptyIfNotBound() $form->setData('pAs5w0rd'); $view = $form->createView(); - $this->assertSame('', $view->getVar('value')); + $this->assertSame('', $view->vars['value']); } public function testEmptyIfBound() @@ -28,7 +28,7 @@ public function testEmptyIfBound() $form->bind('pAs5w0rd'); $view = $form->createView(); - $this->assertSame('', $view->getVar('value')); + $this->assertSame('', $view->vars['value']); } public function testNotEmptyIfBoundAndNotAlwaysEmpty() @@ -37,6 +37,6 @@ public function testNotEmptyIfBoundAndNotAlwaysEmpty() $form->bind('pAs5w0rd'); $view = $form->createView(); - $this->assertSame('pAs5w0rd', $view->getVar('value')); + $this->assertSame('pAs5w0rd', $view->vars['value']); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index 4aed58dbcb8b9..24873d23d9016 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -246,7 +246,7 @@ public function testHoursOption() $this->assertEquals(array( new ChoiceView('6', '06'), new ChoiceView('7', '07'), - ), $view->get('hour')->getVar('choices')); + ), $view['hour']->vars['choices']); } public function testIsMinuteWithinRange_returnsTrueIfWithin() @@ -260,7 +260,7 @@ public function testIsMinuteWithinRange_returnsTrueIfWithin() $this->assertEquals(array( new ChoiceView('6', '06'), new ChoiceView('7', '07'), - ), $view->get('minute')->getVar('choices')); + ), $view['minute']->vars['choices']); } public function testIsSecondWithinRange_returnsTrueIfWithin() @@ -275,7 +275,7 @@ public function testIsSecondWithinRange_returnsTrueIfWithin() $this->assertEquals(array( new ChoiceView('6', '06'), new ChoiceView('7', '07'), - ), $view->get('second')->getVar('choices')); + ), $view['second']->vars['choices']); } public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty() @@ -415,7 +415,7 @@ public function testSingleTextWidgetShouldUseTheRightInputType() )); $view = $form->createView(); - $this->assertEquals('time', $view->getVar('type')); + $this->assertEquals('time', $view->vars['type']); } public function testPassDefaultEmptyValueToViewIfNotRequired() @@ -426,9 +426,9 @@ public function testPassDefaultEmptyValueToViewIfNotRequired() )); $view = $form->createView(); - $this->assertSame('', $view->get('hour')->getVar('empty_value')); - $this->assertSame('', $view->get('minute')->getVar('empty_value')); - $this->assertSame('', $view->get('second')->getVar('empty_value')); + $this->assertSame('', $view['hour']->vars['empty_value']); + $this->assertSame('', $view['minute']->vars['empty_value']); + $this->assertSame('', $view['second']->vars['empty_value']); } public function testPassNoEmptyValueToViewIfRequired() @@ -439,9 +439,9 @@ public function testPassNoEmptyValueToViewIfRequired() )); $view = $form->createView(); - $this->assertNull($view->get('hour')->getVar('empty_value')); - $this->assertNull($view->get('minute')->getVar('empty_value')); - $this->assertNull($view->get('second')->getVar('empty_value')); + $this->assertNull($view['hour']->vars['empty_value']); + $this->assertNull($view['minute']->vars['empty_value']); + $this->assertNull($view['second']->vars['empty_value']); } public function testPassEmptyValueAsString() @@ -452,9 +452,9 @@ public function testPassEmptyValueAsString() )); $view = $form->createView(); - $this->assertSame('Empty', $view->get('hour')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('minute')->getVar('empty_value')); - $this->assertSame('Empty', $view->get('second')->getVar('empty_value')); + $this->assertSame('Empty', $view['hour']->vars['empty_value']); + $this->assertSame('Empty', $view['minute']->vars['empty_value']); + $this->assertSame('Empty', $view['second']->vars['empty_value']); } public function testPassEmptyValueAsArray() @@ -469,9 +469,9 @@ public function testPassEmptyValueAsArray() )); $view = $form->createView(); - $this->assertSame('Empty hour', $view->get('hour')->getVar('empty_value')); - $this->assertSame('Empty minute', $view->get('minute')->getVar('empty_value')); - $this->assertSame('Empty second', $view->get('second')->getVar('empty_value')); + $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); + $this->assertSame('Empty minute', $view['minute']->vars['empty_value']); + $this->assertSame('Empty second', $view['second']->vars['empty_value']); } public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() @@ -486,9 +486,9 @@ public function testPassEmptyValueAsPartialArray_addEmptyIfNotRequired() )); $view = $form->createView(); - $this->assertSame('Empty hour', $view->get('hour')->getVar('empty_value')); - $this->assertSame('', $view->get('minute')->getVar('empty_value')); - $this->assertSame('Empty second', $view->get('second')->getVar('empty_value')); + $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); + $this->assertSame('', $view['minute']->vars['empty_value']); + $this->assertSame('Empty second', $view['second']->vars['empty_value']); } public function testPassEmptyValueAsPartialArray_addNullIfRequired() @@ -503,9 +503,9 @@ public function testPassEmptyValueAsPartialArray_addNullIfRequired() )); $view = $form->createView(); - $this->assertSame('Empty hour', $view->get('hour')->getVar('empty_value')); - $this->assertNull($view->get('minute')->getVar('empty_value')); - $this->assertSame('Empty second', $view->get('second')->getVar('empty_value')); + $this->assertSame('Empty hour', $view['hour']->vars['empty_value']); + $this->assertNull($view['minute']->vars['empty_value']); + $this->assertSame('Empty second', $view['second']->vars['empty_value']); } public function provideCompoundWidgets() @@ -525,9 +525,9 @@ public function testHourErrorsBubbleUp($widget) $form = $this->factory->create('time', null, array( '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()); } @@ -540,9 +540,9 @@ public function testMinuteErrorsBubbleUp($widget) $form = $this->factory->create('time', null, array( '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()); } @@ -556,9 +556,9 @@ public function testSecondErrorsBubbleUp($widget) 'widget' => $widget, '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()); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php index 2550303e65627..113b8d7ed1025 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php @@ -19,7 +19,7 @@ public function testTimezonesAreSelectable() { $form = $this->factory->create('timezone'); $view = $form->createView(); - $choices = $view->getVar('choices'); + $choices = $view->vars['choices']; $this->assertArrayHasKey('Africa', $choices); $this->assertContains(new ChoiceView('Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false); diff --git a/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php index 7f6408c689b3f..47dd52927047e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php @@ -65,7 +65,7 @@ public function testCsrfProtectionByDefaultIfRootAndCompound() )) ->createView(); - $this->assertTrue($view->has('csrf')); + $this->assertTrue(isset($view['csrf'])); } public function testNoCsrfProtectionByDefaultIfCompoundButNotRoot() @@ -79,10 +79,10 @@ public function testNoCsrfProtectionByDefaultIfCompoundButNotRoot() )) ) ->getForm() - ->createView() - ->get('form'); + ->get('form') + ->createView(); - $this->assertFalse($view->has('csrf')); + $this->assertFalse(isset($view['csrf'])); } public function testNoCsrfProtectionByDefaultIfRootButNotCompound() @@ -94,7 +94,7 @@ public function testNoCsrfProtectionByDefaultIfRootButNotCompound() )) ->createView(); - $this->assertFalse($view->has('csrf')); + $this->assertFalse(isset($view['csrf'])); } public function testCsrfProtectionCanBeDisabled() @@ -107,7 +107,7 @@ public function testCsrfProtectionCanBeDisabled() )) ->createView(); - $this->assertFalse($view->has('csrf')); + $this->assertFalse(isset($view['csrf'])); } public function testGenerateCsrfToken() @@ -126,7 +126,7 @@ public function testGenerateCsrfToken() )) ->createView(); - $this->assertEquals('token', $view->get('csrf')->getVar('value')); + $this->assertEquals('token', $view['csrf']->vars['value']); } public function provideBoolean() @@ -250,9 +250,9 @@ public function testNoCsrfProtectionOnPrototype() 'allow_add' => true, )) ->createView() - ->getVar('prototype'); + ->vars['prototype']; - $this->assertFalse($prototypeView->has('csrf')); + $this->assertFalse(isset($prototypeView['csrf'])); $this->assertCount(1, $prototypeView); } } diff --git a/src/Symfony/Component/Form/Tests/FormRendererTest.php b/src/Symfony/Component/Form/Tests/FormRendererTest.php index bf212c90495fa..2ba2f33730425 100644 --- a/src/Symfony/Component/Form/Tests/FormRendererTest.php +++ b/src/Symfony/Component/Form/Tests/FormRendererTest.php @@ -96,8 +96,8 @@ public function isChoiceSelectedProvider() */ public function testIsChoiceSelected($expected, $choice, $value) { - $view = new FormView('name'); - $view->setVar('value', $value); + $view = new FormView(); + $view->vars['value'] = $value; $choice = new ChoiceView($choice, $choice . ' label'); $this->assertSame($expected, $this->renderer->isChoiceSelected($view, $choice)); diff --git a/src/Symfony/Component/Form/Tests/FormViewInterface.php b/src/Symfony/Component/Form/Tests/FormViewInterface.php deleted file mode 100644 index 431dd3a05c6fb..0000000000000 --- a/src/Symfony/Component/Form/Tests/FormViewInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * 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 -{ -} diff --git a/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php b/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php index e89e650bad02f..2aded4fb2a7bc 100644 --- a/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php @@ -13,7 +13,6 @@ use Symfony\Component\Form\ResolvedFormType; use Symfony\Component\Form\FormView; -use Symfony\Component\Form\FormViewInterface; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormConfig; use Symfony\Component\Form\Form; @@ -171,7 +170,7 @@ public function testCreateView() $i = 0; $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 */ $test->assertEquals($index, $i, 'Executed at index ' . $index); $test->assertCount($nbOfChildViews, $view); @@ -242,10 +241,10 @@ public function testCreateView() ->with($this->anything(), $form, $options) ->will($this->returnCallback($assertIndexAndNbOfChildViews(11, 2))); - $parentView = new FormView('parent'); + $parentView = new FormView(); $view = $resolvedType->createView($form, $parentView); - $this->assertSame($parentView, $view->getParent()); + $this->assertSame($parentView, $view->parent); } /** diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index dcc2438a18bd3..cc835bb3c853c 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -580,7 +580,7 @@ public function testBindResetsErrors() public function testCreateView() { $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(); $type->expects($this->once()) @@ -594,9 +594,9 @@ public function testCreateView() public function testCreateViewWithParent() { $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'); - $parentView = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); + $parentView = $this->getMock('Symfony\Component\Form\FormView'); $form = $this->getBuilder()->setType($type)->getForm(); $form->setParent($parentForm); @@ -615,8 +615,8 @@ public function testCreateViewWithParent() public function testCreateViewWithExplicitParent() { $type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface'); - $view = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); - $parentView = $this->getMock('Symfony\Component\Form\Tests\FormViewInterface'); + $view = $this->getMock('Symfony\Component\Form\FormView'); + $parentView = $this->getMock('Symfony\Component\Form\FormView'); $form = $this->getBuilder()->setType($type)->getForm(); $type->expects($this->once()) From 400c95bb4d88182eb98a311187b3f02fc081ec04 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 17:38:50 +0200 Subject: [PATCH 2/9] [Form] Replace methods in ChoiceView by public properties (PHP +100ms, Twig +400ms) --- .../views/Form/choice_widget_options.html.php | 4 ++-- .../Form/Extension/Core/Type/ChoiceType.php | 4 ++-- .../Form/Extension/Core/View/ChoiceView.php | 24 ++----------------- src/Symfony/Component/Form/FormRenderer.php | 2 +- .../Extension/Core/Type/CountryTypeTest.php | 2 +- 5 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index 66c664fb1d620..d099b41f0a554 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -2,10 +2,10 @@ isChoiceGroup($choice)): ?> - + - + diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 3eedb5f6ef5de..e906f46aa8e08 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -226,8 +226,8 @@ private function addSubForms(FormBuilderInterface $builder, array $choiceViews, $this->addSubForms($builder, $choiceView, $options); } else { $choiceOpts = array( - 'value' => $choiceView->getValue(), - 'label' => $choiceView->getLabel(), + 'value' => $choiceView->value, + 'label' => $choiceView->label, 'translation_domain' => $options['translation_domain'], ); diff --git a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php index 7e37c7dcc75a7..158a1a9ce017d 100644 --- a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php +++ b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php @@ -23,14 +23,14 @@ class ChoiceView * * @var string */ - private $value; + public $value; /** * The label displayed to humans. * * @var string */ - private $label; + public $label; /** * Creates a new ChoiceView. @@ -43,24 +43,4 @@ public function __construct($value, $label) $this->value = $value; $this->label = $label; } - - /** - * Returns the choice value. - * - * @return string The view representation of the choice. - */ - public function getValue() - { - return $this->value; - } - - /** - * Returns the choice label. - * - * @return string The label displayed to humans. - */ - public function getLabel() - { - return $this->label; - } } diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index 08aa5a5ec9e49..5f1c98629d656 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -186,7 +186,7 @@ public function isChoiceGroup($choice) public function isChoiceSelected(FormView $view, ChoiceView $choice) { $value = $view->vars['value']; - $choiceValue = $choice->getValue(); + $choiceValue = $choice->value; if (is_array($value)) { return false !== array_search($choiceValue, $value, true); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php index 298d9118f74a9..b607c3f65cfe8 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php @@ -38,7 +38,7 @@ public function testUnknownCountryIsNotIncluded() $choices = $view->vars['choices']; foreach ($choices as $choice) { - if ('ZZ' === $choice->getValue()) { + if ('ZZ' === $choice->value) { $this->fail('Should not contain choice "ZZ"'); } } From 8b727664733027fa31ddd49dcf2c0fd4db098dae Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 16:56:02 +0200 Subject: [PATCH 3/9] [Form] Tweaked the generation of option tags for performance (PHP +200ms, Twig +50ms) --- .../Bridge/Twig/Extension/FormExtension.php | 6 +-- .../views/Form/form_div_layout.html.twig | 13 +++--- .../Form/choice_widget_collapsed.html.php | 4 +- .../views/Form/choice_widget_options.html.php | 10 ++--- .../Templating/Helper/FormHelper.php | 11 ++--- .../Extension/Core/ChoiceList/ChoiceList.php | 44 +++++++++---------- .../Core/ChoiceList/SimpleChoiceList.php | 6 ++- src/Symfony/Component/Form/FormRenderer.php | 17 ++----- .../Component/Form/FormRendererInterface.php | 15 ++----- .../Component/Form/Tests/FormRendererTest.php | 32 +------------- 10 files changed, 50 insertions(+), 108 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index f7206bd5f80cc..f67c3e17538e4 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -69,8 +69,6 @@ public function getFunctions() 'form_row' => new \Twig_Function_Method($this, 'renderer->renderRow', array('is_safe' => array('html'))), 'form_rest' => new \Twig_Function_Method($this, 'renderer->renderRest', array('is_safe' => array('html'))), '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'))), ); } @@ -80,7 +78,9 @@ public function getFunctions() public function getFilters() { return array( - 'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'), + 'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'), + 'is_choice_group' => new \Twig_Filter_Function('is_array', array('is_safe' => array('html'))), + 'is_choice_selected' => new \Twig_Filter_Method($this, 'renderer->isChoiceSelected', array('is_safe' => array('html'))), ); } diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 13ead741260c9..a088ae5337187 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -86,15 +86,14 @@ {% block choice_widget_options %} {% spaceless %} - {% for index, choice in options %} - {% if _form_is_choice_group(choice) %} - - {% for nested_choice in choice %} - - {% endfor %} + {% for group_label, choice in options %} + {% if choice|is_choice_group %} + + {% set options = choice %} + {{ block('choice_widget_options') }} {% else %} - + {% endif %} {% endfor %} {% endspaceless %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_collapsed.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_collapsed.html.php index dd3655b733aba..0bc61c4525dab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_collapsed.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_collapsed.html.php @@ -4,10 +4,10 @@ > 0): ?> - block('choice_widget_options', array('options' => $preferred_choices)) ?> + block('choice_widget_options', array('choices' => $preferred_choices)) ?> 0 && null !== $separator): ?> - block('choice_widget_options', array('options' => $choices)) ?> + block('choice_widget_options', array('choices' => $choices)) ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index d099b41f0a554..ebcff3973a5f9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -1,11 +1,9 @@ - $choice): ?> - isChoiceGroup($choice)): ?> + $choice): ?> + - - - + block('choice_widget_options', array('choices' => $choice)) ?> - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index 15eed3b9153f0..35dbe93ba51ed 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -49,14 +49,9 @@ public function getName() return 'form'; } - public function isChoiceGroup($label) + public function isChoiceSelected(ChoiceView $choice, $selectedValue) { - return $this->renderer->isChoiceGroup($label); - } - - public function isChoiceSelected(FormView $view, ChoiceView $choice) - { - return $this->renderer->isChoiceSelected($view, $choice); + return $this->renderer->isChoiceSelected($choice, $selectedValue); } /** @@ -176,7 +171,7 @@ public function rest(FormView $view, array $variables = array()) */ public function renderBlock($block, array $variables = array()) { - return $this->block($block, $variables); + return $this->renderer->renderBlock($block, $variables); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index 80abc7342955b..4059757b854a7 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -240,27 +240,19 @@ public function getIndicesForValues(array $values) * view objects. * @param array $bucketForRemaining The bucket where to store the * non-preferred view objects. - * @param array $choices The list of choices. - * @param array $labels The labels corresponding to the choices. - * @param array $preferredChoices The preferred choices. + * @param array $choices The list of choices. + * @param array $labels The labels corresponding to the choices. + * @param array $preferredChoices The preferred choices. * * @throws UnexpectedTypeException If the structure of the $labels array * does not match the structure of the * $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 foreach ($choices as $group => $choice) { if (is_array($choice)) { - if (!is_array($labels)) { - throw new UnexpectedTypeException($labels, 'array'); - } - // Don't do the work if the array is empty if (count($choice) > 0) { $this->addChoiceGroup( @@ -292,11 +284,11 @@ protected function addChoices(&$bucketForPreferred, &$bucketForRemaining, $choic * view objects. * @param array $bucketForRemaining The bucket where to store the * non-preferred view objects. - * @param array $choices The list of choices in the group. - * @param array $labels The labels corresponding to the choices in the group. - * @param array $preferredChoices The preferred choices. + * @param array $choices The list of choices in the group. + * @param array $labels The labels corresponding to the choices in the group. + * @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 // key hierarchy @@ -323,13 +315,15 @@ protected function addChoiceGroup($group, &$bucketForPreferred, &$bucketForRemai /** * Adds a new choice. * - * @param array $bucketForPreferred The bucket where to store the preferred - * view objects. - * @param array $bucketForRemaining The bucket where to store the - * non-preferred view objects. - * @param mixed $choice The choice to add. - * @param string $label The label for the choice. - * @param array $preferredChoices The preferred choices. + * @param array $bucketForPreferred The bucket where to store the preferred + * view objects. + * @param array $bucketForRemaining The bucket where to store the + * non-preferred view objects. + * @param mixed $choice The choice to add. + * @param string $label The label for the choice. + * @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) { @@ -366,8 +360,10 @@ protected function addChoice(&$bucketForPreferred, &$bucketForRemaining, $choice * * @param mixed $choice The choice to test. * @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); } diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php index f1af179b6b4dc..3e76900a7881d 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/SimpleChoiceList.php @@ -89,7 +89,7 @@ public function getValuesForChoices(array $choices) * * @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 foreach ($choices as $choice => $label) { @@ -126,8 +126,10 @@ protected function addChoices(&$bucketForPreferred, &$bucketForRemaining, $choic * * @param mixed $choice The choice to test. * @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 return isset($preferredChoices[$choice]); diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index 5f1c98629d656..c4ecb7f4b52b8 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -175,24 +175,15 @@ public function renderBlock($block, array $variables = array()) /** * {@inheritdoc} */ - public function isChoiceGroup($choice) + public function isChoiceSelected(ChoiceView $choice, $selectedValue) { - return is_array($choice) || $choice instanceof \Traversable; - } - - /** - * {@inheritdoc} - */ - public function isChoiceSelected(FormView $view, ChoiceView $choice) - { - $value = $view->vars['value']; $choiceValue = $choice->value; - if (is_array($value)) { - return false !== array_search($choiceValue, $value, true); + if (is_array($selectedValue)) { + return false !== array_search($choiceValue, $selectedValue, true); } - return $choiceValue === $value; + return $choiceValue === $selectedValue; } /** diff --git a/src/Symfony/Component/Form/FormRendererInterface.php b/src/Symfony/Component/Form/FormRendererInterface.php index 8ef742561649e..748ba86b3e281 100644 --- a/src/Symfony/Component/Form/FormRendererInterface.php +++ b/src/Symfony/Component/Form/FormRendererInterface.php @@ -146,24 +146,15 @@ public function renderBlock($block, array $variables = array()); */ 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 FormView $view The view of the choice field - * @param ChoiceView $choice The choice to check + * @param ChoiceView $choice The choice to check. + * @param string|array $selectedValue The selected value(s). * * @return Boolean Whether the choice is selected */ - public function isChoiceSelected(FormView $view, ChoiceView $choice); + public function isChoiceSelected(ChoiceView $choice, $selectedValue); /** * Makes a technical name human readable. diff --git a/src/Symfony/Component/Form/Tests/FormRendererTest.php b/src/Symfony/Component/Form/Tests/FormRendererTest.php index 2ba2f33730425..fa36e75a59d1a 100644 --- a/src/Symfony/Component/Form/Tests/FormRendererTest.php +++ b/src/Symfony/Component/Form/Tests/FormRendererTest.php @@ -40,34 +40,6 @@ protected function setUp() $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 @@ -96,10 +68,8 @@ public function isChoiceSelectedProvider() */ public function testIsChoiceSelected($expected, $choice, $value) { - $view = new FormView(); - $view->vars['value'] = $value; $choice = new ChoiceView($choice, $choice . ' label'); - $this->assertSame($expected, $this->renderer->isChoiceSelected($view, $choice)); + $this->assertSame($expected, $this->renderer->isChoiceSelected($choice, $value)); } } From 0ef9acb479c66d23dd091e0285ce8330a40865c1 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 17:55:22 +0200 Subject: [PATCH 4/9] [Form] Moved the method isChoiceSelected() to the ChoiceView class (PHP +150ms) --- .../Bridge/Twig/Extension/FormExtension.php | 25 ++++++++++++++++++- .../views/Form/choice_widget_options.html.php | 2 +- .../Form/Extension/Core/View/ChoiceView.php | 16 ++++++++++++ src/Symfony/Component/Form/FormRenderer.php | 14 ----------- .../Component/Form/FormRendererInterface.php | 10 -------- 5 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index f67c3e17538e4..97605fdc626a4 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -14,6 +14,7 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\Form\TwigRendererInterface; use Symfony\Component\Form\FormView; +use Symfony\Component\Form\Extension\Core\View\ChoiceView; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; /** @@ -80,10 +81,32 @@ public function getFilters() return array( 'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'), 'is_choice_group' => new \Twig_Filter_Function('is_array', array('is_safe' => array('html'))), - 'is_choice_selected' => new \Twig_Filter_Method($this, 'renderer->isChoiceSelected', array('is_safe' => array('html'))), + 'is_choice_selected' => new \Twig_Filter_Method($this, 'isChoiceSelected'), ); } + /** + * Returns whether a choice is selected for a given form value. + * + * This method exists for the sole purpose that Twig performs (a lot) better + * with filters than with methods of an object. + * + * To give this some perspective, I'm currently testing this on a form with + * a large list of entity fields. Using the filter is around 220ms faster than + * accessing the method directly on the object in the Twig template. + * + * @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 isChoiceSelected(ChoiceView $choice, $selectedValue) + { + return $choice->isSelected($selectedValue); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index ebcff3973a5f9..b43ab00e194b1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -4,6 +4,6 @@ block('choice_widget_options', array('choices' => $choice)) ?> - + diff --git a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php index 158a1a9ce017d..0f7d176e38d09 100644 --- a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php +++ b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php @@ -43,4 +43,20 @@ public function __construct($value, $label) $this->value = $value; $this->label = $label; } + + /** + * Returns whether this choice is selected for the given value. + * + * @param string|array $value The selected choice value. + * + * @return Boolean Whether the choice is selected. + */ + public function isSelected($value) + { + if (is_array($value)) { + return false !== array_search($this->value, $value, true); + } + + return $this->value === $value; + } } diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index c4ecb7f4b52b8..49d7877c90fff 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -172,20 +172,6 @@ public function renderBlock($block, array $variables = array()) return $this->engine->renderBlock($view, $resource, $block, $variables); } - /** - * {@inheritdoc} - */ - public function isChoiceSelected(ChoiceView $choice, $selectedValue) - { - $choiceValue = $choice->value; - - if (is_array($selectedValue)) { - return false !== array_search($choiceValue, $selectedValue, true); - } - - return $choiceValue === $selectedValue; - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/FormRendererInterface.php b/src/Symfony/Component/Form/FormRendererInterface.php index 748ba86b3e281..56936a6dd25f6 100644 --- a/src/Symfony/Component/Form/FormRendererInterface.php +++ b/src/Symfony/Component/Form/FormRendererInterface.php @@ -146,16 +146,6 @@ public function renderBlock($block, array $variables = array()); */ public function renderCsrfToken($intention); - /** - * Returns whether the given choice is selected. - * - * @param ChoiceView $choice The choice to check. - * @param string|array $selectedValue The selected value(s). - * - * @return Boolean Whether the choice is selected - */ - public function isChoiceSelected(ChoiceView $choice, $selectedValue); - /** * Makes a technical name human readable. * From 5dc3c39fd2d84b788eb4fff54a668f230ef38cce Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 18:03:21 +0200 Subject: [PATCH 5/9] [Form] Moved the access to templating helpers out of the choice loop for performance reasons (PHP +100ms) --- .../Resources/views/Form/choice_widget_options.html.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index b43ab00e194b1..9d79a4b725dfd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -1,9 +1,11 @@ + + $choice): ?> - - block('choice_widget_options', array('choices' => $choice)) ?> + + block('choice_widget_options', array('choices' => $choice)) ?> - + From 5984b18a7a307df6251348b18e11e5ca1c1adfd5 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 16 Jul 2012 19:11:36 +0200 Subject: [PATCH 6/9] [Form] Precalculated the closure for deciding whether a choice is selected (PHP +30ms, Twig +30ms) --- .../Bridge/Twig/Extension/FormExtension.php | 22 ++++-- .../Extension/FormExtensionDivLayoutTest.php | 34 +++++++++ .../views/Form/choice_widget_options.html.php | 2 +- .../Form/Extension/Core/Type/ChoiceType.php | 14 ++++ .../Component/Form/Tests/FormRendererTest.php | 75 ------------------- 5 files changed, 65 insertions(+), 82 deletions(-) delete mode 100644 src/Symfony/Component/Form/Tests/FormRendererTest.php diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 97605fdc626a4..1c2fa540d301d 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -88,12 +88,18 @@ public function getFilters() /** * Returns whether a choice is selected for a given form value. * - * This method exists for the sole purpose that Twig performs (a lot) better - * with filters than with methods of an object. + * 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). * - * To give this some perspective, I'm currently testing this on a form with - * a large list of entity fields. Using the filter is around 220ms faster than - * accessing the method directly on the object in the Twig template. + * 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. @@ -104,7 +110,11 @@ public function getFilters() */ public function isChoiceSelected(ChoiceView $choice, $selectedValue) { - return $choice->isSelected($selectedValue); + if (is_array($selectedValue)) { + return false !== array_search($choice->value, $selectedValue, true); + } + + return $choice->value === $selectedValue; } /** diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index f057a515cc6dc..90affd11b38c5 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -18,6 +18,7 @@ use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubTranslator; use Symfony\Bridge\Twig\Tests\Extension\Fixtures\StubFilesystemLoader; use Symfony\Component\Form\FormView; +use Symfony\Component\Form\Extension\Core\View\ChoiceView; use Symfony\Component\Form\Tests\AbstractDivLayoutTest; class FormExtensionDivLayoutTest extends AbstractDivLayoutTest @@ -105,6 +106,39 @@ public function testThemeBlockInheritanceUsingExtend() ); } + 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) + { + $choice = new ChoiceView($choice, $choice . ' label'); + + $this->assertSame($expected, $this->extension->isChoiceSelected($choice, $value)); + } + protected function renderEnctype(FormView $view) { return (string) $this->extension->renderer->renderEnctype($view); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php index 9d79a4b725dfd..39c97f091fc6f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_options.html.php @@ -6,6 +6,6 @@ block('choice_widget_options', array('choices' => $choice)) ?> - + diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index e906f46aa8e08..b031c45a5e7dd 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -90,6 +90,20 @@ public function buildView(FormView $view, FormInterface $form, array $options) '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 // Only add the empty value option if this is not the case if (0 === count($options['choice_list']->getIndicesForValues(array('')))) { diff --git a/src/Symfony/Component/Form/Tests/FormRendererTest.php b/src/Symfony/Component/Form/Tests/FormRendererTest.php deleted file mode 100644 index fa36e75a59d1a..0000000000000 --- a/src/Symfony/Component/Form/Tests/FormRendererTest.php +++ /dev/null @@ -1,75 +0,0 @@ - - * - * 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 - */ -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 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) - { - $choice = new ChoiceView($choice, $choice . ' label'); - - $this->assertSame($expected, $this->renderer->isChoiceSelected($choice, $value)); - } -} From 310f985b9903f62460e92f4e5d17751c7503758b Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 21 Jul 2012 13:49:32 +0200 Subject: [PATCH 7/9] [Form] Added a layer of 2.0 BC methods to FormView and updated UPGRADE and CHANGELOG --- UPGRADE-2.1.md | 107 ++++++++++++++---------- src/Symfony/Component/Form/CHANGELOG.md | 3 +- src/Symfony/Component/Form/FormView.php | 103 +++++++++++++++++++++++ 3 files changed, 167 insertions(+), 46 deletions(-) diff --git a/UPGRADE-2.1.md b/UPGRADE-2.1.md index c8f52b8920da6..8804281f8b44a 100644 --- a/UPGRADE-2.1.md +++ b/UPGRADE-2.1.md @@ -224,30 +224,23 @@ `buildViewBottomUp()` in `FormTypeInterface` and `FormTypeExtensionInterface`. Furthermore, `buildViewBottomUp()` was renamed to `finishView()`. At last, all methods in these types now receive instances of `FormBuilderInterface` - and `FormViewInterface` where they received instances of `FormBuilder` and - `FormView` before. You need to change the method signatures in your - form types and extensions as shown below. + where they received instances of `FormBuilder` before. You need to change the + method signatures in your form types and extensions as shown below. Before: ``` use Symfony\Component\Form\FormBuilder; - use Symfony\Component\Form\FormView; public function buildForm(FormBuilder $builder, array $options) - public function buildView(FormView $view, FormInterface $form) - public function buildViewBottomUp(FormView $view, FormInterface $form) ``` After: ``` use Symfony\Component\Form\FormBuilderInterface; - use Symfony\Component\Form\FormViewInterface; 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 @@ -383,41 +376,6 @@ If address is an object in this case, the code given in "Before" 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 and only contain letters, digits, underscores, hyphens and colons. @@ -1069,6 +1027,67 @@ block('widget_attributes') ?> ``` + * The following methods in class `FormView` were deprecated and will be + 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: + + ``` + $view->set('help', 'A text longer than six characters'); + $view->set('error_class', 'max_length_error'); + ``` + + After: + + ``` + $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 * The methods `setMessage()`, `getMessageTemplate()` and diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index e155a897f4d7e..e7af213aeafe3 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -134,8 +134,6 @@ CHANGELOG FormEvents::BIND_NORM_DATA * [BC BREAK] reversed the order of the first two arguments to `createNamed` 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 @@ -179,3 +177,4 @@ CHANGELOG * `isChoiceGroup` * `isChoiceSelected` * added method `block` to FormHelper and deprecated `renderBlock` instead + * made FormView properties public and deprecated their accessor methods diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index b0a73775b2252..84eb19843c5d8 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -67,6 +67,64 @@ public function getName() return $this->vars['name']; } + /** + * @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 set($name, $value) + { + $this->vars[$name] = $value; + + return $this; + } + + /** + * @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 has($name) + { + return array_key_exists($name, $this->vars); + } + + /** + * @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 get($name, $default = null) + { + if (false === $this->has($name)) { + return $default; + } + + return $this->vars[$name]; + } + + /** + * @return array + * + * @deprecated Deprecated since version 2.1, to be removed in 2.3. Access + * the public property {@link vars} instead. + */ + public function all() + { + return $this->vars; + } + /** * Returns the values of all view variables. * @@ -180,6 +238,51 @@ public function hasParent() return null !== $this->parent; } + /** + * 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 setChildren(array $children) + { + $this->children = $children; + + return $this; + } + + /** + * 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 getChildren() + { + return $this->children; + } + + /** + * 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 getChild($name) + { + return $this->children[$name]; + } + /** * Returns whether this view has any children. * From 921681658c5555d0e09e6b6d5eb01516b0c133b5 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 21 Jul 2012 14:26:59 +0200 Subject: [PATCH 8/9] [Form] Turned Twig filters into tests --- .../Bridge/Twig/Extension/FormExtension.php | 14 +++++++++++--- .../Resources/views/Form/form_div_layout.html.twig | 4 ++-- .../Tests/Extension/FormExtensionDivLayoutTest.php | 6 +++--- .../Templating/Helper/FormHelper.php | 5 ----- src/Symfony/Component/Form/CHANGELOG.md | 7 +++---- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 1c2fa540d301d..8122f6cbeea62 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -80,8 +80,16 @@ public function getFilters() { return array( 'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'), - 'is_choice_group' => new \Twig_Filter_Function('is_array', array('is_safe' => array('html'))), - 'is_choice_selected' => new \Twig_Filter_Method($this, 'isChoiceSelected'), + ); + } + + /** + * {@inheritdoc} + */ + public function getTests() + { + return array( + 'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'), ); } @@ -108,7 +116,7 @@ public function getFilters() * * @see ChoiceView::isSelected() */ - public function isChoiceSelected(ChoiceView $choice, $selectedValue) + public function isSelectedChoice(ChoiceView $choice, $selectedValue) { if (is_array($selectedValue)) { return false !== array_search($choice->value, $selectedValue, true); diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index a088ae5337187..3c10d53d37014 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -87,13 +87,13 @@ {% block choice_widget_options %} {% spaceless %} {% for group_label, choice in options %} - {% if choice|is_choice_group %} + {% if choice is iterable %} {% set options = choice %} {{ block('choice_widget_options') }} {% else %} - + {% endif %} {% endfor %} {% endspaceless %} diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 90affd11b38c5..65f613abe8d54 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -106,7 +106,7 @@ public function testThemeBlockInheritanceUsingExtend() ); } - public function isChoiceSelectedProvider() + public function isSelectedChoiceProvider() { // The commented cases should not be necessary anymore, because the // choice lists should assure that both values passed here are always @@ -130,13 +130,13 @@ public function isChoiceSelectedProvider() } /** - * @dataProvider isChoiceSelectedProvider + * @dataProvider isSelectedChoiceProvider */ public function testIsChoiceSelected($expected, $choice, $value) { $choice = new ChoiceView($choice, $choice . ' label'); - $this->assertSame($expected, $this->extension->isChoiceSelected($choice, $value)); + $this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value)); } protected function renderEnctype(FormView $view) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index 35dbe93ba51ed..c7297fc3652dd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -49,11 +49,6 @@ public function getName() return 'form'; } - public function isChoiceSelected(ChoiceView $choice, $selectedValue) - { - return $this->renderer->isChoiceSelected($choice, $selectedValue); - } - /** * Sets a theme for a given view. * diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index e7af213aeafe3..2229f587f1bce 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -113,10 +113,9 @@ CHANGELOG * deprecated the methods `getDefaultOptions` and `getAllowedOptionValues` in FormTypeInterface and FormTypeExtensionInterface * options passed during construction can now be accessed from FormConfigInterface - * added FormBuilderInterface, FormView and FormConfigEditorInterface - * [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now - receive FormBuilderInterface and FormView instead of FormBuilder and - FormView + * added FormBuilderInterface and FormConfigEditorInterface + * [BC BREAK] the method `buildForm` in FormTypeInterface and FormTypeExtensionInterface + now receives a FormBuilderInterface instead of a FormBuilder instance * [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in FormTypeInterface and FormTypeExtensionInterface * [BC BREAK] the options array is now passed as last argument of the From 24b764e06687d7c172df55943fba1ea9e9f277e4 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 21 Jul 2012 19:45:31 +0200 Subject: [PATCH 9/9] [Form] Fixed issues mentioned in the PR --- .../Bridge/Twig/Extension/FormExtension.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 8122f6cbeea62..0a5f356350aa9 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -13,7 +13,6 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser; use Symfony\Bridge\Twig\Form\TwigRendererInterface; -use Symfony\Component\Form\FormView; use Symfony\Component\Form\Extension\Core\View\ChoiceView; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; @@ -63,13 +62,13 @@ public function getTokenParsers() public function getFunctions() { return array( - 'form_enctype' => new \Twig_Function_Method($this, 'renderer->renderEnctype', array('is_safe' => array('html'))), - 'form_widget' => new \Twig_Function_Method($this, 'renderer->renderWidget', array('is_safe' => array('html'))), - 'form_errors' => new \Twig_Function_Method($this, 'renderer->renderErrors', array('is_safe' => array('html'))), - 'form_label' => new \Twig_Function_Method($this, 'renderer->renderLabel', array('is_safe' => array('html'))), - 'form_row' => new \Twig_Function_Method($this, 'renderer->renderRow', array('is_safe' => array('html'))), - 'form_rest' => new \Twig_Function_Method($this, 'renderer->renderRest', array('is_safe' => array('html'))), - 'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'), + 'form_enctype' => new \Twig_Function_Method($this, 'renderer->renderEnctype', array('is_safe' => array('html'))), + 'form_widget' => new \Twig_Function_Method($this, 'renderer->renderWidget', array('is_safe' => array('html'))), + 'form_errors' => new \Twig_Function_Method($this, 'renderer->renderErrors', array('is_safe' => array('html'))), + 'form_label' => new \Twig_Function_Method($this, 'renderer->renderLabel', array('is_safe' => array('html'))), + 'form_row' => new \Twig_Function_Method($this, 'renderer->renderRow', array('is_safe' => array('html'))), + 'form_rest' => new \Twig_Function_Method($this, 'renderer->renderRest', array('is_safe' => array('html'))), + 'csrf_token' => new \Twig_Function_Method($this, 'renderer->renderCsrfToken'), ); } @@ -79,7 +78,7 @@ public function getFunctions() public function getFilters() { return array( - 'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'), + 'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'), ); }