Modern DOM library written in PHP for HTML documents
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
684 B

<?php
/** @license MIT
* Copyright 2017 , Dustin Wilson, J. King et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace MensBeam\HTML\DOM;
trait WalkShallow {
/**
* Generator which just walks through a node's child nodes. Nonstandard.
*
* @param ?\Closure $filter - An optional closure to use to filter
*/
public function walkShallow(?\Closure $filter = null): \Generator {
$node = (!$this instanceof TemplateElement) ? $this : $this->content;
foreach ($node->childNodes as $child) {
if ($filter === null || $filter($child)) {
yield $child;
}
}
}
}