| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
include __DIR__ . '/../vendor/autoload.php'; |
| 6 |
|
| 7 |
use Jfcherng\Diff\Differ; |
| 8 |
use Jfcherng\Diff\Renderer\RendererConstant; |
| 9 |
|
| 10 |
// the two sample files for comparison |
| 11 |
$oldFile = __DIR__ . '/old_file.txt'; |
| 12 |
$newFile = __DIR__ . '/new_file.txt'; |
| 13 |
$oldString = file_get_contents($oldFile); |
| 14 |
$newString = file_get_contents($newFile); |
| 15 |
|
| 16 |
// options for Diff class |
| 17 |
$diffOptions = [ |
| 18 |
// show how many neighbor lines |
| 19 |
// Differ::CONTEXT_ALL can be used to show the whole file |
| 20 |
'context' => 1, |
| 21 |
// ignore case difference |
| 22 |
'ignoreCase' => false, |
| 23 |
// ignore line ending difference |
| 24 |
'ignoreLineEnding' => false, |
| 25 |
// ignore whitespace difference |
| 26 |
'ignoreWhitespace' => false, |
| 27 |
// if the input sequence is too long, it will just gives up (especially for char-level diff) |
| 28 |
'lengthLimit' => 2000, |
| 29 |
// if truthy, when inputs are identical, the whole inputs will be rendered in the output |
| 30 |
'fullContextIfIdentical' => false, |
| 31 |
]; |
| 32 |
|
| 33 |
// options for renderer class |
| 34 |
$rendererOptions = [ |
| 35 |
// how detailed the rendered HTML is? (none, line, word, char) |
| 36 |
'detailLevel' => 'line', |
| 37 |
// renderer language: eng, cht, chs, jpn, ... |
| 38 |
// or an array which has the same keys with a language file |
| 39 |
// check the "Custom Language" section in the readme for more advanced usage |
| 40 |
'language' => 'eng', |
| 41 |
// show line numbers in HTML renderers |
| 42 |
'lineNumbers' => true, |
| 43 |
// show a separator between different diff hunks in HTML renderers |
| 44 |
'separateBlock' => true, |
| 45 |
// show the (table) header |
| 46 |
'showHeader' => true, |
| 47 |
// convert spaces/tabs into HTML codes like `<span class="ch sp"> </span>` |
| 48 |
// and the frontend is responsible for rendering them with CSS. |
| 49 |
// when using this, "spacesToNbsp" should be false and "tabSize" is not respected. |
| 50 |
'spaceToHtmlTag' => false, |
| 51 |
// the frontend HTML could use CSS "white-space: pre;" to visualize consecutive whitespaces |
| 52 |
// but if you want to visualize them in the backend with " ", you can set this to true |
| 53 |
'spacesToNbsp' => false, |
| 54 |
// HTML renderer tab width (negative = do not convert into spaces) |
| 55 |
'tabSize' => 4, |
| 56 |
// this option is currently only for the Combined renderer. |
| 57 |
// it determines whether a replace-type block should be merged or not |
| 58 |
// depending on the content changed ratio, which values between 0 and 1. |
| 59 |
'mergeThreshold' => 0.8, |
| 60 |
// this option is currently only for the Unified and the Context renderers. |
| 61 |
// RendererConstant::CLI_COLOR_AUTO = colorize the output if possible (default) |
| 62 |
// RendererConstant::CLI_COLOR_ENABLE = force to colorize the output |
| 63 |
// RendererConstant::CLI_COLOR_DISABLE = force not to colorize the output |
| 64 |
'cliColorization' => RendererConstant::CLI_COLOR_AUTO, |
| 65 |
// this option is currently only for the Json renderer. |
| 66 |
// internally, ops (tags) are all int type but this is not good for human reading. |
| 67 |
// set this to "true" to convert them into string form before outputting. |
| 68 |
'outputTagAsString' => false, |
| 69 |
// this option is currently only for the Json renderer. |
| 70 |
// it controls how the output JSON is formatted. |
| 71 |
// see available options on https://www.php.net/manual/en/function.json-encode.php |
| 72 |
'jsonEncodeFlags' => \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE, |
| 73 |
// this option is currently effective when the "detailLevel" is "word" |
| 74 |
// characters listed in this array can be used to make diff segments into a whole |
| 75 |
// for example, making "<del>good</del>-<del>looking</del>" into "<del>good-looking</del>" |
| 76 |
// this should bring better readability but set this to empty array if you do not want it |
| 77 |
'wordGlues' => [' ', '-'], |
| 78 |
// change this value to a string as the returned diff if the two input strings are identical |
| 79 |
'resultForIdenticals' => null, |
| 80 |
// extra HTML classes added to the DOM of the diff container |
| 81 |
'wrapperClasses' => ['diff-wrapper'], |
| 82 |
]; |