beresta_node_child_count($this->handle())); } /** * Ребёнок по индексу с нуля; вне диапазона — BerestaException INDEX_OUT_OF_RANGE. * A child by a zero-based index; out of range is a BerestaException INDEX_OUT_OF_RANGE. */ public function child(int $index): ?Node { return NodeFactory::wrap(Library::ffi()->beresta_node_child($this->handle(), $index), $this->document()); } /** * Все дети списком. / All children as a list. * * @return list */ public function children(): array { return iterator_to_array($this->getIterator(), false); } /** * Перебор детей от первого к последнему (IteratorAggregate). Следующий * сосед берётся на каждом шаге, поэтому удалять текущий узел в цикле нельзя. * * Iterates the children from the first to the last (IteratorAggregate). The next * sibling is taken at every step, so the current node must not be removed in the loop. * * @return \Generator */ public function getIterator(): \Generator { $child = $this->firstChild(); while ($child !== null) { yield $child; $child = $child->nextSibling(); } } }