Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
DOMPPTraverser | |
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addHandler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\Wt2Html; |
5 | |
6 | use Wikimedia\Parsoid\Config\Env; |
7 | use Wikimedia\Parsoid\DOM\Node; |
8 | use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; |
9 | use Wikimedia\Parsoid\Utils\DOMTraverser; |
10 | use Wikimedia\Parsoid\Utils\DTState; |
11 | |
12 | /** |
13 | * This is a class that wraps the DOMTraverser utility for use |
14 | * in the DOM Processor pipeline. |
15 | */ |
16 | class DOMPPTraverser implements Wt2HtmlDOMProcessor { |
17 | private DOMTraverser $dt; |
18 | |
19 | public function __construct( |
20 | ?DOMPostProcessor $domPP, bool $traverseWithTplInfo = false, bool $applyToAttributeEmbeddedHTML = false |
21 | ) { |
22 | $this->dt = new DOMTraverser( $traverseWithTplInfo, $applyToAttributeEmbeddedHTML ); |
23 | } |
24 | |
25 | /** |
26 | * @param ?string $nodeName An optional node name filter |
27 | * @param callable $action A callback, called on each node we traverse that matches nodeName. |
28 | * Proxies call to underlying DOMTraverser. See docs for DOMTraverser::addHandler |
29 | */ |
30 | public function addHandler( ?string $nodeName, callable $action ): void { |
31 | $this->dt->addHandler( $nodeName, $action ); |
32 | } |
33 | |
34 | /** |
35 | * @inheritDoc |
36 | */ |
37 | public function run( |
38 | Env $env, Node $root, array $options = [], bool $atTopLevel = false |
39 | ): void { |
40 | $state = new DTState( $env, $options, $atTopLevel ); |
41 | $this->dt->traverse( new ParsoidExtensionAPI( $env ), $root, $state ); |
42 | } |
43 | } |