merged branch bschussek/issue6558 (PR #6578)

This PR was merged into the 2.1 branch.

Commits
-------

33e9d00 [Form] Deleted references in FormBuilder::getFormConfig() to improve performance

Discussion
----------

[Form] Deleted references in FormBuilder::getFormConfig() to improve performance

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6558
Todo: -
License of the code: MIT
Documentation PR: -

---------------------------------------------------------------------------

by vicb at 2013-01-07T11:09:24Z

> Backwards compatibility break: no

Really ?

---------------------------------------------------------------------------

by vicb at 2013-01-07T12:27:37Z

Adding a public method is a BC break.

---------------------------------------------------------------------------

by bschussek at 2013-01-07T12:42:14Z

The method is inherited from the parent class, so the change should not affect BC.

---------------------------------------------------------------------------

by vicb at 2013-01-07T13:27:21Z

my bad.
This commit is contained in:
Fabien Potencier 2013-01-07 16:44:13 +01:00
commit 87a85b6696
2 changed files with 39 additions and 0 deletions

View File

@ -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}
*/

View File

@ -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')