diff --git a/src/Forms/ControlGroup.php b/src/Forms/ControlGroup.php index 174bb960..b7949cc3 100644 --- a/src/Forms/ControlGroup.php +++ b/src/Forms/ControlGroup.php @@ -17,13 +17,13 @@ */ final class ControlGroup { - protected \SplObjectStorage $controls; + protected \WeakMap $controls; private array $options = []; public function __construct() { - $this->controls = new \SplObjectStorage; + $this->controls = new \WeakMap; } @@ -31,7 +31,7 @@ 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; }