9
9
use PHPHtmlParser \Dom \AbstractNode ;
10
10
use PHPHtmlParser \Dom \Collection ;
11
11
use PHPHtmlParser \Dom \HtmlNode ;
12
+ use PHPHtmlParser \Dom \Tag ;
12
13
use PHPHtmlParser \Dom \TextNode ;
13
14
use PHPHtmlParser \DTO \TagDTO ;
14
15
use PHPHtmlParser \Enum \StringToken ;
@@ -171,10 +172,10 @@ public function loadStr(string $str, ?Options $options = null): Dom
171
172
{
172
173
$ this ->options = new Options ();
173
174
if ($ this ->globalOptions !== null ) {
174
- $ this ->options ->setFromOptions ($ this ->globalOptions );
175
+ $ this ->options = $ this -> options ->setFromOptions ($ this ->globalOptions );
175
176
}
176
177
if ($ options !== null ) {
177
- $ this ->options ->setFromOptions ($ options );
178
+ $ this ->options = $ this -> options ->setFromOptions ($ options );
178
179
}
179
180
180
181
$ this ->rawSize = \strlen ($ str );
@@ -194,7 +195,7 @@ public function loadStr(string $str, ?Options $options = null): Dom
194
195
/**
195
196
* Sets a global options array to be used by all load calls.
196
197
*
197
- * @chainable
198
+ *
198
199
*/
199
200
public function setOptions (Options $ options ): Dom
200
201
{
@@ -512,11 +513,7 @@ private function parse(): void
512
513
*/
513
514
private function parseTag (): TagDTO
514
515
{
515
- $ return = [
516
- 'status ' => false ,
517
- 'closing ' => false ,
518
- 'node ' => null ,
519
- ];
516
+ $ return = [];
520
517
if ($ this ->content ->char () != '< ' ) {
521
518
// we are not at the beginning of a tag
522
519
return new TagDTO ();
@@ -549,12 +546,20 @@ private function parseTag(): TagDTO
549
546
$ return ['tag ' ] = \strtolower ($ tag );
550
547
551
548
return new TagDTO ($ return );
552
- }
553
-
554
- $ tag = \strtolower ($ this ->content ->copyByToken (StringToken::SLASH (), true ));
555
- if (\trim ($ tag ) == '' ) {
556
- // no tag found, invalid < found
557
- return new TagDTO ();
549
+ } elseif ($ this ->content ->char () == '? ' ) {
550
+ // special setting tag
551
+ $ tag = $ this ->content ->fastForward (1 )
552
+ ->copyByToken (StringToken::SLASH (), true );
553
+ $ tag = (new Tag ($ tag ))
554
+ ->setOpening ('<? ' )
555
+ ->setClosing (' ?> ' )
556
+ ->selfClosing ();
557
+ } else {
558
+ $ tag = \strtolower ($ this ->content ->copyByToken (StringToken::SLASH (), true ));
559
+ if (\trim ($ tag ) == '' ) {
560
+ // no tag found, invalid < found
561
+ return new TagDTO ();
562
+ }
558
563
}
559
564
$ node = new HtmlNode ($ tag );
560
565
$ node ->setHtmlSpecialCharsDecode ($ this ->options ->isHtmlSpecialCharsDecode ());
@@ -631,23 +636,22 @@ private function parseTag(): TagDTO
631
636
}
632
637
633
638
$ this ->content ->skipByToken (StringToken::BLANK ());
634
- $ tag = \strtolower ($ tag );
635
639
if ($ this ->content ->char () == '/ ' ) {
636
640
// self closing tag
637
641
$ node ->getTag ()->selfClosing ();
638
642
$ this ->content ->fastForward (1 );
639
- } elseif (\in_array ($ tag , $ this ->options ->getSelfClosing (), true )) {
643
+ } elseif (\in_array ($ node -> getTag ()-> name () , $ this ->options ->getSelfClosing (), true )) {
640
644
// Should be a self closing tag, check if we are strict
641
645
if ($ this ->options ->isStrict ()) {
642
646
$ character = $ this ->content ->getPosition ();
643
- throw new StrictException ("Tag ' $ tag ' is not self closing! (character # $ character) " );
647
+ throw new StrictException ("Tag ' " . $ node -> getTag ()-> name (). " ' is not self closing! (character # $ character) " );
644
648
}
645
649
646
650
// We force self closing on this tag.
647
651
$ node ->getTag ()->selfClosing ();
648
652
649
653
// Should this tag use a trailing slash?
650
- if (\in_array ($ tag , $ this ->options ->getNoSlash (), true )) {
654
+ if (\in_array ($ node -> getTag ()-> name () , $ this ->options ->getNoSlash (), true )) {
651
655
$ node ->getTag ()->noTrailingSlash ();
652
656
}
653
657
}
0 commit comments