|
17 | 17 | <body>
|
18 | 18 | <?php
|
19 | 19 |
|
20 |
| - // include two sample files for comparison |
21 |
| - $oldFilePath = __DIR__ . '/old_file.txt'; |
22 |
| - $newFilePath = __DIR__ . '/new_file.txt'; |
23 |
| - $oldFile = \file_get_contents($oldFilePath); |
24 |
| - $newFile = \file_get_contents($newFilePath); |
| 20 | + // the two sample files for comparison |
| 21 | + $oldFile = __DIR__ . '/old_file.txt'; |
| 22 | + $newFile = __DIR__ . '/new_file.txt'; |
| 23 | + $oldString = \file_get_contents($oldFile); |
| 24 | + $newString = \file_get_contents($newFile); |
25 | 25 |
|
26 | 26 | // options for Diff class
|
27 | 27 | $diffOptions = [
|
|
67 | 67 |
|
68 | 68 | // demo the no-inline-detail diff
|
69 | 69 | $inlineResult = DiffHelper::calculate(
|
70 |
| - $oldFile, |
71 |
| - $newFile, |
| 70 | + $oldString, |
| 71 | + $newString, |
72 | 72 | 'Inline',
|
73 | 73 | $diffOptions,
|
74 | 74 | ['detailLevel' => 'none'] + $rendererOptions
|
|
83 | 83 |
|
84 | 84 | // demo the word-level diff
|
85 | 85 | $inlineResult = DiffHelper::calculate(
|
86 |
| - $oldFile, |
87 |
| - $newFile, |
| 86 | + $oldString, |
| 87 | + $newString, |
88 | 88 | 'Inline',
|
89 | 89 | $diffOptions,
|
90 | 90 | ['detailLevel' => 'line'] + $rendererOptions
|
|
99 | 99 |
|
100 | 100 | // demo the word-level diff
|
101 | 101 | $inlineResult = DiffHelper::calculate(
|
102 |
| - $oldFile, |
103 |
| - $newFile, |
| 102 | + $oldString, |
| 103 | + $newString, |
104 | 104 | 'Inline',
|
105 | 105 | $diffOptions,
|
106 | 106 | ['detailLevel' => 'word'] + $rendererOptions
|
|
115 | 115 |
|
116 | 116 | // demo the character-level diff
|
117 | 117 | $inlineResult = DiffHelper::calculate(
|
118 |
| - $oldFile, |
119 |
| - $newFile, |
| 118 | + $oldString, |
| 119 | + $newString, |
120 | 120 | 'Inline',
|
121 | 121 | $diffOptions,
|
122 | 122 | ['detailLevel' => 'char'] + $rendererOptions
|
|
131 | 131 |
|
132 | 132 | // generate a side by side diff
|
133 | 133 | $sideBySideResult = DiffHelper::calculateFiles(
|
134 |
| - $oldFilePath, |
135 |
| - $newFilePath, |
| 134 | + $oldFile, |
| 135 | + $newFile, |
136 | 136 | 'SideBySide',
|
137 | 137 | $diffOptions,
|
138 | 138 | $rendererOptions
|
|
147 | 147 |
|
148 | 148 | // generate an inline diff
|
149 | 149 | $inlineResult = DiffHelper::calculateFiles(
|
150 |
| - $oldFilePath, |
151 |
| - $newFilePath, |
| 150 | + $oldFile, |
| 151 | + $newFile, |
152 | 152 | 'Inline',
|
153 | 153 | $diffOptions,
|
154 | 154 | $rendererOptions
|
|
163 | 163 |
|
164 | 164 | // generate a combined diff
|
165 | 165 | $sideBySideResult = DiffHelper::calculateFiles(
|
166 |
| - $oldFilePath, |
167 |
| - $newFilePath, |
| 166 | + $oldFile, |
| 167 | + $newFile, |
168 | 168 | 'Combined',
|
169 | 169 | $diffOptions,
|
170 | 170 | $rendererOptions
|
|
179 | 179 |
|
180 | 180 | // generate a unified diff
|
181 | 181 | $unifiedResult = DiffHelper::calculateFiles(
|
182 |
| - $oldFilePath, |
183 |
| - $newFilePath, |
| 182 | + $oldFile, |
| 183 | + $newFile, |
184 | 184 | 'Unified',
|
185 | 185 | $diffOptions,
|
186 | 186 | $rendererOptions
|
|
195 | 195 |
|
196 | 196 | // generate a context diff
|
197 | 197 | $contextResult = DiffHelper::calculateFiles(
|
198 |
| - $oldFilePath, |
199 |
| - $newFilePath, |
| 198 | + $oldFile, |
| 199 | + $newFile, |
200 | 200 | 'Context',
|
201 | 201 | $diffOptions,
|
202 | 202 | $rendererOptions
|
|
211 | 211 |
|
212 | 212 | // generate a JSON diff
|
213 | 213 | $jsonResult = DiffHelper::calculateFiles(
|
214 |
| - $oldFilePath, |
215 |
| - $newFilePath, |
| 214 | + $oldFile, |
| 215 | + $newFile, |
216 | 216 | 'Json',
|
217 | 217 | $diffOptions,
|
218 | 218 | ['outputTagAsString' => true] + $rendererOptions
|
|
0 commit comments