summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Storage/ConfigDiff.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Businessprocess/Storage/ConfigDiff.php')
-rw-r--r--library/Businessprocess/Storage/ConfigDiff.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/library/Businessprocess/Storage/ConfigDiff.php b/library/Businessprocess/Storage/ConfigDiff.php
new file mode 100644
index 0000000..133cfb7
--- /dev/null
+++ b/library/Businessprocess/Storage/ConfigDiff.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Icinga\Module\Businessprocess\Storage;
+
+use ipl\Html\ValidHtml;
+use Jfcherng\Diff\Differ;
+use Jfcherng\Diff\Factory\RendererFactory;
+
+class ConfigDiff implements ValidHtml
+{
+ protected $a;
+
+ protected $b;
+
+ protected $diff;
+ protected $opcodes;
+
+ protected function __construct($a, $b)
+ {
+ 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 Differ($this->a, $this->b, $options);
+ }
+
+ /**
+ * @return string
+ */
+ public function render()
+ {
+ return $this->renderHtmlSideBySide();
+ }
+
+ public function renderHtmlSideBySide()
+ {
+ $renderer = RendererFactory::make('SideBySide');
+ return $renderer->render($this->diff);
+ }
+
+ public function renderHtmlInline()
+ {
+ $renderer = RendererFactory::make('Inline');
+ return $renderer->render($this->diff);
+ }
+
+ public function renderTextContext()
+ {
+ $renderer = RendererFactory::make('Context');
+ return $renderer->render($this->diff);
+ }
+
+ public function renderTextUnified()
+ {
+ $renderer = RendererFactory::make('Unified');
+ return $renderer->render($this->diff);
+ }
+
+ public static function create($a, $b)
+ {
+ $diff = new static($a, $b);
+ return $diff;
+ }
+}