Debian Codegraph @

vendor/wikimedia/parsoid/src/DOM/Document.php

raw
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace Wikimedia\Parsoid\DOM;
6
7 #[\AllowDynamicProperties]
8 class Document extends \DOMDocument implements Node {
9
10 /**
11 * Inprocess cache used in DOMCompat::getBody()
12 *
13 * @var Element|null
14 */
15 public ?Element $body = null;
16
17 public function __construct() {
18 parent::__construct();
19 # Register our alias classes. Notes:
20 # - NodeList can't be passed to registerNodeClass, and so in
21 # "DOMDocument" mode we're always going to be using DOMNodeList,
22 # not the Wikimedia\Parsoid\DOM\Compat\NodeList class defined here.
23 # - Similarly, DOMException is always going to be \DOMException
24 # when we're in DOMDocument mode.
25 # - CharacterData and Node are abstract superclasses. Due to the
26 # limitations of PHP multiple inheritance, we can't make them
27 # proper subclasses of DOMCharacterData/DOMNode. Instead we make
28 # them marker interfaces, and ensure that all subclasses of
29 # DOMNode also implement our Node interface, and similarly all
30 # subclasses of DOMCharacterData implement our CharacterData marker
31 # interface.
32 # - PHP doesn't have a DOMParser equivalent in the dom extension
33 foreach ( [
34 'Document',
35 'Attr',
36 'Comment',
37 'DocumentFragment',
38 'DocumentType',
39 'Element',
40 'ProcessingInstruction',
41 'Text',
42 ] as $cls ) {
43 $this->registerNodeClass(
44 "DOM$cls",
45 "Wikimedia\\Parsoid\\DOM\\$cls"
46 );
47 }
48 }
49 }