Permalink
Browse files

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

…to increase performance (PHP +200ms, Twig +150ms)
  • Loading branch information...
1 parent 19e9ea9 commit 84c9dfdab43a32eda3e31814a59e6499e67db73d @webmozart webmozart committed Jul 16, 2012
Showing with 404 additions and 616 deletions.
  1. +13 −13 AbstractRendererEngine.php
  2. +2 −2 AbstractType.php
  3. +2 −2 AbstractTypeExtension.php
  4. +2 −2 CHANGELOG.md
  5. +3 −3 Extension/Core/Type/CheckboxType.php
  6. +8 −8 Extension/Core/Type/ChoiceType.php
  7. +7 −7 Extension/Core/Type/CollectionType.php
  8. +4 −4 Extension/Core/Type/DateTimeType.php
  9. +5 −5 Extension/Core/Type/DateType.php
  10. +5 −5 Extension/Core/Type/FileType.php
  11. +13 −15 Extension/Core/Type/FormType.php
  12. +3 −3 Extension/Core/Type/MoneyType.php
  13. +3 −3 Extension/Core/Type/PasswordType.php
  14. +3 −3 Extension/Core/Type/TextareaType.php
  15. +4 −4 Extension/Core/Type/TimeType.php
  16. +4 −4 Extension/Csrf/Type/FormTypeCsrfExtension.php
  17. +8 −8 Extension/Templating/TemplatingRendererEngine.php
  18. +1 −1 Form.php
  19. +3 −3 FormInterface.php
  20. +14 −14 FormRenderer.php
  21. +10 −10 FormRendererEngineInterface.php
  22. +16 −16 FormRendererInterface.php
  23. +4 −4 FormTypeExtensionInterface.php
  24. +4 −4 FormTypeInterface.php
  25. +64 −106 FormView.php
  26. +0 −150 FormViewInterface.php
  27. +6 −7 ResolvedFormType.php
  28. +3 −3 ResolvedFormTypeInterface.php
  29. +5 −5 Tests/Extension/Core/Type/CheckboxTypeTest.php
  30. +14 −14 Tests/Extension/Core/Type/ChoiceTypeTest.php
  31. +2 −2 Tests/Extension/Core/Type/CollectionTypeTest.php
  32. +2 −2 Tests/Extension/Core/Type/CountryTypeTest.php
  33. +40 −40 Tests/Extension/Core/Type/DateTimeTypeTest.php
  34. +39 −39 Tests/Extension/Core/Type/DateTypeTest.php
  35. +1 −1 Tests/Extension/Core/Type/FileTypeTest.php
  36. +27 −27 Tests/Extension/Core/Type/FormTypeTest.php
  37. +2 −2 Tests/Extension/Core/Type/LanguageTypeTest.php
  38. +1 −1 Tests/Extension/Core/Type/LocaleTypeTest.php
  39. +2 −2 Tests/Extension/Core/Type/MoneyTypeTest.php
  40. +4 −4 Tests/Extension/Core/Type/NumberTypeTest.php
  41. +3 −3 Tests/Extension/Core/Type/PasswordTypeTest.php
  42. +28 −28 Tests/Extension/Core/Type/TimeTypeTest.php
  43. +1 −1 Tests/Extension/Core/Type/TimezoneTypeTest.php
  44. +9 −9 Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php
  45. +2 −2 Tests/FormRendererTest.php
  46. +0 −16 Tests/FormViewInterface.php
  47. +3 −4 Tests/ResolvedFormTypeTest.php
  48. +5 −5 Tests/SimpleFormTest.php
View
@@ -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
@@ -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)
{
}
@@ -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
@@ -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
@@ -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(),
));
@@ -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,33 +93,33 @@ 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']) {
$childName .= '[]';
}
foreach ($view as $childView) {
- $childView->setVar('full_name', $childName);
+ $childView->vars['full_name'] = $childName;
}
}
}
@@ -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;
}
}
@@ -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';
}
}
@@ -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;
}
}
@@ -13,17 +13,17 @@
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
{
/**
* {@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
;
}
Oops, something went wrong.

0 comments on commit 84c9dfd

Please sign in to comment.