Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ControlGroup uses WeakMap
Browse files Browse the repository at this point in the history
dg committed Jan 30, 2024
1 parent c68c230 commit 9d2b0f0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Forms/ControlGroup.php
Original file line number Diff line number Diff line change
@@ -17,21 +17,21 @@
*/
final class ControlGroup
{
protected \SplObjectStorage $controls;
protected \WeakMap $controls;
private array $options = [];


public function __construct()
{
$this->controls = new \SplObjectStorage;
$this->controls = new \WeakMap;
}


public function add(...$items): static
{
foreach ($items as $item) {
if ($item instanceof Control) {
$this->controls->attach($item);
$this->controls[$item] = null;

} elseif ($item instanceof Container) {
foreach ($item->getComponents() as $component) {
@@ -52,15 +52,15 @@ public function add(...$items): static

public function remove(Control $control): void
{
$this->controls->detach($control);
unset($this->controls[$control]);
}


public function removeOrphans(): void
{
foreach ($this->controls as $control) {
foreach ($this->controls as $control => $foo) {
if (!$control->getForm(false)) {
$this->controls->detach($control);
unset($this->controls[$control]);
}
}
}
@@ -69,7 +69,11 @@ public function removeOrphans(): void
/** @return Control[] */
public function getControls(): array
{
return iterator_to_array($this->controls);
$res = [];
foreach ($this->controls as $control => $foo) {
$res[] = $control;
}
return $res;
}


0 comments on commit 9d2b0f0

Please sign in to comment.