| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\RemexHtml\TreeBuilder; |
| 4 |
|
| 5 |
use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 6 |
|
| 7 |
/** |
| 8 |
* A debugging helper which calls a callback function with a descriptive message |
| 9 |
* each time an Element node is destroyed. |
| 10 |
*/ |
| 11 |
class DestructTracer implements TreeHandler { |
| 12 |
/** @var callable */ |
| 13 |
private $callback; |
| 14 |
|
| 15 |
/** |
| 16 |
* @param callable $callback |
| 17 |
*/ |
| 18 |
public function __construct( $callback ) { |
| 19 |
$this->callback = $callback; |
| 20 |
} |
| 21 |
|
| 22 |
/** @inheritDoc */ |
| 23 |
public function startDocument( $fragmentNamespace, $fragmentName ) { |
| 24 |
} |
| 25 |
|
| 26 |
/** @inheritDoc */ |
| 27 |
public function endDocument( $pos ) { |
| 28 |
} |
| 29 |
|
| 30 |
/** @inheritDoc */ |
| 31 |
public function characters( $preposition, $ref, $text, $start, $length, |
| 32 |
$sourceStart, $sourceLength |
| 33 |
) { |
| 34 |
} |
| 35 |
|
| 36 |
/** @inheritDoc */ |
| 37 |
public function insertElement( $preposition, $ref, Element $element, $void, |
| 38 |
$sourceStart, $sourceLength |
| 39 |
) { |
| 40 |
$element->userData = new DestructTracerNode( $this->callback, $element->getDebugTag() ); |
| 41 |
} |
| 42 |
|
| 43 |
/** @inheritDoc */ |
| 44 |
public function endTag( Element $element, $sourceStart, $sourceLength ) { |
| 45 |
} |
| 46 |
|
| 47 |
/** @inheritDoc */ |
| 48 |
public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { |
| 49 |
} |
| 50 |
|
| 51 |
/** @inheritDoc */ |
| 52 |
public function comment( $preposition, $ref, $text, $sourceStart, $sourceLength ) { |
| 53 |
} |
| 54 |
|
| 55 |
/** @inheritDoc */ |
| 56 |
public function error( $text, $pos ) { |
| 57 |
} |
| 58 |
|
| 59 |
/** @inheritDoc */ |
| 60 |
public function mergeAttributes( Element $element, Attributes $attrs, $sourceStart ) { |
| 61 |
} |
| 62 |
|
| 63 |
/** @inheritDoc */ |
| 64 |
public function removeNode( Element $element, $sourceStart ) { |
| 65 |
} |
| 66 |
|
| 67 |
/** @inheritDoc */ |
| 68 |
public function reparentChildren( Element $element, Element $newParent, $sourceStart ) { |
| 69 |
$newParent->userData = new DestructTracerNode( $this->callback, $newParent->getDebugTag() ); |
| 70 |
} |
| 71 |
} |