2015-09-14 13:37:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director;
|
|
|
|
|
2015-11-05 12:30:07 +01:00
|
|
|
use Diff;
|
|
|
|
use Diff_Renderer_Html_Inline;
|
|
|
|
use Diff_Renderer_Html_SideBySide;
|
|
|
|
use Diff_Renderer_Text_Context;
|
|
|
|
use Diff_Renderer_Text_Unified;
|
2015-09-14 13:37:27 +02:00
|
|
|
use Icinga\Application\Benchmark;
|
|
|
|
|
|
|
|
class ConfigDiff
|
|
|
|
{
|
|
|
|
protected $a;
|
|
|
|
|
|
|
|
protected $b;
|
|
|
|
|
|
|
|
protected $diff;
|
|
|
|
protected $opcodes;
|
|
|
|
|
|
|
|
protected function __construct($a, $b)
|
|
|
|
{
|
2015-11-05 12:30:07 +01:00
|
|
|
require_once dirname(__DIR__) . '/vendor/php-diff/lib/Diff.php';
|
2015-09-14 13:37:27 +02:00
|
|
|
|
2015-11-05 12:30:07 +01:00
|
|
|
$this->a = explode("\n", (string) $a);
|
|
|
|
$this->b = explode("\n", (string) $b);
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
// 'ignoreWhitespace' => true,
|
|
|
|
// 'ignoreCase' => true,
|
|
|
|
);
|
|
|
|
$this->diff = new Diff($this->a, $this->b, $options);
|
2015-09-14 13:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function renderHtml()
|
|
|
|
{
|
2015-11-05 12:30:07 +01:00
|
|
|
return $this->renderHtmlSideBySide();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderHtmlSideBySide()
|
|
|
|
{
|
|
|
|
require_once dirname(__DIR__) . '/vendor/php-diff/lib/Diff/Renderer/Html/SideBySide.php';
|
|
|
|
$renderer = new Diff_Renderer_Html_SideBySide;
|
|
|
|
return $this->diff->Render($renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderHtmlInline()
|
|
|
|
{
|
|
|
|
require_once dirname(__DIR__) . '/vendor/php-diff/lib/Diff/Renderer/Html/Inline.php';
|
|
|
|
$renderer = new Diff_Renderer_Html_Inline;
|
|
|
|
return $this->diff->Render($renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderTextContext()
|
|
|
|
{
|
|
|
|
require_once dirname(__DIR__) . '/vendor/php-diff/lib/Diff/Renderer/Text/Context.php';
|
|
|
|
$renderer = new Diff_Renderer_Text_Context;
|
|
|
|
return $this->diff->Render($renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderTextUnified()
|
|
|
|
{
|
|
|
|
require_once dirname(__DIR__) . '/vendor/php-diff/lib/Diff/Renderer/Text/Context.php';
|
|
|
|
$renderer = new Diff_Renderer_Text_Context;
|
|
|
|
return $this->diff->Render($renderer);
|
2015-09-14 13:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->renderHtml();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function create($a, $b)
|
|
|
|
{
|
|
|
|
$diff = new static($a, $b);
|
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
}
|