Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Wikimedia\Parsoid\DOM\_registerDomAliasClasses
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
Document
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2// phpcs:disable Generic.Classes.DuplicateClassName.Found
3// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
4// phpcs:disable MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic
5declare( strict_types = 1 );
6
7namespace Wikimedia\Parsoid\DOM;
8
9use Wikimedia\Parsoid\Utils\DOMCompat;
10
11function _registerDomAliasClasses( $doc, string $prefix ): void {
12    # Register our alias classes. Notes:
13    #  - NodeList can't be passed to registerNodeClass, and so in
14    #    "DOMDocument" mode we're always going to be using DOMNodeList,
15    #    not the Wikimedia\Parsoid\DOM\Compat\NodeList class defined here.
16    #  - Similarly, DOMException is always going to be \DOMException
17    #    when we're in DOMDocument mode.
18    #  - CharacterData and Node are abstract superclasses.  Due to the
19    #    limitations of PHP multiple inheritance, we can't make them
20    #    proper subclasses of DOMCharacterData/DOMNode.  Instead we make
21    #    them marker interfaces, and ensure that all subclasses of
22    #    DOMNode also implement our Node interface, and similarly all
23    #    subclasses of DOMCharacterData implement our CharacterData marker
24    #    interface.
25    #  - PHP doesn't have a DOMParser equivalent in the dom extension
26    foreach ( [
27        'Document',
28        'Attr',
29        'Comment',
30        'DocumentFragment',
31        'DocumentType',
32        'Element',
33        'ProcessingInstruction',
34        'Text',
35    ] as $cls ) {
36        $doc->registerNodeClass(
37            "$prefix$cls",
38            "Wikimedia\\Parsoid\\DOM\\$cls"
39        );
40    }
41}
42
43if ( DOMCompat::isUsingDodo() ) {
44
45    class_alias( \Wikimedia\Dodo\Document::class, Document::class );
46
47} elseif ( DOMCompat::isUsing84Dom() ) {
48
49    class_alias( \Dom\Document::class, Document::class );
50
51} else {
52
53    #[\AllowDynamicProperties]
54    class Document extends \DOMDocument implements Node {
55
56        /**
57         * Inprocess cache used in DOMCompat::getBody()
58         *
59         * @var Element|null
60         */
61        public ?Element $body = null;
62
63        public function __construct() {
64            parent::__construct();
65            _registerDomAliasClasses( $this, "DOM" );
66        }
67    }
68}