Skip to content

Commit 37d823d

Browse files
committed
feature #39317 [Form] Changed DataMapperInterface $forms parameter type to \Traversable (vudaltsov)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Form] Changed DataMapperInterface $forms parameter type to \Traversable | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | Fix #39311 | License | MIT | Doc PR | no Didn't touch `PropertyPathMapper` because it's deprecated anyway. Commits ------- ce77be2 [Form] Changed DataMapperInterface $forms parameter type to \Traversable
2 parents 1bf4341 + ce77be2 commit 37d823d

File tree

8 files changed

+82
-26
lines changed

8 files changed

+82
-26
lines changed

UPGRADE-5.3.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
UPGRADE FROM 5.2 to 5.3
2+
=======================
3+
4+
Form
5+
----
6+
7+
* Changed `$forms` parameter type of the `DataMapperInterface::mapDataToForms()` method from `iterable` to `\Traversable`.
8+
* Changed `$forms` parameter type of the `DataMapperInterface::mapFormsToData()` method from `iterable` to `\Traversable`.
9+
* Deprecated passing an array as the second argument of the `DataMapper::mapDataToForms()` method, pass `\Traversable` instead.
10+
* Deprecated passing an array as the first argument of the `DataMapper::mapFormsToData()` method, pass `\Traversable` instead.
11+
* Deprecated passing an array as the second argument of the `CheckboxListMapper::mapDataToForms()` method, pass `\Traversable` instead.
12+
* Deprecated passing an array as the first argument of the `CheckboxListMapper::mapFormsToData()` method, pass `\Traversable` instead.
13+
* Deprecated passing an array as the second argument of the `RadioListMapper::mapDataToForms()` method, pass `\Traversable` instead.
14+
* Deprecated passing an array as the first argument of the `RadioListMapper::mapFormsToData()` method, pass `\Traversable` instead.

UPGRADE-6.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ Form
4949
* The `Symfony\Component\Form\Extension\Validator\Util\ServerParams` class has been removed, use its parent `Symfony\Component\Form\Util\ServerParams` instead.
5050
* The `NumberToLocalizedStringTransformer::ROUND_*` constants have been removed, use `\NumberFormatter::ROUND_*` instead.
5151
* Removed `PropertyPathMapper` in favor of `DataMapper` and `PropertyPathAccessor`.
52+
* Changed `$forms` parameter type of the `DataMapper::mapDataToForms()` method from `iterable` to `\Traversable`.
53+
* Changed `$forms` parameter type of the `DataMapper::mapFormsToData()` method from `iterable` to `\Traversable`.
54+
* Changed `$checkboxes` parameter type of the `CheckboxListMapper::mapDataToForms()` method from `iterable` to `\Traversable`.
55+
* Changed `$checkboxes` parameter type of the `CheckboxListMapper::mapFormsToData()` method from `iterable` to `\Traversable`.
56+
* Changed `$radios` parameter type of the `RadioListMapper::mapDataToForms()` method from `iterable` to `\Traversable`.
57+
* Changed `$radios` parameter type of the `RadioListMapper::mapFormsToData()` method from `iterable` to `\Traversable`.
5258

5359
FrameworkBundle
5460
---------------

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* Changed `$forms` parameter type of the `DataMapperInterface::mapDataToForms()` method from `iterable` to `\Traversable`.
8+
* Changed `$forms` parameter type of the `DataMapperInterface::mapFormsToData()` method from `iterable` to `\Traversable`.
9+
* Deprecated passing an array as the second argument of the `DataMapper::mapDataToForms()` method, pass `\Traversable` instead.
10+
* Deprecated passing an array as the first argument of the `DataMapper::mapFormsToData()` method, pass `\Traversable` instead.
11+
* Deprecated passing an array as the second argument of the `CheckboxListMapper::mapDataToForms()` method, pass `\Traversable` instead.
12+
* Deprecated passing an array as the first argument of the `CheckboxListMapper::mapFormsToData()` method, pass `\Traversable` instead.
13+
* Deprecated passing an array as the second argument of the `RadioListMapper::mapDataToForms()` method, pass `\Traversable` instead.
14+
* Deprecated passing an array as the first argument of the `RadioListMapper::mapFormsToData()` method, pass `\Traversable` instead.
15+
416
5.2.0
517
-----
618

src/Symfony/Component/Form/DataMapperInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ interface DataMapperInterface
2222
* The method is responsible for calling {@link FormInterface::setData()}
2323
* on the children of compound forms, defining their underlying model data.
2424
*
25-
* @param mixed $viewData View data of the compound form being initialized
26-
* @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
25+
* @param mixed $viewData View data of the compound form being initialized
26+
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
2727
*
2828
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
2929
*/
30-
public function mapDataToForms($viewData, iterable $forms);
30+
public function mapDataToForms($viewData, \Traversable $forms);
3131

3232
/**
3333
* Maps the model data of a list of children forms into the view data of their parent.
@@ -52,11 +52,11 @@ public function mapDataToForms($viewData, iterable $forms);
5252
* The model data can be an array or an object, so this second argument is always passed
5353
* by reference.
5454
*
55-
* @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
56-
* @param mixed $viewData The compound form's view data that get mapped
57-
* its children model data
55+
* @param FormInterface[]|\Traversable $forms A list of {@link FormInterface} instances
56+
* @param mixed $viewData The compound form's view data that get mapped
57+
* its children model data
5858
*
5959
* @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
6060
*/
61-
public function mapFormsToData(iterable $forms, &$viewData);
61+
public function mapFormsToData(\Traversable $forms, &$viewData);
6262
}

src/Symfony/Component/Form/Extension/Core/DataMapper/CheckboxListMapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class CheckboxListMapper implements DataMapperInterface
3030
*/
3131
public function mapDataToForms($choices, iterable $checkboxes)
3232
{
33+
if (\is_array($checkboxes)) {
34+
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
35+
}
36+
3337
if (null === $choices) {
3438
$choices = [];
3539
}
@@ -49,6 +53,10 @@ public function mapDataToForms($choices, iterable $checkboxes)
4953
*/
5054
public function mapFormsToData(iterable $checkboxes, &$choices)
5155
{
56+
if (\is_array($checkboxes)) {
57+
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
58+
}
59+
5260
if (!\is_array($choices)) {
5361
throw new UnexpectedTypeException($choices, 'array');
5462
}

src/Symfony/Component/Form/Extension/Core/DataMapper/DataMapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function __construct(DataAccessorInterface $dataAccessor = null)
4040
*/
4141
public function mapDataToForms($data, iterable $forms): void
4242
{
43+
if (\is_array($forms)) {
44+
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
45+
}
46+
4347
$empty = null === $data || [] === $data;
4448

4549
if (!$empty && !\is_array($data) && !\is_object($data)) {
@@ -62,6 +66,10 @@ public function mapDataToForms($data, iterable $forms): void
6266
*/
6367
public function mapFormsToData(iterable $forms, &$data): void
6468
{
69+
if (\is_array($forms)) {
70+
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
71+
}
72+
6573
if (null === $data) {
6674
return;
6775
}

src/Symfony/Component/Form/Extension/Core/DataMapper/RadioListMapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class RadioListMapper implements DataMapperInterface
3030
*/
3131
public function mapDataToForms($choice, iterable $radios)
3232
{
33+
if (\is_array($radios)) {
34+
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
35+
}
36+
3337
if (!\is_string($choice)) {
3438
throw new UnexpectedTypeException($choice, 'string');
3539
}
@@ -45,6 +49,10 @@ public function mapDataToForms($choice, iterable $radios)
4549
*/
4650
public function mapFormsToData(iterable $radios, &$choice)
4751
{
52+
if (\is_array($radios)) {
53+
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
54+
}
55+
4856
if (null !== $choice && !\is_string($choice)) {
4957
throw new UnexpectedTypeException($choice, 'null or string');
5058
}

src/Symfony/Component/Form/Tests/Extension/Core/DataMapper/DataMapperTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testMapDataToFormsPassesObjectRefIfByReference()
5050
$config->setPropertyPath($propertyPath);
5151
$form = new Form($config);
5252

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

5555
self::assertSame($engine, $form->getData());
5656
}
@@ -68,7 +68,7 @@ public function testMapDataToFormsPassesObjectCloneIfNotByReference()
6868
$config->setPropertyPath($propertyPath);
6969
$form = new Form($config);
7070

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

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

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

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

8989
self::assertNull($form->getData());
9090
}
@@ -101,7 +101,7 @@ public function testMapDataToFormsIgnoresUnmapped()
101101
$config->setPropertyPath($propertyPath);
102102
$form = new Form($config);
103103

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

106106
self::assertNull($form->getData());
107107
}
@@ -117,7 +117,7 @@ public function testMapDataToFormsIgnoresUninitializedProperties()
117117
$car = new TypehintedPropertiesCar();
118118
$car->engine = 'BMW';
119119

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

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

136136
$form = new Form($config);
137137

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

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

153153
$form = new Form($config);
154154

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

157157
self::assertSame($default, $form->getData());
158158
}
@@ -171,7 +171,7 @@ public function testMapFormsToDataWritesBackIfNotByReference()
171171
$config->setData($engine);
172172
$form = new SubmittedForm($config);
173173

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

176176
self::assertEquals($engine, $car->engine);
177177
self::assertNotSame($engine, $car->engine);
@@ -190,7 +190,7 @@ public function testMapFormsToDataWritesBackIfByReferenceButNoReference()
190190
$config->setData($engine);
191191
$form = new SubmittedForm($config);
192192

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

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

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

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

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

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

234234
self::assertSame($initialEngine, $car->engine);
235235
}
@@ -248,7 +248,7 @@ public function testMapFormsToDataIgnoresUnsubmittedForms()
248248
$config->setData($engine);
249249
$form = new Form($config);
250250

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

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

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

271271
self::assertSame($initialEngine, $car->engine);
272272
}
@@ -285,7 +285,7 @@ public function testMapFormsToDataIgnoresUnsynchronized()
285285
$config->setData($engine);
286286
$form = new NotSynchronizedForm($config);
287287

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy