Skip to content

Commit

Permalink
Container::getControls() returns list instead of iterator with names …
Browse files Browse the repository at this point in the history
…(BC break)
  • Loading branch information
dg committed Feb 25, 2024
1 parent 874d838 commit 7ff4126
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/Forms/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,12 @@ public function addComponent(


/**
* Iterates over all form controls.
* Retrieves the entire hierarchy of form controls including nested.
* @return list<Control>
*/
public function getControls(): \Iterator
public function getControls(): array
{
return $this->getComponents(true, Control::class);
return array_values(array_filter($this->getComponentTree(), fn($c) => $c instanceof Control));
}


Expand Down
20 changes: 1 addition & 19 deletions tests/Forms/Container.getControls().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,4 @@ $form->addContainer('cont')
->addText('name');

$controls = $form->getControls();

$names = $values = [];
foreach ($controls as $name => $value) {
$names[] = $name;
$values[] = $value;
}

Assert::same(['name', 'age', 'name'], $names);
Assert::same([$form['name'], $form['age'], $form['cont-name']], $values);

// again
$names = $values = [];
foreach ($controls as $name => $value) {
$names[] = $name;
$values[] = $value;
}

Assert::same(['name', 'age', 'name'], $names);
Assert::same([$form['name'], $form['age'], $form['cont-name']], $values);
Assert::same([$form['name'], $form['age'], $form['cont-name']], $controls);

0 comments on commit 7ff4126

Please sign in to comment.