blob: 495151e41cb2259615573673e6ae9dab6d7a7473 (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
namespace Icinga\Module\Businessprocess\Storage;
use Diff;
use Diff_Renderer_Html_Inline;
use Diff_Renderer_Html_SideBySide;
use Diff_Renderer_Text_Context;
use Diff_Renderer_Text_Unified;
use ipl\Html\ValidHtml;
class ConfigDiff implements ValidHtml
{
protected $a;
protected $b;
protected $diff;
protected $opcodes;
protected function __construct($a, $b)
{
$this->requireVendorLib('Diff.php');
if (empty($a)) {
$this->a = array();
} else {
$this->a = explode("\n", (string) $a);
}
if (empty($b)) {
$this->b = array();
} else {
$this->b = explode("\n", (string) $b);
}
$options = array(
'context' => 5,
// 'ignoreWhitespace' => true,
// 'ignoreCase' => true,
);
$this->diff = new Diff($this->a, $this->b, $options);
}
/**
* @return string
*/
public function render()
{
return $this->renderHtmlSideBySide();
}
public function renderHtmlSideBySide()
{
$this->requireVendorLib('Diff/Renderer/Html/SideBySide.php');
$renderer = new Diff_Renderer_Html_SideBySide;
return $this->diff->render($renderer);
}
public function renderHtmlInline()
{
$this->requireVendorLib('Diff/Renderer/Html/Inline.php');
$renderer = new Diff_Renderer_Html_Inline;
return $this->diff->render($renderer);
}
public function renderTextContext()
{
$this->requireVendorLib('Diff/Renderer/Text/Context.php');
$renderer = new Diff_Renderer_Text_Context;
return $this->diff->render($renderer);
}
public function renderTextUnified()
{
$this->requireVendorLib('Diff/Renderer/Text/Unified.php');
$renderer = new Diff_Renderer_Text_Unified;
return $this->diff->render($renderer);
}
protected function requireVendorLib($file)
{
require_once dirname(dirname(__DIR__)) . '/vendor/php-diff/lib/' . $file;
}
public static function create($a, $b)
{
$diff = new static($a, $b);
return $diff;
}
}
|