-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-comparison.php
More file actions
57 lines (41 loc) · 1.43 KB
/
file-comparison.php
File metadata and controls
57 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
/*
* This file is part of the ALTO library.
*
* © 2025–present Simon André
*
* For full copyright and license information, please see
* the LICENSE file distributed with this source code.
*/
require __DIR__.'/../../vendor/autoload.php';
use Alto\Code\Diff\Diff;
use Alto\Code\Diff\Model\DiffBundle;
use Alto\Code\Diff\Model\DiffFile;
use Alto\Code\Diff\Renderer\UnifiedRenderer;
echo "=== Compare Two Files (using fixtures) ===\n";
$oldPath = __DIR__.'/fixtures/file1.txt';
$newPath = __DIR__.'/fixtures/file2.txt';
$oldContent = file_get_contents($oldPath);
$newContent = file_get_contents($newPath);
$result = Diff::build()
->contextLines(3)
->compare($oldContent, $newContent);
$renderer = new UnifiedRenderer('fixtures/file1.txt', 'fixtures/file2.txt');
echo $renderer->render($result)."\n";
echo "\n=== Compare Multiple Files (Memory Bundle) ===\n";
// Define content for virtual files
$file1Old = "A\nB\nC";
$file1New = "A\nX\nC";
$file2Old = 'Foo';
$file2New = 'Bar';
$diffFiles = [];
// Compare file1
$result1 = Diff::build()->compare($file1Old, $file1New);
$diffFiles[] = new DiffFile('src/File1.php', 'src/File1.php', $result1);
// Compare file2
$result2 = Diff::build()->compare($file2Old, $file2New);
$diffFiles[] = new DiffFile('src/File2.php', 'src/File2.php', $result2);
$bundle = new DiffBundle($diffFiles);
$renderer = new UnifiedRenderer();
echo $renderer->render($bundle)."\n";