From 5305dd4092de6d3a7c3d3ab02a7d4f16410347d9 Mon Sep 17 00:00:00 2001 From: JoshyPHP Date: Tue, 19 Dec 2023 17:41:05 +0100 Subject: [PATCH] WiP --- src/Document.php | 21 ++++++++++++++----- src/ForwardCompatibleNodes/Attr.php | 14 +++++++++++++ src/ForwardCompatibleNodes/CdataSection.php | 16 ++++++++++++++ src/ForwardCompatibleNodes/Comment.php | 16 ++++++++++++++ .../DocumentFragment.php | 14 +++++++++++++ src/ForwardCompatibleNodes/Element.php | 16 ++++++++++++++ src/ForwardCompatibleNodes/Text.php | 16 ++++++++++++++ 7 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 src/ForwardCompatibleNodes/Attr.php create mode 100644 src/ForwardCompatibleNodes/CdataSection.php create mode 100644 src/ForwardCompatibleNodes/Comment.php create mode 100644 src/ForwardCompatibleNodes/DocumentFragment.php create mode 100644 src/ForwardCompatibleNodes/Element.php create mode 100644 src/ForwardCompatibleNodes/Text.php diff --git a/src/Document.php b/src/Document.php index 7cc04f9..ac47bb8 100644 --- a/src/Document.php +++ b/src/Document.php @@ -46,11 +46,7 @@ public function __construct(string $version = '1.0', string $encoding = '') $this->nodeCreator = new NodeCreator($this); $classes = ['Attr', 'CdataSection', 'Comment', 'DocumentFragment', 'Element', 'Text']; - $namespace = __NAMESPACE__; - if ($this->needsWorkarounds()) - { - $namespace .= '\\PatchedNodes'; - } + $namespace = $this->getNodesNamespace(); foreach ($classes as $className) { $this->registerNodeClass('DOM' . $className, $namespace . '\\' . $className); @@ -89,6 +85,21 @@ public function query(string $expression, ?DOMNode $contextNode = null, bool $re return $result; } + protected function getNodesNamespace(): string + { + $namespace = __NAMESPACE__; + if ($this->needsWorkarounds()) + { + $namespace .= '\\PatchedNodes'; + } + elseif (version_compare(PHP_VERSION, '8.3.0', '<')) + { + $namespace .= '\\ForwardCompatibleNodes'; + } + + return $namespace; + } + protected function needsWorkarounds(): bool { if (version_compare(PHP_VERSION, '8.2.10', '>=')) diff --git a/src/ForwardCompatibleNodes/Attr.php b/src/ForwardCompatibleNodes/Attr.php new file mode 100644 index 0000000..1141bdd --- /dev/null +++ b/src/ForwardCompatibleNodes/Attr.php @@ -0,0 +1,14 @@ +