本文整理汇总了PHP中Diff::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Diff::render方法的具体用法?PHP Diff::render怎么用?PHP Diff::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Diff
的用法示例。
在下文中一共展示了Diff::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: diff
/**
* Get the difference between two files
*
* @static
* @access private
* @param string $a The path to the existing file
* @param string $b The path to the new (replacement) file
* @return string The unified diff between the two
*/
private static function diff($a, $b)
{
$a_code = explode("\n", file_get_contents($a));
$b_code = explode("\n", file_get_contents($b));
$diff = new \Diff($b_code, $a_code, array('ignoreWhitespace' => TRUE, 'ignoreNewLines' => TRUE));
return $diff->render(new \Diff_Renderer_Text_Unified());
}
示例2: buildPatch
public function buildPatch($originalFile, $modfiedFileName, PatchBuffer $buffer)
{
if (!$buffer->isModified()) {
return '';
}
$diff = new \Diff($buffer->getOriginalContents(), $buffer->getModifiedContents());
$renderer = new \Diff_Renderer_Text_Unified();
return "--- {$originalFile}\n" . "+++ {$modfiedFileName}\n" . $diff->render($renderer);
}
示例3: testReplace
public function testReplace()
{
$old = ['first', 'equal'];
$new = ['second', 'equal'];
$diff = new \Diff($old, $new);
$renderer = new \VisualAppeal\Connect\Extensions\DiffRenderer();
$render = @$diff->render($renderer);
$this->assertContains('diff-change-replace', $render);
}
示例4: compareVersions
/**
* Show difference between two versions.
*
* @param \App\Version
* @param \App\Version
* @return void
*/
protected function compareVersions(Version $before, Version $after)
{
// Parse source
$beforeArray = explode("\n", $before->source);
$afterArray = explode("\n", $after->source);
// Compare versions
$diff = new \Diff($beforeArray, $afterArray, $options = []);
// Load view
return view('version.compare', ['title' => _('Versions'), 'subtitle' => _('Compare'), 'before' => $before, 'after' => $after, 'sideBySideDiff' => $diff->Render(new \Diff_Renderer_Html_SideBySide()), 'inlineDiff' => $diff->render(new \Diff_Renderer_Html_Inline())]);
}
示例5: compare
public function compare(IResource $resourceA, IResource $resourceB)
{
$data_a = $resourceA->getCleanFields();
$data_b = $resourceB->getCleanFields();
$a = explode("\n", $data_a['snippet']);
$b = explode("\n", $data_b['snippet']);
$d = new \Diff($a, $b, []);
$renderer = new \Diff_Renderer_Html_SideBySide();
$diffc = $d->render($renderer);
return !empty($diffc);
}
示例6: getDiffHtml
public function getDiffHtml()
{
$old = explode("\n", $this->old_value);
$new = explode("\n", $this->new_value);
foreach ($old as $i => $line) {
$old[$i] = rtrim($line, "\r\n");
}
foreach ($new as $i => $line) {
$new[$i] = rtrim($line, "\r\n");
}
$diff = new \Diff($old, $new);
return $diff->render(new \Diff_Renderer_Html_Inline());
}
示例7: assertJsonResponseContent
protected function assertJsonResponseContent($response, $filename)
{
$expectedResponse = file_get_contents(__DIR__ . sprintf('/../Tests/Responses/%s.json', $filename));
$actualResponse = $response->getContent();
$actualResponse = json_encode(json_decode($actualResponse), JSON_PRETTY_PRINT);
$factory = new SimpleFactory();
$matcher = $factory->createMatcher();
$result = $matcher->match($actualResponse, $expectedResponse);
if (!$result) {
echo $matcher->getError();
$expectedResponse = explode(PHP_EOL, (string) $expectedResponse);
$actualResponse = explode(PHP_EOL, (string) $actualResponse);
$diff = new \Diff($expectedResponse, $actualResponse, array());
$renderer = new \Diff_Renderer_Text_Unified();
echo $diff->render($renderer);
}
$this->assertTrue($result);
}
示例8: compare
public function compare($expected, $actual)
{
$expected = explode(PHP_EOL, (string) $expected);
$actual = explode(PHP_EOL, (string) $actual);
$diff = new \Diff($expected, $actual, array());
$renderer = new \Diff_Renderer_Text_Unified();
$text = $diff->render($renderer);
$lines = array();
foreach (explode("\n", $text) as $line) {
if (0 === strpos($line, '-')) {
$lines[] = sprintf('<diff-del>%s</diff-del>', $line);
} elseif (0 === strpos($line, '+')) {
$lines[] = sprintf('<diff-add>%s</diff-add>', $line);
} else {
$lines[] = $line;
}
}
return sprintf("<code>%s%s</code>", PHP_EOL, implode(PHP_EOL, $lines));
}
示例9: diffWithOnline
public function diffWithOnline($file)
{
$localSourceDir = $this->config->getDeployFromDir();
$remoteSourceDir = $this->config->getTargetWorkspace();
$cmd[] = "cat {$remoteSourceDir}/{$file}";
$command = implode(' && ', $cmd);
$host = GlobalHelper::str2arr($this->config->hosts)[0];
if ($this->runRemoteCommand($command, 0, $host)) {
$contentOld = explode(PHP_EOL, substr($this->log, strlen($host . ' : ')));
array_walk($contentOld, function (&$line) {
$line = rtrim($line, "\r\n");
});
} else {
$contentOld = [];
}
$contentNew = file("{$localSourceDir}/{$file}");
array_walk($contentNew, function (&$line) {
$line = rtrim($line, "\r\n");
});
$diff = new \Diff($contentOld, $contentNew);
return $diff->render(new \Diff_Renderer_Html_Array());
}
示例10: diff
public function diff()
{
$this->test();
if ($this->wasSuccessfull()) {
return;
}
global $HTML;
$HTML->p('Diff', '.label');
$a = explode("\n", $this->prediction);
$b = explode("\n", $this->_result);
$options = array();
// Initialize the diff class
$diff = new \Diff($a, $b, $options);
$renderer = new \Diff_Renderer_Html_Inline();
echo $diff->render($renderer);
}
示例11: theResponseJSONMatches
/**
* @Then /^the response JSON matches "([^"]*)"$/
*
* @param string $expectedJsonFilePath
*
* @throws \Exception
*/
public function theResponseJSONMatches($expectedJsonFilePath)
{
$factory = new PHPMatcherFactory();
$matcher = $factory->createMatcher();
$responseJson = json_encode(json_decode($this->getResponseWithAssertion()->getContent()), JSON_PRETTY_PRINT);
$expectedJson = file_get_contents($this->getFilePath($expectedJsonFilePath));
if ($matcher->match($responseJson, $expectedJson) === false) {
echo $matcher->getError();
$difference = new \Diff(explode(PHP_EOL, $expectedJson), explode(PHP_EOL, $responseJson));
echo $difference->render(new \Diff_Renderer_Text_Unified());
throw new \Exception('Response JSON did not match.');
}
}
示例12: getDiff
public function getDiff($field, $new, $old)
{
$config = ['ignoreNewLines' => true, 'ignoreWhitespace' => true, 'ignoreCase' => true];
$diff = new \Diff((array) $old, (array) $new, $config);
return $diff->render(new \Diff_Renderer_Html_SideBySide());
}
示例13: diffAction
/**
* Shows a visual diff of what has changed
*/
public function diffAction()
{
$id = (int) $this->dispatcher->getParam('id');
$revision = (int) $this->dispatcher->getParam('revision');
$diffVersion = Versions::findFirst(array('page_id = :id: AND version = :revision:', 'bind' => array('id' => $id, 'revision' => $revision)));
if ($diffVersion === false) {
return $this->dispatcher->forward(array('action' => 'error404'));
}
$currentVersion = Pages::findFirst($id);
$diffEngine = new \Diff(explode("\n", $diffVersion->content), explode("\n", $currentVersion->content), []);
$renderer = new \Diff_Renderer_Html_SideBySide();
$this->view->diff = $diffEngine->render($renderer);
$this->view->page = $currentVersion;
$this->view->revision = $diffVersion->version;
$this->view->title = "diff – " . $currentVersion->title;
}
示例14: htmlspecialchars
// Initialize the diff class
$diff = new Diff($a, $b, $options);
?>
<h2>Side by Side Diff</h2>
<?php
// Generate a side by side diff
require_once __DIR__ . '/../lib/Diff/Renderer/Html/SideBySide.php';
$renderer = new Diff_Renderer_Html_SideBySide();
echo $diff->Render($renderer);
?>
<h2>Inline Diff</h2>
<?php
// Generate an inline diff
require_once __DIR__ . '/../lib/Diff/Renderer/Html/Inline.php';
$renderer = new Diff_Renderer_Html_Inline();
echo $diff->render($renderer);
?>
<h2>Unified Diff</h2>
<pre><?php
// Generate a unified diff
require_once __DIR__ . '/../lib/Diff/Renderer/Text/Unified.php';
$renderer = new Diff_Renderer_Text_Unified();
echo htmlspecialchars($diff->render($renderer));
?>
</pre>
<h2>Context Diff</h2>
<pre><?php
// Generate a context diff
require_once __DIR__ . '/../lib/Diff/Renderer/Text/Context.php';
$renderer = new Diff_Renderer_Text_Context();
echo htmlspecialchars($diff->render($renderer));
示例15: compareContent
/**
* Compare given content with the subject's one in the given language.
*
* @param mixed $subject
* @param array $content
* @param string $language
* @param bool $original
*
* @return array
*/
protected function compareContent($subject, array $content, $language, $original = true)
{
$properties = array_keys($content);
$values = $this->getProperties($subject, $properties, $language);
$diffs = [];
$renderer = new \Diff_Renderer_Html_SideBySide();
foreach ($values as $property => $value) {
$a = [$value];
$b = [$content[$property]];
if ($original) {
$b = [$content[$property]['original_phrase']];
}
$diff = new \Diff($a, $b);
$diffs[$property] = $diff->render($renderer);
}
return $diffs;
}