File tree Expand file tree Collapse file tree 7 files changed +62
-2
lines changed Expand file tree Collapse file tree 7 files changed +62
-2
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,9 @@ $rendererOptions = [
92
92
// internally, ops (tags) are all int type but this is not good for human reading.
93
93
// set this to "true" to convert them into string form before outputting.
94
94
'outputTagAsString' => true,
95
+ // change this value to a non-null one as the the returned diff
96
+ // if the two input strings are identical
97
+ 'resultForIdenticals' => null,
95
98
// extra HTML classes added to the DOM of the diff container
96
99
'wrapperClasses' => ['diff-wrapper'],
97
100
];
Original file line number Diff line number Diff line change 48
48
// internally, ops (tags) are all int type but this is not good for human reading.
49
49
// set this to "true" to convert them into string form before outputting.
50
50
'outputTagAsString ' => false ,
51
+ // change this value to a non-null one as the the returned diff
52
+ // if the two input strings are identical
53
+ 'resultForIdenticals ' => null ,
51
54
// extra HTML classes added to the DOM of the diff container
52
55
'wrapperClasses ' => ['diff-wrapper ' ],
53
56
];
Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ abstract class AbstractRenderer implements RendererInterface
49
49
// internally, ops (tags) are all int type but this is not good for human reading.
50
50
// set this to "true" to convert them into string form before outputting.
51
51
'outputTagAsString ' => false ,
52
+ // change this value to a non-null one as the the returned diff
53
+ // if the two input strings are identical
54
+ 'resultForIdenticals ' => null ,
52
55
// extra HTML classes added to the DOM of the diff container
53
56
'wrapperClasses ' => ['diff-wrapper ' ],
54
57
];
@@ -104,12 +107,23 @@ public function getOptions(): array
104
107
105
108
/**
106
109
* {@inheritdoc}
110
+ *
111
+ * @final
112
+ *
113
+ * @todo mark this method with "final" in the next major release
107
114
*/
108
115
public function getResultForIdenticals (): string
109
116
{
110
- return '' ;
117
+ return $ this -> options [ ' resultForIdenticals ' ] ?? $ this -> getResultForIdenticalsDefault () ;
111
118
}
112
119
120
+ /**
121
+ * Get the renderer default result when the old and the new are the same.
122
+ *
123
+ * @return string
124
+ */
125
+ abstract public function getResultForIdenticalsDefault (): string ;
126
+
113
127
/**
114
128
* {@inheritdoc}
115
129
*/
Original file line number Diff line number Diff line change @@ -32,6 +32,14 @@ abstract class AbstractHtml extends AbstractRenderer
32
32
SequenceMatcher::OP_REP => 'rep ' ,
33
33
];
34
34
35
+ /**
36
+ * {@inheritdoc}
37
+ */
38
+ public function getResultForIdenticalsDefault (): string
39
+ {
40
+ return '' ;
41
+ }
42
+
35
43
/**
36
44
* Render and return an array structure suitable for generating HTML
37
45
* based differences. Generally called by subclasses that generate a
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ final class Json extends AbstractHtml
28
28
/**
29
29
* {@inheritdoc}
30
30
*/
31
- public function getResultForIdenticals (): string
31
+ public function getResultForIdenticalsDefault (): string
32
32
{
33
33
return '[] ' ;
34
34
}
Original file line number Diff line number Diff line change @@ -15,4 +15,12 @@ abstract class AbstractText extends AbstractRenderer
15
15
* @var bool is this renderer pure text?
16
16
*/
17
17
const IS_TEXT_RENDERER = true ;
18
+
19
+ /**
20
+ * {@inheritdoc}
21
+ */
22
+ public function getResultForIdenticalsDefault (): string
23
+ {
24
+ return '' ;
25
+ }
18
26
}
Original file line number Diff line number Diff line change @@ -44,4 +44,28 @@ public function testSetOptionsWithLanguageArray(): void
44
44
'Rederer options: "language" array should work. '
45
45
);
46
46
}
47
+
48
+ /**
49
+ * Test the AbstractRenderer::setOptions with result for identicals.
50
+ *
51
+ * @covers \Jfcherng\Diff\Renderer\AbstractRenderer::setOptions
52
+ */
53
+ public function testSetOptionsWithResultForIdenticals (): void
54
+ {
55
+ $ testMarker = '_TEST_MARKER_ ' ;
56
+
57
+ $ diffResult = DiffHelper::calculate (
58
+ 'we are the same ' ,
59
+ 'we are the same ' ,
60
+ 'Inline ' ,
61
+ [],
62
+ ['resultForIdenticals ' => $ testMarker ]
63
+ );
64
+
65
+ static ::assertSame (
66
+ $ testMarker ,
67
+ $ diffResult ,
68
+ 'Rederer options: result for identicals should work. '
69
+ );
70
+ }
47
71
}
You can’t perform that action at this time.
0 commit comments