From 33e9d002a708bf54e551c7e75de57841ee105535 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sat, 5 Jan 2013 18:04:01 +0100 Subject: [PATCH] [Form] Deleted references in FormBuilder::getFormConfig() to improve performance --- src/Symfony/Component/Form/FormBuilder.php | 15 ++++++++++++ .../Component/Form/Tests/FormBuilderTest.php | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index 9d23ff565f..8560e75806 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -202,6 +202,21 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB return count($this->children); } + /** + * {@inheritdoc} + */ + public function getFormConfig() + { + $config = parent::getFormConfig(); + + $config->factory = null; + $config->parent = null; + $config->children = array(); + $config->unresolvedChildren = array(); + + return $config; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index 42d4317459..ff04006b54 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -232,6 +232,30 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase $this->builder->create('bar', 'text'); } + public function testGetFormConfigErasesReferences() + { + $builder = new FormBuilder('name', null, $this->dispatcher, $this->factory); + $builder->setParent(new FormBuilder('parent', null, $this->dispatcher, $this->factory)); + $builder->add(new FormBuilder('child', null, $this->dispatcher, $this->factory)); + + $config = $builder->getFormConfig(); + $reflClass = new \ReflectionClass($config); + $factory = $reflClass->getProperty('factory'); + $parent = $reflClass->getProperty('parent'); + $children = $reflClass->getProperty('children'); + $unresolvedChildren = $reflClass->getProperty('unresolvedChildren'); + + $factory->setAccessible(true); + $parent->setAccessible(true); + $children->setAccessible(true); + $unresolvedChildren->setAccessible(true); + + $this->assertNull($factory->getValue($config)); + $this->assertNull($parent->getValue($config)); + $this->assertEmpty($children->getValue($config)); + $this->assertEmpty($unresolvedChildren->getValue($config)); + } + private function getFormBuilder($name = 'name') { $mock = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')