Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PHP 8.4's HTML5 parser #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

strategy:
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
php: ['8.4']
libxml: ['2.9.14']

# Steps represent a sequence of tasks that will be executed as part of the job
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
"psr-4": {"fivefilters\\Readability\\Test\\": "test"}
},
"require": {
"php": ">=8.1",
"php": ">=8.4",
"ext-dom": "*",
"ext-xml": "*",
"ext-mbstring": "*",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"masterminds/html5": "^2.0",
"league/uri": "^7.0"
},
"require-dev": {
Expand Down
25 changes: 5 additions & 20 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Configuration
protected bool $cleanConditionally = true;
protected bool $weightClasses = true;
protected bool $fixRelativeURLs = false;
protected bool $substituteEntities = false;
protected bool $normalizeEntities = false;
protected bool $summonCthulhu = false;
protected string $originalURL = 'http://fakehost';
Expand Down Expand Up @@ -206,24 +205,6 @@ public function setFixRelativeURLs(bool $fixRelativeURLs): Configuration
return $this;
}

/**
* Get substitute entities.
*/
public function getSubstituteEntities(): bool
{
return $this->substituteEntities;
}

/**
* Set substitute entities.
*/
public function setSubstituteEntities(bool $substituteEntities): Configuration
{
$this->substituteEntities = $substituteEntities;

return $this;
}

/**
* Get normalize entities.
*/
Expand Down Expand Up @@ -273,7 +254,11 @@ public function getParser(): string
*/
public function setParser(string $parser): Configuration
{
$this->parser = $parser;
if ($parser !== 'html5') {
throw new \InvalidArgumentException('This version of Readability.php only supports the HTML5 parser introduced in PHP 8.4');
} else {
$this->parser = $parser;
}

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nodes/DOM/DOMAttr.php → src/Nodes/DOM/Attr.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMAttr extends \DOMAttr
class Attr extends \DOM\Attr
{
use NodeTrait;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMNotation extends \DOMNotation
class CdataSection extends \DOM\CdataSection
{
use NodeTrait;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMCdataSection extends \DOMCdataSection
class CharacterData extends \DOM\CharacterData
{
use NodeTrait;
}
2 changes: 1 addition & 1 deletion src/Nodes/DOM/DOMEntity.php → src/Nodes/DOM/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMEntity extends \DOMEntity
class Comment extends \DOM\Comment
{
use NodeTrait;
}
30 changes: 0 additions & 30 deletions src/Nodes/DOM/DOMDocument.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nodes/DOM/DOMDocumentFragment.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nodes/DOM/DOMDocumentType.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nodes/DOM/DOMEntityReference.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nodes/DOM/DOMProcessingInstruction.php

This file was deleted.

10 changes: 10 additions & 0 deletions src/Nodes/DOM/DocumentFragment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace fivefilters\Readability\Nodes\DOM;

use fivefilters\Readability\Nodes\NodeTrait;

class DocumentFragment extends \DOM\DocumentFragment
{
use NodeTrait;
}
10 changes: 10 additions & 0 deletions src/Nodes/DOM/DocumentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace fivefilters\Readability\Nodes\DOM;

use fivefilters\Readability\Nodes\NodeTrait;

class DocumentType extends \DOM\DocumentType
{
use NodeTrait;
}
8 changes: 4 additions & 4 deletions src/Nodes/DOM/DOMElement.php → src/Nodes/DOM/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMElement extends \DOMElement
class Element extends \DOM\HtmlElement
{
use NodeTrait;

Expand All @@ -13,9 +13,9 @@ class DOMElement extends \DOMElement
*
* To get all child nodes, including non-element nodes like text and comment nodes, use childNodes.
*/
public function children(): DOMNodeList
public function children(): NodeList
{
$newList = new DOMNodeList();
$newList = new NodeList();
foreach ($this->childNodes as $node) {
if ($node->nodeType === XML_ELEMENT_NODE) {
$newList->add($node);
Expand All @@ -29,7 +29,7 @@ public function children(): DOMNodeList
*
* @deprecated Use previousElementSibling instead - introduced in PHP 8.0.
*/
public function previousElementSibling(): ?DOMElement
public function previousElementSibling(): ?Element
{
return $this->previousElementSibling;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nodes/DOM/DOMComment.php → src/Nodes/DOM/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMComment extends \DOMComment
class Entity extends \DOM\Entity
{
use NodeTrait;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMCharacterData extends \DOMCharacterData
class EntityReference extends \DOM\EntityReference
{
use NodeTrait;
}
2 changes: 1 addition & 1 deletion src/Nodes/DOM/DOMNode.php → src/Nodes/DOM/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @method getAttribute($attribute)
* @method hasAttribute($attribute)
*/
class DOMNode extends \DOMNode
class Node extends \DOM\Node
{
use NodeTrait;
}
8 changes: 4 additions & 4 deletions src/Nodes/DOM/DOMNodeList.php → src/Nodes/DOM/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace fivefilters\Readability\Nodes\DOM;

/**
* Class DOMNodeList.
* Class NodeList.
*
* This is a fake DOMNodeList class that allows adding items to the list. The original class is static and the nodes
* are defined automagically when instantiating it. This fake version behaves exactly the same way but adds the function
Expand All @@ -12,7 +12,7 @@
* It cannot extend the original DOMNodeList class because the functionality behind the property ->length is hidden
* from the user and cannot be extended, changed, or tweaked.
*/
class DOMNodeList implements \Countable, \IteratorAggregate
class NodeList implements \Countable, \IteratorAggregate
{
/**
* @var array
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __get($name)
/**
* Add node to the list.
*/
public function add(DOMNode|DOMElement|DOMText|DOMComment $node): DOMNodeList
public function add(Node|Element|Text|Comment $node): NodeList
{
$this->items[] = $node;
$this->length++;
Expand All @@ -53,7 +53,7 @@ public function add(DOMNode|DOMElement|DOMText|DOMComment $node): DOMNodeList
/**
* Get node.
*/
public function item(int $offset): DOMNode|DOMElement|DOMText|DOMComment
public function item(int $offset): Node|Element|Text|Comment
{
return $this->items[$offset];
}
Expand Down
10 changes: 10 additions & 0 deletions src/Nodes/DOM/Notation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace fivefilters\Readability\Nodes\DOM;

use fivefilters\Readability\Nodes\NodeTrait;

class Notation extends \DOM\Notation
{
use NodeTrait;
}
10 changes: 10 additions & 0 deletions src/Nodes/DOM/ProcessingInstruction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace fivefilters\Readability\Nodes\DOM;

use fivefilters\Readability\Nodes\NodeTrait;

class ProcessingInstruction extends \DOM\ProcessingInstruction
{
use NodeTrait;
}
2 changes: 1 addition & 1 deletion src/Nodes/DOM/DOMText.php → src/Nodes/DOM/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use fivefilters\Readability\Nodes\NodeTrait;

class DOMText extends \DOMText
class Text extends \DOM\Text
{
use NodeTrait;
}
Loading
Loading