count(); } protected function __construct(InnerDocument $innerDocument, \DOMNodeList $nodeList) { $this->innerDocument = $innerDocument; $this->innerCollection = $nodeList; } public function count(): int { return $this->innerCollection->length; } public function current(): ?Node { return $this->item($this->position); } public function item(int $index): ?Node { # The item(index) method must return the indexth node in the collection. If # there is no indexth node in the collection, then the method must return null. // PHP's DOM does this okay already $node = $this->innerCollection->item($index); if ($node === null) { return null; } return $this->innerDocument->getWrapperNode($node); } public function key(): int { return $this->position; } public function next(): void { $this->position++; } public function rewind(): void { $this->position = 0; } public function offsetExists($offset): bool { return ($this->innerCollection->item($offset) !== null); } public function offsetGet($offset): ?Node { return $this->item($offset); } public function offsetSet($offset, $value): void { // Collections are immutable; the spec is ambiguous as to what to do here. // Browsers silently fail here, so that's what we're going to do. } public function offsetUnset($offset): void { // Collections are immutable; the spec is ambiguous as to what to do here. // Browsers silently fail here, so that's what we're going to do. } public function valid(): bool { return $this->offsetExists($this->position); } }