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