[Form] Removed the ImmutableFormConfig class to save time spent with copying values (+20ms)

This commit is contained in:
Bernhard Schussek 2012-07-28 10:59:23 +02:00
parent de958c722c
commit 04cb5bc457
13 changed files with 211 additions and 421 deletions

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
@ -344,7 +344,7 @@ class ChoiceList implements ChoiceListInterface
{
$index = $this->createIndex($choice);
if ('' === $index || null === $index || !FormConfig::isValidName((string) $index)) {
if ('' === $index || null === $index || !FormConfigBuilder::isValidName((string) $index)) {
throw new InvalidConfigurationException('The index "' . $index . '" created by the choice list is invalid. It should be a valid, non-empty Form name.');
}

View File

@ -146,10 +146,6 @@ class Form implements \IteratorAggregate, FormInterface
*/
public function __construct(FormConfigInterface $config)
{
if (!$config instanceof ImmutableFormConfig) {
$config = new ImmutableFormConfig($config);
}
// Compound forms always need a data mapper, otherwise calls to
// `setData` and `add` will not lead to the correct population of
// the child forms.
@ -170,7 +166,7 @@ class Form implements \IteratorAggregate, FormInterface
/**
* Returns the configuration of the form.
*
* @return ImmutableFormConfig The form's immutable configuration.
* @return FormConfigInterface The form's configuration.
*/
public function getConfig()
{

View File

@ -20,7 +20,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderInterface
class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormBuilderInterface
{
/**
* The form factory.
@ -56,6 +56,7 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
* @param string $dataClass
* @param EventDispatcherInterface $dispatcher
* @param FormFactoryInterface $factory
* @param array $options
*/
public function __construct($name, $dataClass, EventDispatcherInterface $dispatcher, FormFactoryInterface $factory, array $options = array())
{
@ -77,6 +78,10 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
*/
public function add($child, $type = null, array $options = array())
{
if ($this->locked) {
throw new FormException('The form builder cannot be modified anymore.');
}
if ($child instanceof self) {
$child->setParent($this);
$this->children[$child->getName()] = $child;
@ -110,6 +115,10 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
*/
public function create($name, $type = null, array $options = array())
{
if ($this->locked) {
throw new FormException('The form builder cannot be modified anymore.');
}
if (null === $type && null === $this->getDataClass()) {
$type = 'text';
}
@ -142,6 +151,10 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
*/
public function remove($name)
{
if ($this->locked) {
throw new FormException('The form builder cannot be modified anymore.');
}
unset($this->unresolvedChildren[$name]);
if (array_key_exists($name, $this->children)) {
@ -195,7 +208,7 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
{
$this->resolveChildren();
$form = new Form($this);
$form = new Form($this->getFormConfig());
foreach ($this->children as $child) {
$form->add($child->getForm());
@ -217,6 +230,10 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
*/
public function setParent(FormBuilderInterface $parent = null)
{
if ($this->locked) {
throw new FormException('The form builder cannot be modified anymore.');
}
$this->parent = $parent;
return $this;

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface FormBuilderInterface extends FormConfigEditorInterface, \Traversable, \Countable
interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuilderInterface
{
/**
* Adds a new field to this group. A field must have a unique name within

View File

@ -11,18 +11,25 @@
namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
/**
* A basic form configuration.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormConfig implements FormConfigEditorInterface
class FormConfigBuilder implements FormConfigBuilderInterface
{
/**
* @var Boolean
*/
protected $locked = false;
/**
* @var EventDispatcherInterface
*/
@ -161,6 +168,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function addEventListener($eventName, $listener, $priority = 0)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->dispatcher->addListener($eventName, $listener, $priority);
return $this;
@ -171,6 +182,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function addEventSubscriber(EventSubscriberInterface $subscriber)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->dispatcher->addSubscriber($subscriber);
return $this;
@ -181,6 +196,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function addValidator(FormValidatorInterface $validator)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->validators[] = $validator;
return $this;
@ -191,6 +210,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
if ($forcePrepend) {
array_unshift($this->viewTransformers, $viewTransformer);
} else {
@ -205,6 +228,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function resetViewTransformers()
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->viewTransformers = array();
return $this;
@ -215,13 +242,17 @@ class FormConfig implements FormConfigEditorInterface
*
* @param DataTransformerInterface $viewTransformer
*
* @return self The configuration object.
* @return FormConfigBuilder The configuration object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link addViewTransformer()} instead.
*/
public function appendClientTransformer(DataTransformerInterface $viewTransformer)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
return $this->addViewTransformer($viewTransformer);
}
@ -230,25 +261,33 @@ class FormConfig implements FormConfigEditorInterface
*
* @param DataTransformerInterface $viewTransformer
*
* @return self The configuration object.
* @return FormConfigBuilder The configuration object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
public function prependClientTransformer(DataTransformerInterface $viewTransformer)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
return $this->addViewTransformer($viewTransformer, true);
}
/**
* Alias of {@link resetViewTransformers()}.
*
* @return self The configuration object.
* @return FormConfigBuilder The configuration object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link resetViewTransformers()} instead.
*/
public function resetClientTransformers()
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
return $this->resetViewTransformers();
}
@ -257,6 +296,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
if ($forceAppend) {
$this->modelTransformers[] = $modelTransformer;
} else {
@ -271,6 +314,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function resetModelTransformers()
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->modelTransformers = array();
return $this;
@ -281,12 +328,16 @@ class FormConfig implements FormConfigEditorInterface
*
* @param DataTransformerInterface $modelTransformer
*
* @return self The configuration object.
* @return FormConfigBuilder The configuration object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
public function appendNormTransformer(DataTransformerInterface $modelTransformer)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
return $this->addModelTransformer($modelTransformer, true);
}
@ -295,26 +346,34 @@ class FormConfig implements FormConfigEditorInterface
*
* @param DataTransformerInterface $modelTransformer
*
* @return self The configuration object.
* @return FormConfigBuilder The configuration object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link addModelTransformer()} instead.
*/
public function prependNormTransformer(DataTransformerInterface $modelTransformer)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
return $this->addModelTransformer($modelTransformer);
}
/**
* Alias of {@link resetModelTransformers()}.
*
* @return self The configuration object.
* @return FormConfigBuilder The configuration object.
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link resetModelTransformers()} instead.
*/
public function resetNormTransformers()
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
return $this->resetModelTransformers();
}
@ -549,6 +608,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setAttribute($name, $value)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->attributes[$name] = $value;
return $this;
@ -559,6 +622,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setAttributes(array $attributes)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->attributes = $attributes;
return $this;
@ -569,6 +636,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setDataMapper(DataMapperInterface $dataMapper = null)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->dataMapper = $dataMapper;
return $this;
@ -579,6 +650,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setDisabled($disabled)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->disabled = (Boolean) $disabled;
return $this;
@ -589,6 +664,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setEmptyData($emptyData)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->emptyData = $emptyData;
return $this;
@ -599,6 +678,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setErrorBubbling($errorBubbling)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->errorBubbling = null === $errorBubbling ? null : (Boolean) $errorBubbling;
return $this;
@ -609,6 +692,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setRequired($required)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->required = (Boolean) $required;
return $this;
@ -619,6 +706,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setPropertyPath($propertyPath)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
if (null !== $propertyPath && !$propertyPath instanceof PropertyPath) {
$propertyPath = new PropertyPath($propertyPath);
}
@ -633,6 +724,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setMapped($mapped)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->mapped = $mapped;
return $this;
@ -643,6 +738,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setByReference($byReference)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->byReference = $byReference;
return $this;
@ -653,6 +752,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setVirtual($virtual)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->virtual = $virtual;
return $this;
@ -663,6 +766,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setCompound($compound)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->compound = $compound;
return $this;
@ -673,6 +780,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setType(ResolvedFormTypeInterface $type)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->type = $type;
return $this;
@ -683,6 +794,10 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setData($data)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->data = $data;
return $this;
@ -693,11 +808,31 @@ class FormConfig implements FormConfigEditorInterface
*/
public function setDataLocked($locked)
{
if ($this->locked) {
throw new FormException('The config builder cannot be modified anymore.');
}
$this->dataLocked = $locked;
return $this;
}
/**
* {@inheritdoc}
*/
public function getFormConfig()
{
// This method should be idempotent, so clone the builder
$config = clone $this;
$config->locked = true;
if (!$config->dispatcher instanceof ImmutableEventDispatcher) {
$config->dispatcher = new ImmutableEventDispatcher($config->dispatcher);
}
return $config;
}
/**
* Validates whether the given variable is a valid form name.
*

View File

@ -16,7 +16,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface FormConfigEditorInterface extends FormConfigInterface
interface FormConfigBuilderInterface extends FormConfigInterface
{
/**
* Adds an event listener to an event on this form.
@ -240,4 +240,11 @@ interface FormConfigEditorInterface extends FormConfigInterface
* @return self The configuration object.
*/
public function setDataLocked($locked);
/**
* Builds and returns the form configuration.
*
* @return FormConfigInterface
*/
public function getFormConfig();
}

View File

@ -1,365 +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;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
/**
* A read-only form configuration.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class ImmutableFormConfig implements FormConfigInterface
{
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
private $dispatcher;
/**
* @var string
*/
private $name;
/**
* @var PropertyPath
*/
private $propertyPath;
/**
* @var Boolean
*/
private $mapped;
/**
* @var Boolean
*/
private $byReference;
/**
* @var Boolean
*/
private $virtual;
/**
* @var Boolean
*/
private $compound;
/**
* @var ResolvedFormTypeInterface
*/
private $type;
/**
* @var array
*/
private $viewTransformers;
/**
* @var array
*/
private $modelTransformers;
/**
* @var DataMapperInterface
*/
private $dataMapper;
/**
* @var FormValidatorInterface
*/
private $validators;
/**
* @var Boolean
*/
private $required;
/**
* @var Boolean
*/
private $disabled;
/**
* @var Boolean
*/
private $errorBubbling;
/**
* @var mixed
*/
private $emptyData;
/**
* @var array
*/
private $attributes;
/**
* @var mixed
*/
private $data;
/**
* @var string
*/
private $dataClass;
/**
* @var Boolean
*/
private $dataLocked;
/**
* @var array
*/
private $options;
/**
* Creates an unmodifiable copy of a given configuration.
*
* @param FormConfigInterface $config The configuration to copy.
*/
public function __construct(FormConfigInterface $config)
{
$dispatcher = $config->getEventDispatcher();
if (!$dispatcher instanceof ImmutableEventDispatcher) {
$dispatcher = new ImmutableEventDispatcher($dispatcher);
}
$this->dispatcher = $dispatcher;
$this->name = $config->getName();
$this->propertyPath = $config->getPropertyPath();
$this->mapped = $config->getMapped();
$this->byReference = $config->getByReference();
$this->virtual = $config->getVirtual();
$this->compound = $config->getCompound();
$this->type = $config->getType();
$this->viewTransformers = $config->getViewTransformers();
$this->modelTransformers = $config->getModelTransformers();
$this->dataMapper = $config->getDataMapper();
$this->validators = $config->getValidators();
$this->required = $config->getRequired();
$this->disabled = $config->getDisabled();
$this->errorBubbling = $config->getErrorBubbling();
$this->emptyData = $config->getEmptyData();
$this->attributes = $config->getAttributes();
$this->data = $config->getData();
$this->dataClass = $config->getDataClass();
$this->dataLocked = $config->getDataLocked();
$this->options = $config->getOptions();
}
/**
* {@inheritdoc}
*/
public function getEventDispatcher()
{
return $this->dispatcher;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getPropertyPath()
{
return $this->propertyPath;
}
/**
* {@inheritdoc}
*/
public function getMapped()
{
return $this->mapped;
}
/**
* {@inheritdoc}
*/
public function getByReference()
{
return $this->byReference;
}
/**
* {@inheritdoc}
*/
public function getVirtual()
{
return $this->virtual;
}
/**
* {@inheritdoc}
*/
public function getCompound()
{
return $this->compound;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return $this->type;
}
/**
* {@inheritdoc}
*/
public function getViewTransformers()
{
return $this->viewTransformers;
}
/**
* {@inheritdoc}
*/
public function getModelTransformers()
{
return $this->modelTransformers;
}
/**
* Returns the data mapper of the form.
*
* @return DataMapperInterface The data mapper.
*/
public function getDataMapper()
{
return $this->dataMapper;
}
/**
* {@inheritdoc}
*/
public function getValidators()
{
return $this->validators;
}
/**
* {@inheritdoc}
*/
public function getRequired()
{
return $this->required;
}
/**
* {@inheritdoc}
*/
public function getDisabled()
{
return $this->disabled;
}
/**
* {@inheritdoc}
*/
public function getErrorBubbling()
{
return $this->errorBubbling;
}
/**
* {@inheritdoc}
*/
public function getEmptyData()
{
return $this->emptyData;
}
/**
* {@inheritdoc}
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* {@inheritdoc}
*/
public function hasAttribute($name)
{
return isset($this->attributes[$name]);
}
/**
* {@inheritdoc}
*/
public function getAttribute($name, $default = null)
{
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
}
/**
* {@inheritdoc}
*/
public function getData()
{
return $this->data;
}
/**
* {@inheritdoc}
*/
public function getDataClass()
{
return $this->dataClass;
}
/**
* {@inheritdoc}
*/
public function getDataLocked()
{
return $this->dataLocked;
}
/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->options;
}
/**
* {@inheritdoc}
*/
public function hasOption($name)
{
return isset($this->options[$name]);
}
/**
* {@inheritdoc}
*/
public function getOption($name, $default = null)
{
return isset($this->options[$name]) ? $this->options[$name] : $default;
}
}

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form\Tests\Extension\Core\DataMapper;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
@ -89,7 +89,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
->with($car)
->will($this->returnValue($engine));
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$form = $this->getForm($config);
@ -112,7 +112,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
->with($car)
->will($this->returnValue($engine));
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(false);
$config->setPropertyPath($propertyPath);
$form = $this->getForm($config);
@ -127,7 +127,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
{
$car = new \stdClass();
$config = new FormConfig(null, '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder(null, '\stdClass', $this->dispatcher);
$config->setByReference(true);
$form = $this->getForm($config);
@ -146,7 +146,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('getValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setMapped(false);
$config->setPropertyPath($propertyPath);
@ -164,7 +164,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('getValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$form = $this->getForm($config);
@ -185,14 +185,14 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
->with($car)
->will($this->returnValue($engine));
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setVirtual(true);
$config->setCompound(true);
$config->setDataMapper($this->getDataMapper());
$form = $this->getForm($config);
$config = new FormConfig('engine', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('engine', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$child = $this->getForm($config);
@ -215,7 +215,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
->method('setValue')
->with($car, $engine);
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(false);
$config->setPropertyPath($propertyPath);
$config->setData($engine);
@ -234,7 +234,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
->method('setValue')
->with($car, $engine);
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$config->setData($engine);
@ -258,7 +258,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('setValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$config->setData($engine);
@ -276,7 +276,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('setValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$config->setData($engine);
@ -294,7 +294,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('setValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$config->setData(null);
@ -312,7 +312,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('setValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$config->setData($engine);
@ -330,7 +330,7 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
$propertyPath->expects($this->never())
->method('setValue');
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($propertyPath);
$config->setData($engine);
@ -356,14 +356,14 @@ class PropertyPathMapperTest extends \PHPUnit_Framework_TestCase
->method('setValue')
->with($car, $engine);
$config = new FormConfig('name', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', '\stdClass', $this->dispatcher);
$config->setPropertyPath($parentPath);
$config->setVirtual(true);
$config->setCompound(true);
$config->setDataMapper($this->getDataMapper());
$form = $this->getForm($config);
$config = new FormConfig('engine', '\stdClass', $this->dispatcher);
$config = new FormConfigBuilder('engine', '\stdClass', $this->dispatcher);
$config->setByReference(true);
$config->setPropertyPath($childPath);
$config->setData($engine);

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
use Symfony\Component\Form\Extension\Core\EventListener\BindRequestListener;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -96,7 +96,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('author', null, $dispatcher);
$config = new FormConfigBuilder('author', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
@ -123,7 +123,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('', null, $dispatcher);
$config = new FormConfigBuilder('', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
@ -150,7 +150,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('author', null, $dispatcher);
$config = new FormConfigBuilder('author', null, $dispatcher);
$config->setCompound(true);
$config->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'));
$form = new Form($config);
@ -177,7 +177,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('author', null, $dispatcher);
$config = new FormConfigBuilder('author', null, $dispatcher);
$config->setCompound(false);
$form = new Form($config);
$event = new FormEvent($form, $request);
@ -201,7 +201,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('author', null, $dispatcher);
$config = new FormConfigBuilder('author', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
@ -225,7 +225,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('', null, $dispatcher);
$config = new FormConfigBuilder('', null, $dispatcher);
$form = new Form($config);
$event = new FormEvent($form, $request);
@ -249,7 +249,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('author', null, $dispatcher);
$config = new FormConfigBuilder('author', null, $dispatcher);
$config->setCompound(true);
$config->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'));
$form = new Form($config);
@ -272,7 +272,7 @@ class BindRequestListenerTest extends \PHPUnit_Framework_TestCase
));
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$config = new FormConfig('author', null, $dispatcher);
$config = new FormConfigBuilder('author', null, $dispatcher);
$config->setCompound(false);
$form = new Form($config);
$event = new FormEvent($form, $request);

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Validator\ConstraintViolation;
@ -67,7 +67,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = array(), $virtual = false, $synchronized = true)
{
$config = new FormConfig($name, $dataClass, $this->dispatcher, array(
$config = new FormConfigBuilder($name, $dataClass, $this->dispatcher, array(
'error_mapping' => $errorMapping,
));
$config->setMapped(true);

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Tests;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
class FormConfigTest extends \PHPUnit_Framework_TestCase
{
@ -64,7 +64,7 @@ class FormConfigTest extends \PHPUnit_Framework_TestCase
$dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
try {
new FormConfig($name, null, $dispatcher);
new FormConfigBuilder($name, null, $dispatcher);
if (!$accepted) {
$this->fail(sprintf('The value "%s" should not be accepted', $name));
}

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\ResolvedFormType;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\Form;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Form\FormConfig;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Exception\TransformationFailedException;
@ -34,7 +34,7 @@ class SimpleFormTest extends AbstractFormTest
'foo' => 'bar',
));
$config = new FormConfig('name', null, $this->dispatcher);
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addViewTransformer($view);
$config->addModelTransformer($model);
$config->setData('default');
@ -56,7 +56,7 @@ class SimpleFormTest extends AbstractFormTest
$mock->expects($this->at(1))
->method('preBind');
$config = new FormConfig('name', null, $this->dispatcher);
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addEventListener(FormEvents::PRE_SET_DATA, array($mock, 'preSetData'));
$config->addEventListener(FormEvents::PRE_BIND, array($mock, 'preBind'));
$form = new Form($config);
@ -716,7 +716,7 @@ class SimpleFormTest extends AbstractFormTest
*/
public function testViewDataMustNotBeObjectIfDataClassIsNull()
{
$config = new FormConfig('name', null, $this->dispatcher);
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addViewTransformer(new FixedDataTransformer(array(
'' => '',
'foo' => new \stdClass(),
@ -729,7 +729,7 @@ class SimpleFormTest extends AbstractFormTest
public function testViewDataMayBeArrayAccessIfDataClassIsNull()
{
$arrayAccess = $this->getMock('\ArrayAccess');
$config = new FormConfig('name', null, $this->dispatcher);
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addViewTransformer(new FixedDataTransformer(array(
'' => '',
'foo' => $arrayAccess,
@ -746,7 +746,7 @@ class SimpleFormTest extends AbstractFormTest
*/
public function testViewDataMustBeObjectIfDataClassIsSet()
{
$config = new FormConfig('name', 'stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
$config->addViewTransformer(new FixedDataTransformer(array(
'' => '',
'foo' => array('bar' => 'baz'),
@ -762,7 +762,7 @@ class SimpleFormTest extends AbstractFormTest
public function testSetDataCannotInvokeItself()
{
// Cycle detection to prevent endless loops
$config = new FormConfig('name', 'stdClass', $this->dispatcher);
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$event->getForm()->setData('bar');
});