|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Caxy\HtmlDiff\ListDiff; |
|
4
|
|
|
|
|
5
|
|
|
class DiffListItem |
|
6
|
|
|
{ |
|
7
|
|
|
protected $attributes = array(); |
|
8
|
|
|
|
|
9
|
|
|
protected $text; |
|
10
|
|
|
|
|
11
|
|
|
protected $startTag; |
|
12
|
|
|
|
|
13
|
|
|
protected $endTag; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct($text, $attributes = array(), $startTag, $endTag) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
$this->text = $text; |
|
|
|
|
|
|
18
|
|
|
$this->attributes = $attributes; |
|
19
|
|
|
$this->startTag = $startTag; |
|
|
|
|
|
|
20
|
|
|
$this->endTag = $endTag; |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return array |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getAttributes() |
|
27
|
|
|
{ |
|
28
|
|
|
return $this->attributes; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param array $attributes |
|
33
|
|
|
* |
|
34
|
|
|
* @return DiffListItem |
|
35
|
|
|
*/ |
|
36
|
|
|
public function setAttributes($attributes) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->attributes = $attributes; |
|
39
|
|
|
|
|
40
|
|
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return mixed |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getText() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->text; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param mixed $text |
|
53
|
|
|
* |
|
54
|
|
|
* @return DiffListItem |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setText($text) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->text = $text; |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return mixed |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getStartTag() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->startTag; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getStartTagWithDiffClass($class = 'normal') |
|
72
|
|
|
{ |
|
73
|
|
|
return str_replace('>', ' class="'.$class.'">', $this->startTag); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param mixed $startTag |
|
78
|
|
|
* |
|
79
|
|
|
* @return DiffListItem |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setStartTag($startTag) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->startTag = $startTag; |
|
84
|
|
|
|
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @return mixed |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getEndTag() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->endTag; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param mixed $endTag |
|
98
|
|
|
* |
|
99
|
|
|
* @return DiffListItem |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setEndTag($endTag) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->endTag = $endTag; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getHtml($class = 'normal', $wrapTag = null) |
|
109
|
|
|
{ |
|
110
|
|
|
$startWrap = $wrapTag ? sprintf('<%s>', $wrapTag) : ''; |
|
111
|
|
|
$endWrap = $wrapTag ? sprintf('</%s>', $wrapTag) : ''; |
|
|
|
|
|
|
112
|
|
|
return sprintf('%s%s%s%s%s', $this->getStartTagWithDiffClass($class), $startWrap, $this->getInnerHtml(), $endWrap, $this->endTag); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getInnerHtml() |
|
116
|
|
|
{ |
|
117
|
|
|
return implode('', $this->text); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function __toString() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->getHtml(); |
|
123
|
|
|
} |
|
124
|
|
|
} |
If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway: