Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Form] The properties of FormView are now accessed directly in order …

…to increase performance (PHP +200ms, Twig +150ms)
  • Loading branch information...
commit d072f35ea0166004b6407d510ec9f484f8eef78a 1 parent 9f157a1
@webmozart webmozart authored
Showing with 438 additions and 650 deletions.
  1. +5 −5 src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
  2. +1 −1  src/Symfony/Bridge/Twig/Extension/FormExtension.php
  3. +9 −9 src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php
  4. +1 −1  src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_enctype.html.php
  5. +1 −1  src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php
  6. +1 −1  src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_widget_compound.html.php
  7. +16 −16 src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
  8. +13 −13 src/Symfony/Component/Form/AbstractRendererEngine.php
  9. +2 −2 src/Symfony/Component/Form/AbstractType.php
  10. +2 −2 src/Symfony/Component/Form/AbstractTypeExtension.php
  11. +2 −2 src/Symfony/Component/Form/CHANGELOG.md
  12. +3 −3 src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php
  13. +8 −8 src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
  14. +7 −7 src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php
  15. +4 −4 src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
  16. +5 −5 src/Symfony/Component/Form/Extension/Core/Type/DateType.php
  17. +5 −5 src/Symfony/Component/Form/Extension/Core/Type/FileType.php
  18. +13 −15 src/Symfony/Component/Form/Extension/Core/Type/FormType.php
  19. +3 −3 src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php
  20. +3 −3 src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php
  21. +3 −3 src/Symfony/Component/Form/Extension/Core/Type/TextareaType.php
  22. +4 −4 src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
  23. +4 −4 src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php
  24. +8 −8 src/Symfony/Component/Form/Extension/Templating/TemplatingRendererEngine.php
  25. +1 −1  src/Symfony/Component/Form/Form.php
  26. +3 −3 src/Symfony/Component/Form/FormInterface.php
  27. +14 −14 src/Symfony/Component/Form/FormRenderer.php
  28. +10 −10 src/Symfony/Component/Form/FormRendererEngineInterface.php
  29. +16 −16 src/Symfony/Component/Form/FormRendererInterface.php
  30. +4 −4 src/Symfony/Component/Form/FormTypeExtensionInterface.php
  31. +4 −4 src/Symfony/Component/Form/FormTypeInterface.php
  32. +64 −106 src/Symfony/Component/Form/FormView.php
  33. +0 −150 src/Symfony/Component/Form/FormViewInterface.php
  34. +6 −7 src/Symfony/Component/Form/ResolvedFormType.php
  35. +3 −3 src/Symfony/Component/Form/ResolvedFormTypeInterface.php
  36. +5 −5 src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php
  37. +14 −14 src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php
  38. +2 −2 src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php
  39. +2 −2 src/Symfony/Component/Form/Tests/Extension/Core/Type/CountryTypeTest.php
  40. +40 −40 src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php
  41. +39 −39 src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
  42. +1 −1  src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
  43. +27 −27 src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
  44. +2 −2 src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php
  45. +1 −1  src/Symfony/Component/Form/Tests/Extension/Core/Type/LocaleTypeTest.php
  46. +2 −2 src/Symfony/Component/Form/Tests/Extension/Core/Type/MoneyTypeTest.php
  47. +4 −4 src/Symfony/Component/Form/Tests/Extension/Core/Type/NumberTypeTest.php
  48. +3 −3 src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php
  49. +28 −28 src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php
  50. +1 −1  src/Symfony/Component/Form/Tests/Extension/Core/Type/TimezoneTypeTest.php
  51. +9 −9 src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php
  52. +2 −2 src/Symfony/Component/Form/Tests/FormRendererTest.php
  53. +0 −16 src/Symfony/Component/Form/Tests/FormViewInterface.php
  54. +3 −4 src/Symfony/Component/Form/Tests/ResolvedFormTypeTest.php
  55. +5 −5 src/Symfony/Component/Form/Tests/SimpleFormTest.php
View
10 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()
View
2  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;
/**
View
18 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 <bschussek@gmail.com>
@@ -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)
View
2  src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_enctype.html.php
@@ -1 +1 @@
-<?php if ($form->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
+<?php if ($form->vars['multipart']): ?>enctype="multipart/form-data"<?php endif ?>
View
2  src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget_compound.html.php
@@ -1,5 +1,5 @@
<div <?php echo $view['form']->block('widget_container_attributes') ?>>
- <?php if (!$form->hasParent() && $errors): ?>
+ <?php if (!$form->parent && $errors): ?>
<tr>
<td colspan="2">
<?php echo $view['form']->errors($form) ?>
View
2  src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_widget_compound.html.php
@@ -1,5 +1,5 @@
<table <?php echo $view['form']->block('widget_container_attributes') ?>>
- <?php if (!$form->hasParent()): ?>
+ <?php if (!$form->parent): ?>
<?php echo $view['form']->errors($form) ?>
<?php endif ?>
<?php echo $view['form']->block('form_rows') ?>
View
32 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 "<Bundle>:<Controller>".
*
- * @param FormViewInterface $view A FormViewInterface instance
+ * @param FormView $view A FormView instance
* @param string|array $themes A theme or an array of theme
*/
- 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)
*
* <form action="..." method="post" <?php echo $view['form']->enctype() ?>>
*
- * @param FormViewInterface $view The view for which to render the encoding type
+ * @param FormView $view The view for which to render the encoding type
*
* @return string The HTML markup
*/
- public function enctype(FormViewInterface $view)
+ public function enctype(FormView $view)
{
return $this->renderer->renderEnctype($view);
}
@@ -101,12 +101,12 @@ public function enctype(FormViewInterface $view)
*
* <?php echo view['form']->widget(array('separator' => '+++++)) ?>
*
- * @param FormViewInterface $view The view for which to render the widget
+ * @param FormView $view The view for which to render the widget
* @param array $variables Additional variables passed to the template
*
* @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);
}
View
26 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 @@ public function getResourceHierarchyLevel(FormViewInterface $view, array $blockH
*
* @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 @@ public function getResourceHierarchyLevel(FormViewInterface $view, array $blockH
*
* @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];
View
4 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)
{
}
View
4 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)
{
}
View
4 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
View
6 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(),
));
View
16 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;
}
}
}
View
14 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;
}
}
View
8 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';
}
}
View
10 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;
}
}
View
10 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
;
}
View
28 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;
}
/**
View
6 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']);
}
/**
View
6 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'] = '';
}
}
View
6 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;
}
/**
View
8 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';
}
}
View
8 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);
}
}
View
16 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
View
2  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();
View
6 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);
}
View
28 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 (= "_<id>_<section>" 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
View
20 src/Symfony/Component/Form/FormRendererEngineInterface.php
@@ -21,11 +21,11 @@
/**
* 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());
}
View
32 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);
*
* <form action="..." method="post" <?php echo $renderer->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());
*
* <?php echo $renderer->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.
View
8 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.
View
8 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.
View
170 src/Symfony/Component/Form/FormView.php
@@ -14,18 +14,28 @@
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
-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,7 +168,12 @@ 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()
{
@@ -175,46 +181,6 @@ public function hasParent()
}
/**
- * {@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.
*
* @return Boolean Whether the view has children.
@@ -228,14 +194,6 @@ public function hasChildren()
}
/**
- * {@inheritdoc}
- */
- public function has($name)
- {
- return isset($this->children[$name]);
- }
-
- /**
* Returns a child by name (implements \ArrayAccess).
*
* @param string $name The child name
@@ -244,7 +202,7 @@ public function has($name)
*/
public function offsetGet($name)
{
- return $this->get($name);
+ return $this->children[$name];
}
/**
View
150 src/Symfony/Component/Form/FormViewInterface.php
@@ -1,150 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Form;
-
-/**
- * @author Bernhard Schussek <bschussek@gmail.com>
- */
-interface FormViewInterface extends \ArrayAccess, \Traversable, \Countable
-{
- /**
- * Returns the name of the form.
- *
- * @return string The form name.
- */
- public function getName();
-
- /**
- * Returns whether the view was already rendered.
- *
- * @return Boolean Whether this view's widget is rendered.
- */
- public function isRendered();
-
- /**
- * Marks the view as rendered.
- *
- * @return FormViewInterface The view object.
- */
- public function setRendered();
-
- /**
- * Sets the parent view.
- *
- * @param FormViewInterface $parent The parent view.
- *
- * @return FormViewInterface The view object.
- */
- public function setParent(FormViewInterface $parent = null);
-
- /**
- * Returns the parent view.
- *
- * @return FormViewInterface The parent view.
- */
- public function getParent();
-
- /**
- * Returns whether this view has a parent.
- *
- * @return Boolean Whether this view has a parent
- */
- public function hasParent();
-
- /**
- * Adds a child view.
- *
- * @param FormViewInterface $child The child view to add.
- *
- * @return FormViewInterface The view object.
- */
- public function add(FormViewInterface $child);
-
- /**
- * Removes a child view.
- *
- * @param string $name The name of the removed child view.
- *
- * @return FormViewInterface The view object.
- */
- public function remove($name);
-
- /**
- * Returns the children.
- *
- * @return array The children as instances of FormView
- */
- public function all();
-
- /**
- * Returns a given child.
- *
- * @param string $name The name of the child
- *
- * @return FormViewInterface The child view
- */
- public function get($name);
-
- /**
- * Returns whether this view has a given child.
- *
- * @param string $name The name of the child
- *
- * @return Boolean Whether the child with the given name exists
- */
- public function has($name);
-
- /**
- * Sets a view variable.
- *
- * @param string $name The variable name.
- * @param string $value