Skip to content

Commit

Permalink
WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Dec 19, 2023
1 parent 4aaab9c commit 5305dd4
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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', '>='))
Expand Down
14 changes: 14 additions & 0 deletions src/ForwardCompatibleNodes/Attr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);

/**
* @package s9e\SweetDOM
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\SweetDOM\ForwardCompatibleNodes;

use s9e\SweetDOM\Attr as ParentClass;

class Attr extends ParentClass
{
}
16 changes: 16 additions & 0 deletions src/ForwardCompatibleNodes/CdataSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

/**
* @package s9e\SweetDOM
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\SweetDOM\ForwardCompatibleNodes;

use s9e\SweetDOM\CdataSection as ParentClass;
use s9e\SweetDOM\NodeTraits\ChildNodeForwardCompatibility;

class CdataSection extends ParentClass
{
use ChildNodeForwardCompatibility;
}
16 changes: 16 additions & 0 deletions src/ForwardCompatibleNodes/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

/**
* @package s9e\SweetDOM
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\SweetDOM\ForwardCompatibleNodes;

use s9e\SweetDOM\Comment as ParentClass;
use s9e\SweetDOM\NodeTraits\ChildNodeForwardCompatibility;

class Comment extends ParentClass
{
use ChildNodeForwardCompatibility;
}
14 changes: 14 additions & 0 deletions src/ForwardCompatibleNodes/DocumentFragment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types=1);

/**
* @package s9e\SweetDOM
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\SweetDOM\ForwardCompatibleNodes;

use s9e\SweetDOM\DocumentFragment as ParentClass;

class DocumentFragment extends ParentClass
{
}
16 changes: 16 additions & 0 deletions src/ForwardCompatibleNodes/Element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

/**
* @package s9e\SweetDOM
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\SweetDOM\ForwardCompatibleNodes;

use s9e\SweetDOM\Element as ParentClass;
use s9e\SweetDOM\NodeTraits\ChildNodeForwardCompatibility;

class Element extends ParentClass
{
use ChildNodeForwardCompatibility;
}
16 changes: 16 additions & 0 deletions src/ForwardCompatibleNodes/Text.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

/**
* @package s9e\SweetDOM
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\SweetDOM\ForwardCompatibleNodes;

use s9e\SweetDOM\NodeTraits\ChildNodeForwardCompatibility;
use s9e\SweetDOM\Text as ParentClass;

class Text extends ParentClass
{
use ChildNodeForwardCompatibility;
}

0 comments on commit 5305dd4

Please sign in to comment.