[Form] Renamed client and application format to view and model format
This commit is contained in:
parent
8cae3282d8
commit
bec80157f9
@ -467,8 +467,10 @@
|
||||
* `getClientTransformers`
|
||||
* `getAttribute`
|
||||
* `hasAttribute`
|
||||
* `getClientData`
|
||||
|
||||
You can access these methods on the `FormConfigInterface` object instead.
|
||||
The method `getClientData` has a new equivalent that is named `getViewData`.
|
||||
You can access all other methods on the `FormConfigInterface` object instead.
|
||||
|
||||
Before:
|
||||
|
||||
@ -644,6 +646,31 @@
|
||||
public function buildViewBottomUp(FormViewInterface $view, FormInterface $form, array $options)
|
||||
```
|
||||
|
||||
* The following methods in `FormBuilder` were deprecated and have a new equivalent:
|
||||
|
||||
* `prependClientTransformer`: `addViewTransformer`
|
||||
* `appendClientTransformer`: no new equivalent, should not be used
|
||||
* `getClientTransformers`: `getViewTransformers`
|
||||
* `resetClientTransformers`: `resetViewTransformers`
|
||||
* `prependNormTransformer`: no new equivalent, should not be used
|
||||
* `appendNormTransformer`: `addModelTransformer`
|
||||
* `getNormTransformers`: `getModelTransformers`
|
||||
* `resetNormTransformers`: `resetModelTransformers`
|
||||
|
||||
The deprecated methods will be removed in Symfony 2.3. You are advised to update your application.
|
||||
|
||||
Before:
|
||||
|
||||
```
|
||||
$builder->prependClientTransformer(new MyTransformer());
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```
|
||||
$builder->addViewTransformer(new MyTransformer());
|
||||
```
|
||||
|
||||
### Validator
|
||||
|
||||
* The methods `setMessage()`, `getMessageTemplate()` and
|
||||
|
@ -75,6 +75,7 @@ CHANGELOG
|
||||
* errors are not mapped to unsynchronized forms anymore
|
||||
* [BC BREAK] changed Form constructor to accept a single `FormConfigInterface` object
|
||||
* [BC BREAK] changed argument order in the FormBuilder constructor
|
||||
* added Form method `getViewData`
|
||||
* deprecated Form methods
|
||||
* `getTypes`
|
||||
* `getErrorBubbling`
|
||||
@ -82,6 +83,23 @@ CHANGELOG
|
||||
* `getClientTransformers`
|
||||
* `getAttribute`
|
||||
* `hasAttribute`
|
||||
* `getClientData`
|
||||
* added FormBuilder methods
|
||||
* `addViewTransformer`
|
||||
* `getViewTransformers`
|
||||
* `resetViewTransformers`
|
||||
* `addModelTransformer`
|
||||
* `getModelTransformers`
|
||||
* `resetModelTransformers`
|
||||
* deprecated FormBuilder methods
|
||||
* `prependClientTransformer`
|
||||
* `appendClientTransformer`
|
||||
* `getClientTransformers`
|
||||
* `resetClientTransformers`
|
||||
* `prependNormTransformer`
|
||||
* `appendNormTransformer`
|
||||
* `getNormTransformers`
|
||||
* `resetNormTransformers`
|
||||
* deprecated the option "validation_constraint" in favor of the new
|
||||
option "constraints"
|
||||
* removed superfluous methods from DataMapperInterface
|
||||
|
@ -26,7 +26,7 @@ class CheckboxType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->appendClientTransformer(new BooleanToStringTransformer($options['value']))
|
||||
->addViewTransformer(new BooleanToStringTransformer($options['value']))
|
||||
;
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ class CheckboxType extends AbstractType
|
||||
{
|
||||
$view
|
||||
->set('value', $options['value'])
|
||||
->set('checked', null !== $form->getClientData())
|
||||
->set('checked', null !== $form->getViewData())
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -46,20 +46,20 @@ class ChoiceType extends AbstractType
|
||||
|
||||
if ($options['multiple']) {
|
||||
$builder
|
||||
->appendClientTransformer(new ChoicesToBooleanArrayTransformer($options['choice_list']))
|
||||
->addViewTransformer(new ChoicesToBooleanArrayTransformer($options['choice_list']))
|
||||
->addEventSubscriber(new FixCheckboxInputListener($options['choice_list']), 10)
|
||||
;
|
||||
} else {
|
||||
$builder
|
||||
->appendClientTransformer(new ChoiceToBooleanArrayTransformer($options['choice_list']))
|
||||
->addViewTransformer(new ChoiceToBooleanArrayTransformer($options['choice_list']))
|
||||
->addEventSubscriber(new FixRadioInputListener($options['choice_list']), 10)
|
||||
;
|
||||
}
|
||||
} else {
|
||||
if ($options['multiple']) {
|
||||
$builder->appendClientTransformer(new ChoicesToValuesTransformer($options['choice_list']));
|
||||
$builder->addViewTransformer(new ChoicesToValuesTransformer($options['choice_list']));
|
||||
} else {
|
||||
$builder->appendClientTransformer(new ChoiceToValueTransformer($options['choice_list']));
|
||||
$builder->addViewTransformer(new ChoiceToValueTransformer($options['choice_list']));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ class DateTimeType extends AbstractType
|
||||
}
|
||||
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
|
||||
$builder->addViewTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
|
||||
} else {
|
||||
// Only pass a subset of the options to children
|
||||
$dateOptions = array_intersect_key($options, array_flip(array(
|
||||
@ -86,7 +86,7 @@ class DateTimeType extends AbstractType
|
||||
$timeOptions['input'] = 'array';
|
||||
|
||||
$builder
|
||||
->appendClientTransformer(new DataTransformerChain(array(
|
||||
->addViewTransformer(new DataTransformerChain(array(
|
||||
new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts),
|
||||
new ArrayToPartsTransformer(array(
|
||||
'date' => array('year', 'month', 'day'),
|
||||
|
@ -63,7 +63,7 @@ class DateType extends AbstractType
|
||||
);
|
||||
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
|
||||
$builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
|
||||
} else {
|
||||
$yearOptions = $monthOptions = $dayOptions = array();
|
||||
|
||||
@ -110,7 +110,7 @@ class DateType extends AbstractType
|
||||
->add('year', $options['widget'], $yearOptions)
|
||||
->add('month', $options['widget'], $monthOptions)
|
||||
->add('day', $options['widget'], $dayOptions)
|
||||
->appendClientTransformer(new DateTimeToArrayTransformer(
|
||||
->addViewTransformer(new DateTimeToArrayTransformer(
|
||||
$options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')
|
||||
))
|
||||
;
|
||||
|
@ -97,7 +97,7 @@ class FormType extends AbstractType
|
||||
->set('read_only', $readOnly)
|
||||
->set('errors', $form->getErrors())
|
||||
->set('valid', $form->isBound() ? $form->isValid() : true)
|
||||
->set('value', $form->getClientData())
|
||||
->set('value', $form->getViewData())
|
||||
->set('disabled', $form->isDisabled())
|
||||
->set('required', $form->isRequired())
|
||||
->set('max_length', $options['max_length'])
|
||||
|
@ -23,7 +23,7 @@ class IntegerType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->appendClientTransformer(
|
||||
$builder->addViewTransformer(
|
||||
new IntegerToLocalizedStringTransformer(
|
||||
$options['precision'],
|
||||
$options['grouping'],
|
||||
|
@ -28,7 +28,7 @@ class MoneyType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->appendClientTransformer(new MoneyToLocalizedStringTransformer(
|
||||
->addViewTransformer(new MoneyToLocalizedStringTransformer(
|
||||
$options['precision'],
|
||||
$options['grouping'],
|
||||
null,
|
||||
|
@ -23,7 +23,7 @@ class NumberType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->appendClientTransformer(new NumberToLocalizedStringTransformer(
|
||||
$builder->addViewTransformer(new NumberToLocalizedStringTransformer(
|
||||
$options['precision'],
|
||||
$options['grouping'],
|
||||
$options['rounding_mode']
|
||||
|
@ -23,7 +23,7 @@ class PercentType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->appendClientTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type']));
|
||||
$builder->addViewTransformer(new PercentToLocalizedStringTransformer($options['precision'], $options['type']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ class RepeatedType extends AbstractType
|
||||
$options['second_options']['required'] = $options['required'];
|
||||
|
||||
$builder
|
||||
->appendClientTransformer(new ValueToDuplicatesTransformer(array(
|
||||
->addViewTransformer(new ValueToDuplicatesTransformer(array(
|
||||
$options['first_name'],
|
||||
$options['second_name'],
|
||||
)))
|
||||
|
@ -24,7 +24,7 @@ class TextType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->appendClientTransformer(new ValueToStringTransformer())
|
||||
->addViewTransformer(new ValueToStringTransformer())
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ class TimeType extends AbstractType
|
||||
}
|
||||
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
|
||||
$builder->addViewTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
|
||||
} else {
|
||||
$hourOptions = $minuteOptions = $secondOptions = array();
|
||||
|
||||
@ -92,7 +92,7 @@ class TimeType extends AbstractType
|
||||
$builder->add('second', $options['widget'], $secondOptions);
|
||||
}
|
||||
|
||||
$builder->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, 'text' === $options['widget']));
|
||||
$builder->addViewTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, 'text' === $options['widget']));
|
||||
}
|
||||
|
||||
if ('string' === $options['input']) {
|
||||
|
@ -80,15 +80,15 @@ class FormValidator extends ConstraintValidator
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$clientDataAsString = is_scalar($form->getClientData())
|
||||
? (string) $form->getClientData()
|
||||
: gettype($form->getClientData());
|
||||
$clientDataAsString = is_scalar($form->getViewData())
|
||||
? (string) $form->getViewData()
|
||||
: gettype($form->getViewData());
|
||||
|
||||
// Mark the form with an error if it is not synchronized
|
||||
$this->context->addViolation(
|
||||
$config->getOption('invalid_message'),
|
||||
array('{{ value }}' => $clientDataAsString),
|
||||
$form->getClientData(),
|
||||
$form->getViewData(),
|
||||
null,
|
||||
Form::ERR_INVALID
|
||||
);
|
||||
|
@ -89,10 +89,10 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
private $bound = false;
|
||||
|
||||
/**
|
||||
* The form data in application format
|
||||
* The form data in model format
|
||||
* @var mixed
|
||||
*/
|
||||
private $appData;
|
||||
private $modelData;
|
||||
|
||||
/**
|
||||
* The form data in normalized format
|
||||
@ -101,10 +101,10 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
private $normData;
|
||||
|
||||
/**
|
||||
* The form data in client format
|
||||
* The form data in view format
|
||||
* @var mixed
|
||||
*/
|
||||
private $clientData;
|
||||
private $viewData;
|
||||
|
||||
/**
|
||||
* The bound values that don't belong to any children
|
||||
@ -113,7 +113,7 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
private $extraData = array();
|
||||
|
||||
/**
|
||||
* Whether the data in application, normalized and client format is
|
||||
* Whether the data in model, normalized and view format is
|
||||
* synchronized. Data may not be synchronized if transformation errors
|
||||
* occur.
|
||||
* @var Boolean
|
||||
@ -315,75 +315,75 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
/**
|
||||
* Updates the form with default data.
|
||||
*
|
||||
* @param array $appData The data formatted as expected for the underlying object
|
||||
* @param array $modelData The data formatted as expected for the underlying object
|
||||
*
|
||||
* @return Form The current form
|
||||
*/
|
||||
public function setData($appData)
|
||||
public function setData($modelData)
|
||||
{
|
||||
if ($this->bound) {
|
||||
throw new AlreadyBoundException('You cannot change the data of a bound form');
|
||||
}
|
||||
|
||||
if (is_object($appData) && !$this->config->getByReference()) {
|
||||
$appData = clone $appData;
|
||||
if (is_object($modelData) && !$this->config->getByReference()) {
|
||||
$modelData = clone $modelData;
|
||||
}
|
||||
|
||||
$event = new DataEvent($this, $appData);
|
||||
$event = new DataEvent($this, $modelData);
|
||||
$this->config->getEventDispatcher()->dispatch(FormEvents::PRE_SET_DATA, $event);
|
||||
|
||||
// Hook to change content of the data
|
||||
$event = new FilterDataEvent($this, $appData);
|
||||
$event = new FilterDataEvent($this, $modelData);
|
||||
$this->config->getEventDispatcher()->dispatch(FormEvents::SET_DATA, $event);
|
||||
$appData = $event->getData();
|
||||
$modelData = $event->getData();
|
||||
|
||||
// Treat data as strings unless a value transformer exists
|
||||
if (!$this->config->getClientTransformers() && !$this->config->getNormTransformers() && is_scalar($appData)) {
|
||||
$appData = (string) $appData;
|
||||
if (!$this->config->getViewTransformers() && !$this->config->getModelTransformers() && is_scalar($modelData)) {
|
||||
$modelData = (string) $modelData;
|
||||
}
|
||||
|
||||
// Synchronize representations - must not change the content!
|
||||
$normData = $this->appToNorm($appData);
|
||||
$clientData = $this->normToClient($normData);
|
||||
$normData = $this->modelToNorm($modelData);
|
||||
$viewData = $this->normToView($normData);
|
||||
|
||||
// Validate if client data matches data class (unless empty)
|
||||
if (!empty($clientData)) {
|
||||
// Validate if view data matches data class (unless empty)
|
||||
if (!empty($viewData)) {
|
||||
$dataClass = $this->config->getDataClass();
|
||||
|
||||
if (null === $dataClass && is_object($clientData) && !$clientData instanceof \ArrayAccess) {
|
||||
if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) {
|
||||
$expectedType = 'scalar, array or an instance of \ArrayAccess';
|
||||
|
||||
throw new FormException(
|
||||
'The form\'s client data is expected to be of type ' . $expectedType . ', ' .
|
||||
'but is an instance of class ' . get_class($clientData) . '. You ' .
|
||||
'The form\'s view data is expected to be of type ' . $expectedType . ', ' .
|
||||
'but is an instance of class ' . get_class($viewData) . '. You ' .
|
||||
'can avoid this error by setting the "data_class" option to ' .
|
||||
'"' . get_class($clientData) . '" or by adding a client transformer ' .
|
||||
'that transforms ' . get_class($clientData) . ' to ' . $expectedType . '.'
|
||||
'"' . get_class($viewData) . '" or by adding a view transformer ' .
|
||||
'that transforms ' . get_class($viewData) . ' to ' . $expectedType . '.'
|
||||
);
|
||||
}
|
||||
|
||||
if (null !== $dataClass && !$clientData instanceof $dataClass) {
|
||||
if (null !== $dataClass && !$viewData instanceof $dataClass) {
|
||||
throw new FormException(
|
||||
'The form\'s client data is expected to be an instance of class ' .
|
||||
$dataClass . ', but has the type ' . gettype($clientData) . '. You ' .
|
||||
'The form\'s view data is expected to be an instance of class ' .
|
||||
$dataClass . ', but has the type ' . gettype($viewData) . '. You ' .
|
||||
'can avoid this error by setting the "data_class" option to ' .
|
||||
'null or by adding a client transformer that transforms ' .
|
||||
gettype($clientData) . ' to ' . $dataClass . '.'
|
||||
'null or by adding a view transformer that transforms ' .
|
||||
gettype($viewData) . ' to ' . $dataClass . '.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->appData = $appData;
|
||||
$this->modelData = $modelData;
|
||||
$this->normData = $normData;
|
||||
$this->clientData = $clientData;
|
||||
$this->viewData = $viewData;
|
||||
$this->synchronized = true;
|
||||
|
||||
if (count($this->children) > 0 && $this->config->getDataMapper()) {
|
||||
// Update child forms from the data
|
||||
$this->config->getDataMapper()->mapDataToForms($clientData, $this->children);
|
||||
$this->config->getDataMapper()->mapDataToForms($viewData, $this->children);
|
||||
}
|
||||
|
||||
$event = new DataEvent($this, $appData);
|
||||
$event = new DataEvent($this, $modelData);
|
||||
$this->config->getEventDispatcher()->dispatch(FormEvents::POST_SET_DATA, $event);
|
||||
|
||||
return $this;
|
||||
@ -396,7 +396,7 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->appData;
|
||||
return $this->modelData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -404,9 +404,22 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getViewData()
|
||||
{
|
||||
return $this->viewData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link getViewData()}.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link getViewData()} instead.
|
||||
*/
|
||||
public function getClientData()
|
||||
{
|
||||
return $this->clientData;
|
||||
return $this->getViewData();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -422,13 +435,13 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
/**
|
||||
* Binds data to the form, transforms and validates it.
|
||||
*
|
||||
* @param string|array $clientData The data
|
||||
* @param string|array $submittedData The data
|
||||
*
|
||||
* @return Form The current form
|
||||
*
|
||||
* @throws UnexpectedTypeException
|
||||
*/
|
||||
public function bind($clientData)
|
||||
public function bind($submittedData)
|
||||
{
|
||||
if ($this->bound) {
|
||||
throw new AlreadyBoundException('A form can only be bound once');
|
||||
@ -444,43 +457,46 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
// whether an empty value has been submitted or whether no value has
|
||||
// been submitted at all. This is important for processing checkboxes
|
||||
// and radio buttons with empty values.
|
||||
if (is_scalar($clientData)) {
|
||||
$clientData = (string) $clientData;
|
||||
if (is_scalar($submittedData)) {
|
||||
$submittedData = (string) $submittedData;
|
||||
}
|
||||
|
||||
// Initialize errors in the very beginning so that we don't lose any
|
||||
// errors added during listeners
|
||||
$this->errors = array();
|
||||
|
||||
$event = new DataEvent($this, $clientData);
|
||||
$event = new DataEvent($this, $submittedData);
|
||||
$this->config->getEventDispatcher()->dispatch(FormEvents::PRE_BIND, $event);
|
||||
|
||||
$appData = null;
|
||||
$modelData = null;
|
||||
$normData = null;
|
||||
$extraData = array();
|
||||
$synchronized = false;
|
||||
|
||||
// Hook to change content of the data bound by the browser
|
||||
$event = new FilterDataEvent($this, $clientData);
|
||||
$event = new FilterDataEvent($this, $submittedData);
|
||||
$this->config->getEventDispatcher()->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
|
||||
$clientData = $event->getData();
|
||||
$submittedData = $event->getData();
|
||||
|
||||
// Build the data in the view format
|
||||
$viewData = $submittedData;
|
||||
|
||||
if (count($this->children) > 0) {
|
||||
if (null === $clientData || '' === $clientData) {
|
||||
$clientData = array();
|
||||
if (null === $viewData || '' === $viewData) {
|
||||
$viewData = array();
|
||||
}
|
||||
|
||||
if (!is_array($clientData)) {
|
||||
throw new UnexpectedTypeException($clientData, 'array');
|
||||
if (!is_array($viewData)) {
|
||||
throw new UnexpectedTypeException($viewData, 'array');
|
||||
}
|
||||
|
||||
foreach ($this->children as $name => $child) {
|
||||
if (!isset($clientData[$name])) {
|
||||
$clientData[$name] = null;
|
||||
if (!isset($viewData[$name])) {
|
||||
$viewData[$name] = null;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($clientData as $name => $value) {
|
||||
foreach ($viewData as $name => $value) {
|
||||
if ($this->has($name)) {
|
||||
$this->children[$name]->bind($value);
|
||||
} else {
|
||||
@ -488,31 +504,32 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a data mapper, use old client data and merge
|
||||
// If we have a data mapper, use old view data and merge
|
||||
// data from the children into it later
|
||||
if ($this->config->getDataMapper()) {
|
||||
$clientData = $this->getClientData();
|
||||
$viewData = $this->getViewData();
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $clientData || '' === $clientData) {
|
||||
if (null === $viewData || '' === $viewData) {
|
||||
$emptyData = $this->config->getEmptyData();
|
||||
|
||||
if ($emptyData instanceof \Closure) {
|
||||
$emptyData = $emptyData($this, $clientData);
|
||||
/* @var \Closure $emptyData */
|
||||
$emptyData = $emptyData($this, $viewData);
|
||||
}
|
||||
|
||||
$clientData = $emptyData;
|
||||
$viewData = $emptyData;
|
||||
}
|
||||
|
||||
// Merge form data from children into existing client data
|
||||
if (count($this->children) > 0 && $this->config->getDataMapper() && null !== $clientData) {
|
||||
$this->config->getDataMapper()->mapFormsToData($this->children, $clientData);
|
||||
// Merge form data from children into existing view data
|
||||
if (count($this->children) > 0 && $this->config->getDataMapper() && null !== $viewData) {
|
||||
$this->config->getDataMapper()->mapFormsToData($this->children, $viewData);
|
||||
}
|
||||
|
||||
try {
|
||||
// Normalize data to unified representation
|
||||
$normData = $this->clientToNorm($clientData);
|
||||
$normData = $this->viewToNorm($viewData);
|
||||
$synchronized = true;
|
||||
} catch (TransformationFailedException $e) {
|
||||
}
|
||||
@ -525,18 +542,18 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
$normData = $event->getData();
|
||||
|
||||
// Synchronize representations - must not change the content!
|
||||
$appData = $this->normToApp($normData);
|
||||
$clientData = $this->normToClient($normData);
|
||||
$modelData = $this->normToModel($normData);
|
||||
$viewData = $this->normToView($normData);
|
||||
}
|
||||
|
||||
$this->bound = true;
|
||||
$this->appData = $appData;
|
||||
$this->modelData = $modelData;
|
||||
$this->normData = $normData;
|
||||
$this->clientData = $clientData;
|
||||
$this->viewData = $viewData;
|
||||
$this->extraData = $extraData;
|
||||
$this->synchronized = $synchronized;
|
||||
|
||||
$event = new DataEvent($this, $clientData);
|
||||
$event = new DataEvent($this, $viewData);
|
||||
$this->config->getEventDispatcher()->dispatch(FormEvents::POST_BIND, $event);
|
||||
|
||||
foreach ($this->config->getValidators() as $validator) {
|
||||
@ -673,7 +690,7 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
}
|
||||
}
|
||||
|
||||
return array() === $this->appData || null === $this->appData || '' === $this->appData;
|
||||
return array() === $this->modelData || null === $this->modelData || '' === $this->modelData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -761,11 +778,11 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
* @return array An array of DataTransformerInterface
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link getConfig()} and {@link FormConfigInterface::getNormTransformers()} instead.
|
||||
* {@link getConfig()} and {@link FormConfigInterface::getModelTransformers()} instead.
|
||||
*/
|
||||
public function getNormTransformers()
|
||||
{
|
||||
return $this->config->getNormTransformers();
|
||||
return $this->config->getModelTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -774,11 +791,11 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
* @return array An array of DataTransformerInterface
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link getConfig()} and {@link FormConfigInterface::getClientTransformers()} instead.
|
||||
* {@link getConfig()} and {@link FormConfigInterface::getViewTransformers()} instead.
|
||||
*/
|
||||
public function getClientTransformers()
|
||||
{
|
||||
return $this->config->getClientTransformers();
|
||||
return $this->config->getViewTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -815,7 +832,7 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
$child->setParent($this);
|
||||
|
||||
if ($this->config->getDataMapper()) {
|
||||
$this->config->getDataMapper()->mapDataToForms($this->getClientData(), array($child));
|
||||
$this->config->getDataMapper()->mapDataToForms($this->getViewData(), array($child));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -974,9 +991,9 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function appToNorm($value)
|
||||
private function modelToNorm($value)
|
||||
{
|
||||
foreach ($this->config->getNormTransformers() as $transformer) {
|
||||
foreach ($this->config->getModelTransformers() as $transformer) {
|
||||
$value = $transformer->transform($value);
|
||||
}
|
||||
|
||||
@ -990,9 +1007,9 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function normToApp($value)
|
||||
private function normToModel($value)
|
||||
{
|
||||
$transformers = $this->config->getNormTransformers();
|
||||
$transformers = $this->config->getModelTransformers();
|
||||
|
||||
for ($i = count($transformers) - 1; $i >= 0; --$i) {
|
||||
$value = $transformers[$i]->reverseTransform($value);
|
||||
@ -1008,15 +1025,15 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function normToClient($value)
|
||||
private function normToView($value)
|
||||
{
|
||||
if (!$this->config->getClientTransformers()) {
|
||||
if (!$this->config->getViewTransformers()) {
|
||||
// Scalar values should always be converted to strings to
|
||||
// facilitate differentiation between empty ("") and zero (0).
|
||||
return null === $value || is_scalar($value) ? (string) $value : $value;
|
||||
}
|
||||
|
||||
foreach ($this->config->getClientTransformers() as $transformer) {
|
||||
foreach ($this->config->getViewTransformers() as $transformer) {
|
||||
$value = $transformer->transform($value);
|
||||
}
|
||||
|
||||
@ -1030,9 +1047,9 @@ class Form implements \IteratorAggregate, FormInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function clientToNorm($value)
|
||||
private function viewToNorm($value)
|
||||
{
|
||||
$transformers = $this->config->getClientTransformers();
|
||||
$transformers = $this->config->getViewTransformers();
|
||||
|
||||
if (!$transformers) {
|
||||
return '' === $value ? null : $value;
|
||||
|
@ -61,12 +61,12 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $clientTransformers = array();
|
||||
private $viewTransformers = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $normTransformers = array();
|
||||
private $modelTransformers = array();
|
||||
|
||||
/**
|
||||
* @var DataMapperInterface
|
||||
@ -178,9 +178,9 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function appendClientTransformer(DataTransformerInterface $clientTransformer)
|
||||
public function addViewTransformer(DataTransformerInterface $viewTransformer)
|
||||
{
|
||||
$this->clientTransformers[] = $clientTransformer;
|
||||
$this->viewTransformers[] = $viewTransformer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -188,19 +188,63 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prependClientTransformer(DataTransformerInterface $clientTransformer)
|
||||
public function resetViewTransformers()
|
||||
{
|
||||
array_unshift($this->clientTransformers, $clientTransformer);
|
||||
$this->viewTransformers = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Alias of {@link addViewTransformer()}.
|
||||
*
|
||||
* @param DataTransformerInterface $viewTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link addViewTransformer()} instead.
|
||||
*/
|
||||
public function appendClientTransformer(DataTransformerInterface $viewTransformer)
|
||||
{
|
||||
return $this->addViewTransformer($viewTransformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the client transformer chain.
|
||||
*
|
||||
* @param DataTransformerInterface $viewTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
*/
|
||||
public function prependClientTransformer(DataTransformerInterface $viewTransformer)
|
||||
{
|
||||
array_unshift($this->viewTransformers, $viewTransformer);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link resetViewTransformers()}.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link resetViewTransformers()} instead.
|
||||
*/
|
||||
public function resetClientTransformers()
|
||||
{
|
||||
$this->clientTransformers = array();
|
||||
return $this->resetViewTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addModelTransformer(DataTransformerInterface $modelTransformer)
|
||||
{
|
||||
array_unshift($this->modelTransformers, $modelTransformer);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -208,31 +252,55 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function appendNormTransformer(DataTransformerInterface $normTransformer)
|
||||
public function resetModelTransformers()
|
||||
{
|
||||
$this->normTransformers[] = $normTransformer;
|
||||
$this->modelTransformers = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Appends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $modelTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
|
||||
*/
|
||||
public function prependNormTransformer(DataTransformerInterface $normTransformer)
|
||||
public function appendNormTransformer(DataTransformerInterface $modelTransformer)
|
||||
{
|
||||
array_unshift($this->normTransformers, $normTransformer);
|
||||
$this->modelTransformers[] = $modelTransformer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Alias of {@link addModelTransformer()}.
|
||||
*
|
||||
* @param DataTransformerInterface $modelTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link addModelTransformer()} instead.
|
||||
*/
|
||||
public function prependNormTransformer(DataTransformerInterface $modelTransformer)
|
||||
{
|
||||
return $this->addModelTransformer($modelTransformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link resetModelTransformers()}.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link resetModelTransformers()} instead.
|
||||
*/
|
||||
public function resetNormTransformers()
|
||||
{
|
||||
$this->normTransformers = array();
|
||||
|
||||
return $this;
|
||||
return $this->resetModelTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,17 +362,43 @@ class FormConfig implements FormConfigEditorInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewTransformers()
|
||||
{
|
||||
return $this->viewTransformers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link getViewTransformers()}.
|
||||
*
|
||||
* @return array The view transformers.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link getViewTransformers()} instead.
|
||||
*/
|
||||
public function getClientTransformers()
|
||||
{
|
||||
return $this->clientTransformers;
|
||||
return $this->getViewTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getModelTransformers()
|
||||
{
|
||||
return $this->modelTransformers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of {@link getModelTransformers()}.
|
||||
*
|
||||
* @return array The model transformers.
|
||||
*
|
||||
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
|
||||
* {@link getModelTransformers()} instead.
|
||||
*/
|
||||
public function getNormTransformers()
|
||||
{
|
||||
return $this->normTransformers;
|
||||
return $this->getModelTransformers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,52 +54,34 @@ interface FormConfigEditorInterface extends FormConfigInterface
|
||||
/**
|
||||
* Appends a transformer to the client transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $clientTransformer
|
||||
* @param DataTransformerInterface $viewTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function appendClientTransformer(DataTransformerInterface $clientTransformer);
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the client transformer chain.
|
||||
*
|
||||
* @param DataTransformerInterface $clientTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function prependClientTransformer(DataTransformerInterface $clientTransformer);
|
||||
function addViewTransformer(DataTransformerInterface $viewTransformer);
|
||||
|
||||
/**
|
||||
* Clears the client transformers.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function resetClientTransformers();
|
||||
|
||||
/**
|
||||
* Appends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $normTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function appendNormTransformer(DataTransformerInterface $normTransformer);
|
||||
function resetViewTransformers();
|
||||
|
||||
/**
|
||||
* Prepends a transformer to the normalization transformer chain
|
||||
*
|
||||
* @param DataTransformerInterface $normTransformer
|
||||
* @param DataTransformerInterface $modelTransformer
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function prependNormTransformer(DataTransformerInterface $normTransformer);
|
||||
function addModelTransformer(DataTransformerInterface $modelTransformer);
|
||||
|
||||
/**
|
||||
* Clears the normalization transformers.
|
||||
*
|
||||
* @return self The configuration object.
|
||||
*/
|
||||
function resetNormTransformers();
|
||||
function resetModelTransformers();
|
||||
|
||||
/**
|
||||
* Sets the value for an attribute.
|
||||
|
@ -77,14 +77,14 @@ interface FormConfigInterface
|
||||
*
|
||||
* @return array An array of {@link DataTransformerInterface} instances.
|
||||
*/
|
||||
function getClientTransformers();
|
||||
function getViewTransformers();
|
||||
|
||||
/**
|
||||
* Returns the view transformers of the form.
|
||||
*
|
||||
* @return array An array of {@link DataTransformerInterface} instances.
|
||||
*/
|
||||
function getNormTransformers();
|
||||
function getModelTransformers();
|
||||
|
||||
/**
|
||||
* Returns the data mapper of the form.
|
||||
|
@ -101,11 +101,11 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
|
||||
/**
|
||||
* Updates the field with default data.
|
||||
*
|
||||
* @param array $appData The data formatted as expected for the underlying object
|
||||
* @param array $modelData The data formatted as expected for the underlying object
|
||||
*
|
||||
* @return FormInterface The form instance
|
||||
*/
|
||||
function setData($appData);
|
||||
function setData($modelData);
|
||||
|
||||
/**
|
||||
* Returns the data in the format needed for the underlying object.
|
||||
@ -128,7 +128,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getClientData();
|
||||
function getViewData();
|
||||
|
||||
/**
|
||||
* Returns the extra data.
|
||||
|
@ -122,7 +122,7 @@ class CheckboxTypeTest extends TypeTestCase
|
||||
|
||||
$form = $this->builder
|
||||
->create('expedited_shipping', 'checkbox')
|
||||
->prependNormTransformer($transformer)
|
||||
->addModelTransformer($transformer)
|
||||
->getForm();
|
||||
$form->setData($data);
|
||||
$view = $form->createView();
|
||||
|
@ -185,7 +185,7 @@ class FormValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$form = $this->getBuilder('name', '\stdClass', array('invalid_message' => 'Invalid!'))
|
||||
->setData($object)
|
||||
->appendClientTransformer(new CallbackTransformer(
|
||||
->addViewTransformer(new CallbackTransformer(
|
||||
function ($data) { return $data; },
|
||||
function () { throw new TransformationFailedException(); }
|
||||
))
|
||||
@ -218,7 +218,7 @@ class FormValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
$form = $this->getBuilder('name', '\stdClass', $options)
|
||||
->setData($object)
|
||||
->appendClientTransformer(new CallbackTransformer(
|
||||
->addViewTransformer(new CallbackTransformer(
|
||||
function ($data) { return $data; },
|
||||
function () { throw new TransformationFailedException(); }
|
||||
))
|
||||
|
@ -75,7 +75,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase
|
||||
$config->setAttribute('error_mapping', $errorMapping);
|
||||
|
||||
if (!$synchronized) {
|
||||
$config->appendClientTransformer(new CallbackTransformer(
|
||||
$config->addViewTransformer(new CallbackTransformer(
|
||||
function ($normData) { return $normData; },
|
||||
function () { throw new TransformationFailedException(); }
|
||||
));
|
||||
|
@ -63,13 +63,13 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
));
|
||||
|
||||
$config = new FormConfig('name', null, $this->dispatcher);
|
||||
$config->appendClientTransformer($client);
|
||||
$config->addViewTransformer($client);
|
||||
$config->appendNormTransformer($norm);
|
||||
$form = new Form($config);
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertSame('foo', $form->getNormData());
|
||||
$this->assertSame('bar', $form->getClientData());
|
||||
$this->assertSame('bar', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testValidIfAllChildrenAreValid()
|
||||
@ -496,7 +496,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
'' => '',
|
||||
'filtered' => 'norm',
|
||||
)))
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'norm' => 'client',
|
||||
)))
|
||||
@ -512,11 +512,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetDataExecutesClientTransformersInOrder()
|
||||
{
|
||||
$form = $this->getBuilder()
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'first' => 'second',
|
||||
)))
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'second' => 'third',
|
||||
)))
|
||||
@ -557,7 +557,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertSame('1', $form->getData());
|
||||
$this->assertSame('1', $form->getNormData());
|
||||
$this->assertSame('1', $form->getClientData());
|
||||
$this->assertSame('1', $form->getViewData());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -592,7 +592,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('', $form->getClientData());
|
||||
$this->assertSame('', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testBindConvertsEmptyToNullIfNoTransformer()
|
||||
@ -603,7 +603,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertNull($form->getData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertSame('', $form->getClientData());
|
||||
$this->assertSame('', $form->getViewData());
|
||||
}
|
||||
|
||||
public function testBindExecutesTransformationChain()
|
||||
@ -618,7 +618,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
'norm' => 'filterednorm',
|
||||
),
|
||||
)))
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
// direction is reversed!
|
||||
'norm' => 'filteredclient',
|
||||
@ -641,11 +641,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
public function testBindExecutesClientTransformersInReverseOrder()
|
||||
{
|
||||
$form = $this->getBuilder()
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'third' => 'second',
|
||||
)))
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'second' => 'first',
|
||||
)))
|
||||
@ -694,7 +694,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
->will($this->throwException(new TransformationFailedException()));
|
||||
|
||||
$form = $this->getBuilder()
|
||||
->appendClientTransformer($transformer)
|
||||
->addViewTransformer($transformer)
|
||||
->getForm();
|
||||
|
||||
$form->bind('foobar');
|
||||
@ -706,7 +706,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$form = $this->getBuilder()
|
||||
->setEmptyData('foo')
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
// direction is reversed!
|
||||
'bar' => 'foo',
|
||||
@ -729,7 +729,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
return 'foo';
|
||||
})
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
// direction is reversed!
|
||||
'bar' => 'foo',
|
||||
@ -746,7 +746,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$mapper = $this->getDataMapper();
|
||||
$form = $this->getBuilder()
|
||||
->setDataMapper($mapper)
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'foo' => 'bar',
|
||||
)))
|
||||
@ -766,7 +766,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$mapper = $this->getDataMapper();
|
||||
$form = $this->getBuilder()
|
||||
->setDataMapper($mapper)
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'foo' => 'bar',
|
||||
)))
|
||||
@ -788,7 +788,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
$mapper = $this->getDataMapper();
|
||||
$form = $this->getBuilder()
|
||||
->setDataMapper($mapper)
|
||||
->appendClientTransformer(new FixedDataTransformer(array(
|
||||
->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'foo' => 'bar',
|
||||
)))
|
||||
@ -1259,7 +1259,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
public function testClientDataMustNotBeObjectIfDataClassIsNull()
|
||||
{
|
||||
$config = new FormConfig('name', null, $this->dispatcher);
|
||||
$config->appendClientTransformer(new FixedDataTransformer(array(
|
||||
$config->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'foo' => new \stdClass(),
|
||||
)));
|
||||
@ -1272,7 +1272,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$arrayAccess = $this->getMock('\ArrayAccess');
|
||||
$config = new FormConfig('name', null, $this->dispatcher);
|
||||
$config->appendClientTransformer(new FixedDataTransformer(array(
|
||||
$config->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'foo' => $arrayAccess,
|
||||
)));
|
||||
@ -1280,7 +1280,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$form->setData('foo');
|
||||
|
||||
$this->assertSame($arrayAccess, $form->getClientData());
|
||||
$this->assertSame($arrayAccess, $form->getViewData());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1289,7 +1289,7 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
||||
public function testClientDataMustBeObjectIfDataClassIsSet()
|
||||
{
|
||||
$config = new FormConfig('name', 'stdClass', $this->dispatcher);
|
||||
$config->appendClientTransformer(new FixedDataTransformer(array(
|
||||
$config->addViewTransformer(new FixedDataTransformer(array(
|
||||
'' => '',
|
||||
'foo' => array('bar' => 'baz'),
|
||||
)));
|
||||
|
@ -136,8 +136,8 @@ class UnmodifiableFormConfig implements FormConfigInterface
|
||||
$this->byReference = $config->getByReference();
|
||||
$this->virtual = $config->getVirtual();
|
||||
$this->types = $config->getTypes();
|
||||
$this->clientTransformers = $config->getClientTransformers();
|
||||
$this->normTransformers = $config->getNormTransformers();
|
||||
$this->clientTransformers = $config->getViewTransformers();
|
||||
$this->normTransformers = $config->getModelTransformers();
|
||||
$this->dataMapper = $config->getDataMapper();
|
||||
$this->validators = $config->getValidators();
|
||||
$this->required = $config->getRequired();
|
||||
@ -209,7 +209,7 @@ class UnmodifiableFormConfig implements FormConfigInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClientTransformers()
|
||||
public function getViewTransformers()
|
||||
{
|
||||
return $this->clientTransformers;
|
||||
}
|
||||
@ -217,7 +217,7 @@ class UnmodifiableFormConfig implements FormConfigInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNormTransformers()
|
||||
public function getModelTransformers()
|
||||
{
|
||||
return $this->normTransformers;
|
||||
}
|
||||
|
Reference in New Issue
Block a user