This class renders the diff in classic "unified diff" format.
Copyright 2004-2016 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you did
not receive this file, see http://www.horde.org/licenses/lgpl21.
/** * Generates a diff of the contributed code to the original * * @param string $parentCode * @param string $currentCode * * @return string */ public function generateDiff($parentCode, $currentCode) { $diff = new \Horde_Text_Diff('auto', array(explode(PHP_EOL, $parentCode), explode(PHP_EOL, $currentCode))); $renderer = new \Horde_Text_Diff_Renderer_Unified(); return $renderer->render($diff); }
/** * Update the package.xml file for this component. * * @param string $action The action to perform. Either "update", "diff", * or "print". * @param array $options Options for this operation. * * @return NULL */ public function updatePackageXml($action, $options) { if (!file_exists($this->getPackageXmlPath())) { $this->getFactory()->createPackageFile($this->_directory); } $package_xml = $this->getPackageXml(); /* Skip updating if this is a PECL package. */ if (!$package_xml->findNode('/p:package/p:providesextension')) { $package_xml->updateContents($this->getFactory()->createContentList($this->_directory), $options); } switch ($action) { case 'print': return (string) $package_xml; case 'diff': $new = (string) $package_xml; $old = file_get_contents($this->getPackageXmlPath()); $renderer = new Horde_Text_Diff_Renderer_Unified(); return $renderer->render(new Horde_Text_Diff('auto', array(explode("\n", $old), explode("\n", $new)))); default: file_put_contents($this->getPackageXmlPath(), (string) $package_xml); if (!empty($options['commit'])) { $options['commit']->add($this->getPackageXmlPath(), $this->_directory); } return true; } }
public function testPearBug6251() { /* too much trailing context */ $oldtext = <<<EOT Original Text ss ttt EOT; $newtext = <<<EOT Modified Text ss ttt EOT; $patch = "@@ -1,5 +1,5 @@\n \n-Original Text\n+Modified Text\n \n \n \n"; $test = array(explode("\n", $oldtext), explode("\n", $newtext)); $diff = new Horde_Text_Diff('Native', $test); $renderer = new Horde_Text_Diff_Renderer_Unified(array('leading_context_lines' => 3, 'trailing_context_lines' => 3)); $this->assertEquals($patch, $renderer->render($diff)); }