<?php
declare(strict_types=1);
namespace League\CommonMark\Node;
use League\CommonMark\Node\Block\AbstractBlock;
final class NodeIterator implements \IteratorAggregate
{
public const FLAG_BLOCKS_ONLY = 1;
private Node $node;
private bool $blocksOnly;
public function __construct(Node $node, int $flags = 0)
{
$this->node = $node;
$this->blocksOnly = ($flags & self::FLAG_BLOCKS_ONLY) === self::FLAG_BLOCKS_ONLY;
}
public function getIterator(): \Generator
{
$stack = [$this->node];
$index = 0;
while ($stack) {
$node = \array_pop($stack);
yield $index++ => $node;