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