Skip to content

Commit 4def7f7

Browse files
tgalopinnicolas-grekas
authored andcommitted
Make masterminds/html5 as a required dependency of DomCrawler
1 parent 47fa3d2 commit 4def7f7

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

Crawler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Crawler implements \Countable, \IteratorAggregate
5858
*/
5959
private bool $isHtml = true;
6060

61-
private ?HTML5 $html5Parser;
61+
private HTML5 $html5Parser;
6262

6363
/**
6464
* @param \DOMNodeList|\DOMNode|\DOMNode[]|string|null $node A Node to use as the base for the crawling
@@ -67,7 +67,7 @@ public function __construct(\DOMNodeList|\DOMNode|array|string $node = null, str
6767
{
6868
$this->uri = $uri;
6969
$this->baseHref = $baseHref ?: $uri;
70-
$this->html5Parser = class_exists(HTML5::class) ? new HTML5(['disable_html_ns' => true]) : null;
70+
$this->html5Parser = new HTML5(['disable_html_ns' => true]);
7171
$this->cachedNamespaces = new \ArrayObject();
7272

7373
$this->add($node);
@@ -589,7 +589,7 @@ public function html(string $default = null): string
589589
$node = $this->getNode(0);
590590
$owner = $node->ownerDocument;
591591

592-
if (null !== $this->html5Parser && '<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
592+
if ('<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
593593
$owner = $this->html5Parser;
594594
}
595595

@@ -610,7 +610,7 @@ public function outerHtml(): string
610610
$node = $this->getNode(0);
611611
$owner = $node->ownerDocument;
612612

613-
if (null !== $this->html5Parser && '<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
613+
if ('<!DOCTYPE html>' === $owner->saveXML($owner->childNodes[0])) {
614614
$owner = $this->html5Parser;
615615
}
616616

@@ -1178,12 +1178,10 @@ private function parseHtmlString(string $content, string $charset): \DOMDocument
11781178

11791179
private function canParseHtml5String(string $content): bool
11801180
{
1181-
if (null === $this->html5Parser) {
1182-
return false;
1183-
}
11841181
if (false === ($pos = stripos($content, '<!doctype html>'))) {
11851182
return false;
11861183
}
1184+
11871185
$header = substr($content, 0, $pos);
11881186

11891187
return '' === $header || $this->isValidHtml5Heading($header);

composer.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
"require": {
1919
"php": ">=8.1",
2020
"symfony/polyfill-ctype": "~1.8",
21-
"symfony/polyfill-mbstring": "~1.0"
22-
},
23-
"require-dev": {
24-
"symfony/css-selector": "^5.4|^6.0",
21+
"symfony/polyfill-mbstring": "~1.0",
2522
"masterminds/html5": "^2.6"
2623
},
27-
"conflict": {
28-
"masterminds/html5": "<2.6"
24+
"require-dev": {
25+
"symfony/css-selector": "^5.4|^6.0"
2926
},
3027
"suggest": {
3128
"symfony/css-selector": ""

0 commit comments

Comments
 (0)