Skip to content

[Form] Changed DataMapperInterface $forms parameter type to \Traversable #39317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions UPGRADE-5.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
UPGRADE FROM 5.2 to 5.3
=======================

Form
----

* Changed `$forms` parameter type of the `DataMapperInterface::mapDataToForms()` method from `iterable` to `\Traversable`.
* Changed `$forms` parameter type of the `DataMapperInterface::mapFormsToData()` method from `iterable` to `\Traversable`.
* Deprecated passing an array as the second argument of the `DataMapper::mapDataToForms()` method, pass `\Traversable` instead.
* Deprecated passing an array as the first argument of the `DataMapper::mapFormsToData()` method, pass `\Traversable` instead.
* Deprecated passing an array as the second argument of the `CheckboxListMapper::mapDataToForms()` method, pass `\Traversable` instead.
* Deprecated passing an array as the first argument of the `CheckboxListMapper::mapFormsToData()` method, pass `\Traversable` instead.
* Deprecated passing an array as the second argument of the `RadioListMapper::mapDataToForms()` method, pass `\Traversable` instead.
* Deprecated passing an array as the first argument of the `RadioListMapper::mapFormsToData()` method, pass `\Traversable` instead.
6 changes: 6 additions & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Form
* The `Symfony\Component\Form\Extension\Validator\Util\ServerParams` class has been removed, use its parent `Symfony\Component\Form\Util\ServerParams` instead.
* The `NumberToLocalizedStringTransformer::ROUND_*` constants have been removed, use `\NumberFormatter::ROUND_*` instead.
* Removed `PropertyPathMapper` in favor of `DataMapper` and `PropertyPathAccessor`.
* Changed `$forms` parameter type of the `DataMapper::mapDataToForms()` method from `iterable` to `\Traversable`.
* Changed `$forms` parameter type of the `DataMapper::mapFormsToData()` method from `iterable` to `\Traversable`.
* Changed `$checkboxes` parameter type of the `CheckboxListMapper::mapDataToForms()` method from `iterable` to `\Traversable`.
* Changed `$checkboxes` parameter type of the `CheckboxListMapper::mapFormsToData()` method from `iterable` to `\Traversable`.
* Changed `$radios` parameter type of the `RadioListMapper::mapDataToForms()` method from `iterable` to `\Traversable`.
* Changed `$radios` parameter type of the `RadioListMapper::mapFormsToData()` method from `iterable` to `\Traversable`.

FrameworkBundle
---------------
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
CHANGELOG
=========

5.3.0
-----

* Changed `$forms` parameter type of the `DataMapperInterface::mapDataToForms()` method from `iterable` to `\Traversable`.
* Changed `$forms` parameter type of the `DataMapperInterface::mapFormsToData()` method from `iterable` to `\Traversable`.
* Deprecated passing an array as the second argument of the `DataMapper::mapDataToForms()` method, pass `\Traversable` instead.
* Deprecated passing an array as the first argument of the `DataMapper::mapFormsToData()` method, pass `\Traversable` instead.
* Deprecated passing an array as the second argument of the `CheckboxListMapper::mapDataToForms()` method, pass `\Traversable` instead.
* Deprecated passing an array as the first argument of the `CheckboxListMapper::mapFormsToData()` method, pass `\Traversable` instead.
* Deprecated passing an array as the second argument of the `RadioListMapper::mapDataToForms()` method, pass `\Traversable` instead.
* Deprecated passing an array as the first argument of the `RadioListMapper::mapFormsToData()` method, pass `\Traversable` instead.

5.2.0
-----

Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/Form/DataMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ interface DataMapperInterface
* The method is responsible for calling {@link FormInterface::setData()}
* on the children of compound forms, defining their underlying model data.
*
* @param mixed $viewData View data of the compound form being initialized
* @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
* @param mixed $viewData View data of the compound form being initialized
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
*/
public function mapDataToForms($viewData, iterable $forms);
public function mapDataToForms($viewData, \Traversable $forms);

/**
* Maps the model data of a list of children forms into the view data of their parent.
Expand All @@ -52,11 +52,11 @@ public function mapDataToForms($viewData, iterable $forms);
* The model data can be an array or an object, so this second argument is always passed
* by reference.
*
* @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
* @param mixed $viewData The compound form's view data that get mapped
* its children model data
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
* @param mixed $viewData The compound form's view data that get mapped
* its children model data
*
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
*/
public function mapFormsToData(iterable $forms, &$viewData);
public function mapFormsToData(\Traversable $forms, &$viewData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class CheckboxListMapper implements DataMapperInterface
*/
public function mapDataToForms($choices, iterable $checkboxes)
{
if (\is_array($checkboxes)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (null === $choices) {
$choices = [];
}
Expand All @@ -49,6 +53,10 @@ public function mapDataToForms($choices, iterable $checkboxes)
*/
public function mapFormsToData(iterable $checkboxes, &$choices)
{
if (\is_array($checkboxes)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (!\is_array($choices)) {
throw new UnexpectedTypeException($choices, 'array');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function __construct(DataAccessorInterface $dataAccessor = null)
*/
public function mapDataToForms($data, iterable $forms): void
{
if (\is_array($forms)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

$empty = null === $data || [] === $data;

if (!$empty && !\is_array($data) && !\is_object($data)) {
Expand All @@ -62,6 +66,10 @@ public function mapDataToForms($data, iterable $forms): void
*/
public function mapFormsToData(iterable $forms, &$data): void
{
if (\is_array($forms)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (null === $data) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class RadioListMapper implements DataMapperInterface
*/
public function mapDataToForms($choice, iterable $radios)
{
if (\is_array($radios)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (!\is_string($choice)) {
throw new UnexpectedTypeException($choice, 'string');
}
Expand All @@ -45,6 +49,10 @@ public function mapDataToForms($choice, iterable $radios)
*/
public function mapFormsToData(iterable $radios, &$choice)
{
if (\is_array($radios)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (null !== $choice && !\is_string($choice)) {
throw new UnexpectedTypeException($choice, 'null or string');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testMapDataToFormsPassesObjectRefIfByReference()
$config->setPropertyPath($propertyPath);
$form = new Form($config);

$this->mapper->mapDataToForms($car, [$form]);
$this->mapper->mapDataToForms($car, new \ArrayIterator([$form]));

self::assertSame($engine, $form->getData());
}
Expand All @@ -68,7 +68,7 @@ public function testMapDataToFormsPassesObjectCloneIfNotByReference()
$config->setPropertyPath($propertyPath);
$form = new Form($config);

$this->mapper->mapDataToForms($car, [$form]);
$this->mapper->mapDataToForms($car, new \ArrayIterator([$form]));

self::assertNotSame($engine, $form->getData());
self::assertEquals($engine, $form->getData());
Expand All @@ -84,7 +84,7 @@ public function testMapDataToFormsIgnoresEmptyPropertyPath()

self::assertNull($form->getPropertyPath());

$this->mapper->mapDataToForms($car, [$form]);
$this->mapper->mapDataToForms($car, new \ArrayIterator([$form]));

self::assertNull($form->getData());
}
Expand All @@ -101,7 +101,7 @@ public function testMapDataToFormsIgnoresUnmapped()
$config->setPropertyPath($propertyPath);
$form = new Form($config);

$this->mapper->mapDataToForms($car, [$form]);
$this->mapper->mapDataToForms($car, new \ArrayIterator([$form]));

self::assertNull($form->getData());
}
Expand All @@ -117,7 +117,7 @@ public function testMapDataToFormsIgnoresUninitializedProperties()
$car = new TypehintedPropertiesCar();
$car->engine = 'BMW';

$this->mapper->mapDataToForms($car, [$engineForm, $colorForm]);
$this->mapper->mapDataToForms($car, new \ArrayIterator([$engineForm, $colorForm]));

self::assertSame($car->engine, $engineForm->getData());
self::assertNull($colorForm->getData());
Expand All @@ -135,7 +135,7 @@ public function testMapDataToFormsSetsDefaultDataIfPassedDataIsNull()

$form = new Form($config);

$this->mapper->mapDataToForms(null, [$form]);
$this->mapper->mapDataToForms(null, new \ArrayIterator([$form]));

self::assertSame($default, $form->getData());
}
Expand All @@ -152,7 +152,7 @@ public function testMapDataToFormsSetsDefaultDataIfPassedDataIsEmptyArray()

$form = new Form($config);

$this->mapper->mapDataToForms([], [$form]);
$this->mapper->mapDataToForms([], new \ArrayIterator([$form]));

self::assertSame($default, $form->getData());
}
Expand All @@ -171,7 +171,7 @@ public function testMapFormsToDataWritesBackIfNotByReference()
$config->setData($engine);
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertEquals($engine, $car->engine);
self::assertNotSame($engine, $car->engine);
Expand All @@ -190,7 +190,7 @@ public function testMapFormsToDataWritesBackIfByReferenceButNoReference()
$config->setData($engine);
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame($engine, $car->engine);
}
Expand All @@ -209,7 +209,7 @@ public function testMapFormsToDataWritesBackIfByReferenceAndReference()

$car->engine = 'Rolls-Royce';

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame('Rolls-Royce', $car->engine);
}
Expand All @@ -229,7 +229,7 @@ public function testMapFormsToDataIgnoresUnmapped()
$config->setMapped(false);
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame($initialEngine, $car->engine);
}
Expand All @@ -248,7 +248,7 @@ public function testMapFormsToDataIgnoresUnsubmittedForms()
$config->setData($engine);
$form = new Form($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame($initialEngine, $car->engine);
}
Expand All @@ -266,7 +266,7 @@ public function testMapFormsToDataIgnoresEmptyData()
$config->setData(null);
$form = new Form($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame($initialEngine, $car->engine);
}
Expand All @@ -285,7 +285,7 @@ public function testMapFormsToDataIgnoresUnsynchronized()
$config->setData($engine);
$form = new NotSynchronizedForm($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame($initialEngine, $car->engine);
}
Expand All @@ -305,7 +305,7 @@ public function testMapFormsToDataIgnoresDisabled()
$config->setDisabled(true);
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame($initialEngine, $car->engine);
}
Expand All @@ -320,7 +320,7 @@ public function testMapFormsToUninitializedProperties()
$config->setData('BMW');
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $car);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $car);

self::assertSame('BMW', $car->engine);
}
Expand All @@ -342,7 +342,7 @@ public function testMapFormsToDataDoesNotChangeEqualDateTimeInstance($date)
$config->setData($publishedAt);
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $article);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $article);

self::assertSame($publishedAtValue, $article['publishedAt']);
}
Expand All @@ -367,7 +367,7 @@ public function testMapDataToFormsUsingGetCallbackOption()
]);
$form = new Form($config);

$this->mapper->mapDataToForms($person, [$form]);
$this->mapper->mapDataToForms($person, new \ArrayIterator([$form]));

self::assertSame($initialName, $form->getData());
}
Expand All @@ -384,7 +384,7 @@ public function testMapFormsToDataUsingSetCallbackOption()
$config->setData('Jane Doe');
$form = new SubmittedForm($config);

$this->mapper->mapFormsToData([$form], $person);
$this->mapper->mapFormsToData(new \ArrayIterator([$form]), $person);

self::assertSame('Jane Doe', $person->myName());
}
Expand Down