|
15 | 15 | <body>
|
16 | 16 | <?php
|
17 | 17 |
|
18 |
| - // include two sample files for comparison |
19 |
| - $oldFilePath = __DIR__ . '/old_file.txt'; |
20 |
| - $newFilePath = __DIR__ . '/new_file.txt'; |
21 |
| - $oldFile = \file_get_contents($oldFilePath); |
22 |
| - $newFile = \file_get_contents($newFilePath); |
23 |
| - |
24 |
| - // options for Diff class |
25 |
| - $diffOptions = [ |
26 |
| - // show how many neighbor lines |
27 |
| - 'context' => 1, |
28 |
| - // ignore case difference |
29 |
| - 'ignoreCase' => false, |
30 |
| - // ignore whitespace difference |
31 |
| - 'ignoreWhitespace' => false, |
32 |
| - ]; |
33 |
| - |
34 |
| - // options for renderer class |
35 |
| - $rendererOptions = [ |
36 |
| - // how detailed the rendered HTML is? (line, word, char) |
37 |
| - 'detailLevel' => 'line', |
38 |
| - // renderer language: eng, cht, chs, jpn, ... |
39 |
| - // or an array which has the same keys with a language file |
40 |
| - 'language' => 'eng', |
41 |
| - // show a separator between different diff hunks in HTML renderers |
42 |
| - 'separateBlock' => true, |
43 |
| - // the frontend HTML could use CSS "white-space: pre;" to visualize consecutive whitespaces |
44 |
| - // but if you want to visualize them in the backend with " ", you can set this to true |
45 |
| - 'spacesToNbsp' => false, |
46 |
| - // HTML renderer tab width (negative = do not convert into spaces) |
47 |
| - 'tabSize' => 4, |
48 |
| - // internally, ops (tags) are all int type but this is not good for human reading. |
49 |
| - // set this to "true" to convert them into string form before outputting. |
50 |
| - 'outputTagAsString' => false, |
51 |
| - // extra HTML classes added to the DOM of the diff container |
52 |
| - 'wrapperClasses' => ['diff-wrapper'], |
53 |
| - ]; |
| 18 | + // include two sample files for comparison |
| 19 | + $oldFilePath = __DIR__ . '/old_file.txt'; |
| 20 | + $newFilePath = __DIR__ . '/new_file.txt'; |
| 21 | + $oldFile = \file_get_contents($oldFilePath); |
| 22 | + $newFile = \file_get_contents($newFilePath); |
| 23 | + |
| 24 | + // options for Diff class |
| 25 | + $diffOptions = [ |
| 26 | + // show how many neighbor lines |
| 27 | + 'context' => 1, |
| 28 | + // ignore case difference |
| 29 | + 'ignoreCase' => false, |
| 30 | + // ignore whitespace difference |
| 31 | + 'ignoreWhitespace' => false, |
| 32 | + ]; |
| 33 | + |
| 34 | + // options for renderer class |
| 35 | + $rendererOptions = [ |
| 36 | + // how detailed the rendered HTML is? (line, word, char) |
| 37 | + 'detailLevel' => 'line', |
| 38 | + // renderer language: eng, cht, chs, jpn, ... |
| 39 | + // or an array which has the same keys with a language file |
| 40 | + 'language' => 'eng', |
| 41 | + // show a separator between different diff hunks in HTML renderers |
| 42 | + 'separateBlock' => true, |
| 43 | + // the frontend HTML could use CSS "white-space: pre;" to visualize consecutive whitespaces |
| 44 | + // but if you want to visualize them in the backend with " ", you can set this to true |
| 45 | + 'spacesToNbsp' => false, |
| 46 | + // HTML renderer tab width (negative = do not convert into spaces) |
| 47 | + 'tabSize' => 4, |
| 48 | + // internally, ops (tags) are all int type but this is not good for human reading. |
| 49 | + // set this to "true" to convert them into string form before outputting. |
| 50 | + 'outputTagAsString' => false, |
| 51 | + // extra HTML classes added to the DOM of the diff container |
| 52 | + 'wrapperClasses' => ['diff-wrapper'], |
| 53 | + ]; |
54 | 54 |
|
55 | 55 | ?>
|
56 | 56 |
|
57 | 57 | <h1>None-level Diff</h1>
|
58 | 58 | <?php
|
59 | 59 |
|
60 |
| - // demo the no-inline-detail diff |
61 |
| - $result = DiffHelper::calculate( |
62 |
| - $oldFile, |
63 |
| - $newFile, |
64 |
| - 'Inline', |
65 |
| - $diffOptions, |
66 |
| - ['detailLevel' => 'none'] + $rendererOptions |
67 |
| - ); |
| 60 | + // demo the no-inline-detail diff |
| 61 | + $result = DiffHelper::calculate( |
| 62 | + $oldFile, |
| 63 | + $newFile, |
| 64 | + 'Inline', |
| 65 | + $diffOptions, |
| 66 | + ['detailLevel' => 'none'] + $rendererOptions |
| 67 | + ); |
68 | 68 |
|
69 |
| - echo $result; |
| 69 | + echo $result; |
70 | 70 |
|
71 | 71 | ?>
|
72 | 72 |
|
73 | 73 | <h1>Line-level Diff (Default)</h1>
|
74 | 74 | <?php
|
75 | 75 |
|
76 |
| - // demo the word-level diff |
77 |
| - $result = DiffHelper::calculate( |
78 |
| - $oldFile, |
79 |
| - $newFile, |
80 |
| - 'Inline', |
81 |
| - $diffOptions, |
82 |
| - ['detailLevel' => 'line'] + $rendererOptions |
83 |
| - ); |
| 76 | + // demo the word-level diff |
| 77 | + $result = DiffHelper::calculate( |
| 78 | + $oldFile, |
| 79 | + $newFile, |
| 80 | + 'Inline', |
| 81 | + $diffOptions, |
| 82 | + ['detailLevel' => 'line'] + $rendererOptions |
| 83 | + ); |
84 | 84 |
|
85 |
| - echo $result; |
| 85 | + echo $result; |
86 | 86 |
|
87 | 87 | ?>
|
88 | 88 |
|
89 | 89 | <h1>Word-level Diff</h1>
|
90 | 90 | <?php
|
91 | 91 |
|
92 |
| - // demo the word-level diff |
93 |
| - $result = DiffHelper::calculate( |
94 |
| - $oldFile, |
95 |
| - $newFile, |
96 |
| - 'Inline', |
97 |
| - $diffOptions, |
98 |
| - ['detailLevel' => 'word'] + $rendererOptions |
99 |
| - ); |
| 92 | + // demo the word-level diff |
| 93 | + $result = DiffHelper::calculate( |
| 94 | + $oldFile, |
| 95 | + $newFile, |
| 96 | + 'Inline', |
| 97 | + $diffOptions, |
| 98 | + ['detailLevel' => 'word'] + $rendererOptions |
| 99 | + ); |
100 | 100 |
|
101 |
| - echo $result; |
| 101 | + echo $result; |
102 | 102 |
|
103 | 103 | ?>
|
104 | 104 |
|
105 | 105 | <h1>Character-level Diff</h1>
|
106 | 106 | <?php
|
107 | 107 |
|
108 |
| - // demo the character-level diff |
109 |
| - $result = DiffHelper::calculate( |
110 |
| - $oldFile, |
111 |
| - $newFile, |
112 |
| - 'Inline', |
113 |
| - $diffOptions, |
114 |
| - ['detailLevel' => 'char'] + $rendererOptions |
115 |
| - ); |
| 108 | + // demo the character-level diff |
| 109 | + $result = DiffHelper::calculate( |
| 110 | + $oldFile, |
| 111 | + $newFile, |
| 112 | + 'Inline', |
| 113 | + $diffOptions, |
| 114 | + ['detailLevel' => 'char'] + $rendererOptions |
| 115 | + ); |
116 | 116 |
|
117 |
| - echo $result; |
| 117 | + echo $result; |
118 | 118 |
|
119 | 119 | ?>
|
120 | 120 |
|
121 | 121 | <h1>Side by Side Diff</h1>
|
122 | 122 | <?php
|
123 | 123 |
|
124 |
| - // generate a side by side diff |
125 |
| - $result = DiffHelper::calculateFiles( |
126 |
| - $oldFilePath, |
127 |
| - $newFilePath, |
128 |
| - 'SideBySide', |
129 |
| - $diffOptions, |
130 |
| - $rendererOptions |
131 |
| - ); |
| 124 | + // generate a side by side diff |
| 125 | + $result = DiffHelper::calculateFiles( |
| 126 | + $oldFilePath, |
| 127 | + $newFilePath, |
| 128 | + 'SideBySide', |
| 129 | + $diffOptions, |
| 130 | + $rendererOptions |
| 131 | + ); |
132 | 132 |
|
133 |
| - echo $result; |
| 133 | + echo $result; |
134 | 134 |
|
135 | 135 | ?>
|
136 | 136 |
|
137 | 137 | <h1>Inline Diff</h1>
|
138 | 138 | <?php
|
139 | 139 |
|
140 |
| - // generate an inline diff |
141 |
| - $result = DiffHelper::calculateFiles( |
142 |
| - $oldFilePath, |
143 |
| - $newFilePath, |
144 |
| - 'Inline', |
145 |
| - $diffOptions, |
146 |
| - $rendererOptions |
147 |
| - ); |
| 140 | + // generate an inline diff |
| 141 | + $result = DiffHelper::calculateFiles( |
| 142 | + $oldFilePath, |
| 143 | + $newFilePath, |
| 144 | + 'Inline', |
| 145 | + $diffOptions, |
| 146 | + $rendererOptions |
| 147 | + ); |
148 | 148 |
|
149 |
| - echo $result; |
| 149 | + echo $result; |
150 | 150 |
|
151 | 151 | ?>
|
152 | 152 |
|
153 | 153 | <h1>Unified Diff</h1>
|
154 | 154 | <pre><?php
|
155 | 155 |
|
156 |
| - // generate a unified diff |
157 |
| - $result = DiffHelper::calculateFiles( |
158 |
| - $oldFilePath, |
159 |
| - $newFilePath, |
160 |
| - 'Unified', |
161 |
| - $diffOptions, |
162 |
| - $rendererOptions |
163 |
| - ); |
| 156 | + // generate a unified diff |
| 157 | + $result = DiffHelper::calculateFiles( |
| 158 | + $oldFilePath, |
| 159 | + $newFilePath, |
| 160 | + 'Unified', |
| 161 | + $diffOptions, |
| 162 | + $rendererOptions |
| 163 | + ); |
164 | 164 |
|
165 |
| - echo \htmlspecialchars($result); |
| 165 | + echo \htmlspecialchars($result); |
166 | 166 |
|
167 | 167 | ?></pre>
|
168 | 168 |
|
169 | 169 | <h1>Context Diff</h1>
|
170 | 170 | <pre><?php
|
171 | 171 |
|
172 |
| - // generate a context diff |
173 |
| - $result = DiffHelper::calculateFiles( |
174 |
| - $oldFilePath, |
175 |
| - $newFilePath, |
176 |
| - 'Context', |
177 |
| - $diffOptions, |
178 |
| - $rendererOptions |
179 |
| - ); |
| 172 | + // generate a context diff |
| 173 | + $result = DiffHelper::calculateFiles( |
| 174 | + $oldFilePath, |
| 175 | + $newFilePath, |
| 176 | + 'Context', |
| 177 | + $diffOptions, |
| 178 | + $rendererOptions |
| 179 | + ); |
180 | 180 |
|
181 |
| - echo \htmlspecialchars($result); |
| 181 | + echo \htmlspecialchars($result); |
182 | 182 |
|
183 | 183 | ?></pre>
|
184 | 184 |
|
185 | 185 | <h1>JSON Diff</h1>
|
186 | 186 | <pre><?php
|
187 | 187 |
|
188 |
| - // generate a JSON diff |
189 |
| - $result = DiffHelper::calculateFiles( |
190 |
| - $oldFilePath, |
191 |
| - $newFilePath, |
192 |
| - 'Json', |
193 |
| - $diffOptions, |
194 |
| - ['outputTagAsString' => true] + $rendererOptions |
195 |
| - ); |
196 |
| - |
197 |
| - $beautified = \json_encode( |
198 |
| - \json_decode($result, true), |
199 |
| - \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT |
200 |
| - ); |
201 |
| - |
202 |
| - echo $beautified; |
| 188 | + // generate a JSON diff |
| 189 | + $result = DiffHelper::calculateFiles( |
| 190 | + $oldFilePath, |
| 191 | + $newFilePath, |
| 192 | + 'Json', |
| 193 | + $diffOptions, |
| 194 | + ['outputTagAsString' => true] + $rendererOptions |
| 195 | + ); |
| 196 | + |
| 197 | + $beautified = \json_encode( |
| 198 | + \json_decode($result, true), |
| 199 | + \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT |
| 200 | + ); |
| 201 | + |
| 202 | + echo $beautified; |
203 | 203 |
|
204 | 204 | ?></pre>
|
205 | 205 | </body>
|
|
0 commit comments