Skip to content

Commit f96d357

Browse files
committed
Container::getControls() returns list instead of iterator with names (BC break)
1 parent b4c5970 commit f96d357

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

src/Forms/Container.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,12 @@ public function addComponent(
301301

302302

303303
/**
304-
* Iterates over all form controls.
304+
* Retrieves the entire hierarchy of form controls including nested.
305+
* @return list<Control>
305306
*/
306-
public function getControls(): \Iterator
307+
public function getControls(): array
307308
{
308-
return $this->getComponents(true, Control::class);
309+
return array_values(array_filter($this->getComponentTree(), fn($c) => $c instanceof Control));
309310
}
310311

311312

tests/Forms/Container.getControls().phpt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,4 @@ $form->addContainer('cont')
1515
->addText('name');
1616

1717
$controls = $form->getControls();
18-
19-
$names = $values = [];
20-
foreach ($controls as $name => $value) {
21-
$names[] = $name;
22-
$values[] = $value;
23-
}
24-
25-
Assert::same(['name', 'age', 'name'], $names);
26-
Assert::same([$form['name'], $form['age'], $form['cont-name']], $values);
27-
28-
// again
29-
$names = $values = [];
30-
foreach ($controls as $name => $value) {
31-
$names[] = $name;
32-
$values[] = $value;
33-
}
34-
35-
Assert::same(['name', 'age', 'name'], $names);
36-
Assert::same([$form['name'], $form['age'], $form['cont-name']], $values);
18+
Assert::same([$form['name'], $form['age'], $form['cont-name']], $controls);

0 commit comments

Comments
 (0)