|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Steve Nebes <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace SN\DaisyDiff\Html\Dom; |
|
12
|
|
|
|
|
13
|
|
|
use SN\DaisyDiff\Html\Modification\Modification; |
|
14
|
|
|
use SN\DaisyDiff\Html\Modification\ModificationType; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Represents a piece of text in the HTML file. |
|
18
|
|
|
*/ |
|
19
|
|
|
class TextNode extends Node |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $s = ''; |
|
23
|
|
|
|
|
24
|
|
|
/** @var Modification|null */ |
|
25
|
|
|
private $modification; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param TagNode $parent |
|
29
|
|
|
* @param string $s |
|
30
|
|
|
*/ |
|
31
|
104 |
|
public function __construct(?TagNode $parent, string $s) |
|
32
|
|
|
{ |
|
33
|
104 |
|
parent::__construct($parent); |
|
34
|
|
|
|
|
35
|
104 |
|
$this->modification = new Modification(ModificationType::NONE, ModificationType::NONE); |
|
36
|
104 |
|
$this->s = $s; |
|
37
|
104 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @todo Check if we need to deep clone this. |
|
41
|
|
|
* |
|
42
|
|
|
* @return Node |
|
43
|
|
|
*/ |
|
44
|
22 |
|
public function copyTree(): Node |
|
45
|
|
|
{ |
|
46
|
22 |
|
$node = clone $this; |
|
47
|
22 |
|
$node->setParent(null); |
|
48
|
|
|
|
|
49
|
22 |
|
return $node; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return Node |
|
54
|
|
|
*/ |
|
55
|
27 |
|
public function getLeftMostChild(): Node |
|
56
|
|
|
{ |
|
57
|
27 |
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return Node |
|
62
|
|
|
*/ |
|
63
|
46 |
|
public function getRightMostChild(): Node |
|
64
|
|
|
{ |
|
65
|
46 |
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
24 |
|
public function getMinimalDeletedSet(int $id): array |
|
72
|
|
|
{ |
|
73
|
24 |
|
$nodes = []; |
|
74
|
24 |
|
$modification = $this->getModification(); |
|
75
|
|
|
|
|
76
|
24 |
|
if ($modification->getType() === ModificationType::REMOVED && $modification->getId() === $id) { |
|
77
|
24 |
|
$nodes[] = $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
24 |
|
return $nodes; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
69 |
|
public function getText(): string |
|
87
|
|
|
{ |
|
88
|
69 |
|
return $this->s; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param Node|null $other |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
50 |
|
public function isSameText(?Node $other): bool |
|
96
|
|
|
{ |
|
97
|
50 |
|
if ($other instanceof TextNode) { |
|
98
|
50 |
|
return $this->getText() === $other->getText(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return Modification|null |
|
106
|
|
|
*/ |
|
107
|
76 |
|
public function getModification(): ?Modification |
|
108
|
|
|
{ |
|
109
|
76 |
|
return $this->modification; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param Modification|null $m |
|
114
|
|
|
*/ |
|
115
|
75 |
|
public function setModification(?Modification $m): void |
|
116
|
|
|
{ |
|
117
|
75 |
|
$this->modification = $m; |
|
118
|
75 |
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
7 |
|
public function __toString(): string |
|
124
|
|
|
{ |
|
125
|
7 |
|
return $this->getText(); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|