Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| DOMDataUtils | |
0.00% |
0 / 9 |
|
0.00% |
0 / 9 |
90 | |
0.00% |
0 / 1 |
| getDataParsoid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDataParsoid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDataMw | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| dataMwExists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDataMw | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDataParsoidDiff | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDataParsoidDiff | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| noAttrs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| cloneNode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\Parsoid\Ext; |
| 5 | |
| 6 | use stdClass; |
| 7 | use Wikimedia\Parsoid\DOM\Element; |
| 8 | use Wikimedia\Parsoid\NodeData\DataMw; |
| 9 | use Wikimedia\Parsoid\NodeData\DataParsoid; |
| 10 | use Wikimedia\Parsoid\Utils\DOMDataUtils as DDU; |
| 11 | |
| 12 | /** |
| 13 | * This class provides DOM data helpers needed by extensions. |
| 14 | * These helpers support fetching / updating attributes of DOM nodes. |
| 15 | */ |
| 16 | class DOMDataUtils { |
| 17 | /** |
| 18 | * Get data parsoid info from DOM element |
| 19 | * @param Element $elt |
| 20 | * @return DataParsoid ( this is mostly used for type hinting ) |
| 21 | */ |
| 22 | public static function getDataParsoid( Element $elt ): DataParsoid { |
| 23 | return DDU::getDataParsoid( $elt ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Set data parsoid info on a DOM element |
| 28 | * @param Element $elt |
| 29 | * @param ?DataParsoid $dp data-parsoid |
| 30 | */ |
| 31 | public static function setDataParsoid( Element $elt, ?DataParsoid $dp ): void { |
| 32 | DDU::setDataParsoid( $elt, $dp ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Get data meta wiki info from a DOM element |
| 37 | * @param Element $elt |
| 38 | * @return ?DataMw |
| 39 | */ |
| 40 | public static function getDataMw( Element $elt ): ?DataMw { |
| 41 | return DDU::getDataMw( $elt ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Check if there is meta wiki info on a DOM element |
| 46 | * @param Element $elt |
| 47 | * @return bool |
| 48 | */ |
| 49 | public static function dataMwExists( Element $elt ): bool { |
| 50 | return DDU::validDataMw( $elt ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Set data meta wiki info from a DOM element |
| 55 | * @param Element $elt |
| 56 | * @param ?DataMw $dmw data-mw |
| 57 | */ |
| 58 | public static function setDataMw( Element $elt, ?DataMw $dmw ): void { |
| 59 | DDU::setDataMw( $elt, $dmw ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get data diff info from a DOM element. |
| 64 | * @param Element $elt |
| 65 | * @return ?stdClass |
| 66 | */ |
| 67 | public static function getDataParsoidDiff( Element $elt ): ?stdClass { |
| 68 | return DDU::getDataParsoidDiff( $elt ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Set data diff info on a DOM element. |
| 73 | * @param Element $elt |
| 74 | * @param ?stdClass $diffObj data-parsoid-diff object |
| 75 | */ |
| 76 | public static function setDataParsoidDiff( Element $elt, ?stdClass $diffObj ): void { |
| 77 | DDU::setDataParsoidDiff( $elt, $diffObj ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Does this node have any attributes? This method is the preferred way of |
| 82 | * interrogating this property since Parsoid DOMs might have Parsoid-internal |
| 83 | * attributes added. |
| 84 | * @param Element $elt |
| 85 | * @return bool |
| 86 | */ |
| 87 | public static function noAttrs( Element $elt ): bool { |
| 88 | return DDU::noAttrs( $elt ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Clones a node and its data bag |
| 93 | * @param Element $elt |
| 94 | * @param bool $deep |
| 95 | * @return Element |
| 96 | */ |
| 97 | public static function cloneNode( Element $elt, bool $deep ): Element { |
| 98 | return DDU::cloneNode( $elt, $deep ); |
| 99 | } |
| 100 | } |