Skip to content

Commit ffbc691

Browse files
author
Greg Bowler
committed
tweak: class definition
1 parent 81e28ef commit ffbc691

File tree

1 file changed

+80
-34
lines changed

1 file changed

+80
-34
lines changed

src/Node.php

+80-34
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,86 @@
11
<?php
2+
// phpcs:ignoreFile
23
namespace Gt\Dom;
34

45
use DOMNode;
56

6-
class Node extends DOMNode {
7-
use NonDocumentTypeChildNode;
8-
use ChildNode;
9-
use ParentNode;
10-
use RegisteredNodeClass;
11-
12-
const TYPE_ELEMENT = XML_ELEMENT_NODE;
13-
const TYPE_ATTR = XML_ATTRIBUTE_NODE;
14-
const TYPE_TEXT = XML_TEXT_NODE;
15-
const TYPE_CDATA = XML_CDATA_SECTION_NODE;
16-
const TYPE_ENTITY_REF = XML_ENTITY_REF_NODE;
17-
const TYPE_ENTITY = XML_ENTITY_NODE;
18-
const TYPE_PI = XML_PI_NODE;
19-
const TYPE_COMMENT = XML_COMMENT_NODE;
20-
const TYPE_DOCUMENT = XML_DOCUMENT_NODE;
21-
const TYPE_DOCUMENT_TYPE = XML_DOCUMENT_TYPE_NODE;
22-
const TYPE_DOCUMENT_FRAGMENT = XML_DOCUMENT_FRAG_NODE;
23-
const TYPE_NOTATION = XML_NOTATION_NODE;
24-
const TYPE_HTML_DOCUMENT = XML_HTML_DOCUMENT_NODE;
25-
const TYPE_DTD = XML_DTD_NODE;
26-
const TYPE_ELEMENT_DECL = XML_ELEMENT_DECL_NODE;
27-
const TYPE_ATTRIBUTE_DECL = XML_ATTRIBUTE_DECL_NODE;
28-
const TYPE_ENTITY_DECL = XML_ENTITY_DECL_NODE;
29-
const TYPE_NAMESPACE_DECL = XML_NAMESPACE_DECL_NODE;
30-
31-
public const DOCUMENT_POSITION_DISCONNECTED = 1, DOCUMENT_POSITION_PRECEDING = 2, DOCUMENT_POSITION_FOLLOWING = 4;
32-
// public const DOCUMENT_POSITION_DISCONNECTED = 1;//0b000001;
33-
// public const DOCUMENT_POSITION_PRECEDING = 2;//0b000010;
34-
// public const DOCUMENT_POSITION_FOLLOWING = 4;//0b000100;
35-
public const DOCUMENT_POSITION_CONTAINS = 8;//0b001000;
36-
public const DOCUMENT_POSITION_CONTAINED_BY = 16;//0b010000;
37-
public const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32;//0b100000;
38-
39-
private function __construct() {}
7+
/**
8+
* This class is defined twice to assure backwards compatibility with PHP
9+
* versions from 8.1 through to 8.4 and beyond. When support for <= 8.3 is
10+
* dropped, this strange hack will be removed, as we can all use typed class
11+
* constants.
12+
*/
13+
if(version_compare(PHP_VERSION, "8.4", ">=")) {
14+
class Node extends DOMNode {
15+
use NonDocumentTypeChildNode;
16+
use ChildNode;
17+
use ParentNode;
18+
use RegisteredNodeClass;
19+
20+
const TYPE_ELEMENT = XML_ELEMENT_NODE;
21+
const TYPE_ATTR = XML_ATTRIBUTE_NODE;
22+
const TYPE_TEXT = XML_TEXT_NODE;
23+
const TYPE_CDATA = XML_CDATA_SECTION_NODE;
24+
const TYPE_ENTITY_REF = XML_ENTITY_REF_NODE;
25+
const TYPE_ENTITY = XML_ENTITY_NODE;
26+
const TYPE_PI = XML_PI_NODE;
27+
const TYPE_COMMENT = XML_COMMENT_NODE;
28+
const TYPE_DOCUMENT = XML_DOCUMENT_NODE;
29+
const TYPE_DOCUMENT_TYPE = XML_DOCUMENT_TYPE_NODE;
30+
const TYPE_DOCUMENT_FRAGMENT = XML_DOCUMENT_FRAG_NODE;
31+
const TYPE_NOTATION = XML_NOTATION_NODE;
32+
const TYPE_HTML_DOCUMENT = XML_HTML_DOCUMENT_NODE;
33+
const TYPE_DTD = XML_DTD_NODE;
34+
const TYPE_ELEMENT_DECL = XML_ELEMENT_DECL_NODE;
35+
const TYPE_ATTRIBUTE_DECL = XML_ATTRIBUTE_DECL_NODE;
36+
const TYPE_ENTITY_DECL = XML_ENTITY_DECL_NODE;
37+
const TYPE_NAMESPACE_DECL = XML_NAMESPACE_DECL_NODE;
38+
39+
public const int DOCUMENT_POSITION_DISCONNECTED = 0b000001;
40+
public const int DOCUMENT_POSITION_PRECEDING = 0b000010;
41+
public const int DOCUMENT_POSITION_FOLLOWING = 0b000100;
42+
public const int DOCUMENT_POSITION_CONTAINS = 0b001000;
43+
public const int DOCUMENT_POSITION_CONTAINED_BY = 0b010000;
44+
public const int DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0b100000;
45+
46+
private function __construct() {}
47+
}
48+
}
49+
else {
50+
class Node extends DOMNode {
51+
use NonDocumentTypeChildNode;
52+
use ChildNode;
53+
use ParentNode;
54+
use RegisteredNodeClass;
55+
56+
const TYPE_ELEMENT = XML_ELEMENT_NODE;
57+
const TYPE_ATTR = XML_ATTRIBUTE_NODE;
58+
const TYPE_TEXT = XML_TEXT_NODE;
59+
const TYPE_CDATA = XML_CDATA_SECTION_NODE;
60+
const TYPE_ENTITY_REF = XML_ENTITY_REF_NODE;
61+
const TYPE_ENTITY = XML_ENTITY_NODE;
62+
const TYPE_PI = XML_PI_NODE;
63+
const TYPE_COMMENT = XML_COMMENT_NODE;
64+
const TYPE_DOCUMENT = XML_DOCUMENT_NODE;
65+
const TYPE_DOCUMENT_TYPE = XML_DOCUMENT_TYPE_NODE;
66+
const TYPE_DOCUMENT_FRAGMENT = XML_DOCUMENT_FRAG_NODE;
67+
const TYPE_NOTATION = XML_NOTATION_NODE;
68+
const TYPE_HTML_DOCUMENT = XML_HTML_DOCUMENT_NODE;
69+
const TYPE_DTD = XML_DTD_NODE;
70+
const TYPE_ELEMENT_DECL = XML_ELEMENT_DECL_NODE;
71+
const TYPE_ATTRIBUTE_DECL = XML_ATTRIBUTE_DECL_NODE;
72+
const TYPE_ENTITY_DECL = XML_ENTITY_DECL_NODE;
73+
const TYPE_NAMESPACE_DECL = XML_NAMESPACE_DECL_NODE;
74+
75+
public const DOCUMENT_POSITION_DISCONNECTED = 0b000001;
76+
public const DOCUMENT_POSITION_PRECEDING = 0b000010;
77+
public const DOCUMENT_POSITION_FOLLOWING = 0b000100;
78+
public const DOCUMENT_POSITION_CONTAINS = 0b001000;
79+
public const DOCUMENT_POSITION_CONTAINED_BY = 0b010000;
80+
public const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0b100000;
81+
82+
private function __construct() {}
83+
}
4084
}
85+
86+
// phpcs:enable

0 commit comments

Comments
 (0)