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.
22 lines
627 B
22 lines
627 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;
|
|
|
|
trait Moonwalk {
|
|
/** Generator which walks up the DOM. Nonstandard. */
|
|
public function moonwalk(?\Closure $filter = null): \Generator {
|
|
return $this->moonwalkGenerator($this, $filter);
|
|
}
|
|
|
|
private function moonwalkGenerator(\DOMNode $node, ?\Closure $filter = null) {
|
|
do {
|
|
if ($filter === null || $filter($node)) {
|
|
yield $node;
|
|
}
|
|
} while ($node = $node->parentNode);
|
|
}
|
|
}
|
|
|