storage = new \SplDoublyLinkedList(); } /** * Utility method to transform an arbitrary array to a proper SelectItem collection * * @param array $itemList List of SelectItem elements or legacy item arrays * @param string $type The field type, e.g. "select" */ public static function createFromArray(array $itemList, string $type): self { $collection = new self(); foreach ($itemList as $item) { if ($item instanceof SelectItem) { $collection->add($item); continue; } if (is_array($item)) { $collection->add( SelectItem::fromTcaItemArray($item, $type) ); continue; } throw new \InvalidArgumentException( 'Values of $itemList must be of type ' . SelectItem::class . ' or array.', 1762417317 ); } return $collection; } public function current(): SelectItem { return $this->storage->current(); } public function next(): void { $this->storage->next(); } public function key(): int { return $this->storage->key(); } public function valid(): bool { return $this->storage->valid(); } public function rewind(): void { $this->storage->rewind(); } public function count(): int { return $this->storage->count(); } /** * @param mixed $data * @todo replace this with a strict "SelectItem" type in TYPO3 v15.0 */ public function add($data): void { if ($data instanceof SelectItem) { $this->storage->push($data); } } /** * @param SelectItemCollection $other */ public function addAll(CollectionInterface $other): void { foreach ($other as $item) { if ($item instanceof SelectItem) { $this->storage->push($item); } } } /** * @param mixed $data * @todo replace this with a strict "SelectItem" type in TYPO3 v15.0 */ public function remove($data): void { if (!($data instanceof SelectItem)) { return; } foreach ($this->storage as $key => $value) { if ($value === $data) { $this->storage->offsetUnset($key); break; } } } public function removeAll(): void { $this->storage = new \SplDoublyLinkedList(); } /** * @return SelectItem[] */ public function toArray(): array { $items = []; foreach ($this->storage as $item) { $items[] = $item; } return $items; } }