diff --git a/apps/advanced/composer.json b/apps/advanced/composer.json index 94a60be..2d5b987 100644 --- a/apps/advanced/composer.json +++ b/apps/advanced/composer.json @@ -13,12 +13,6 @@ "source": "https://github.com/yiisoft/yii2" }, "minimum-stability": "dev", - "repositories": [ - { - "type": "pear", - "url": "http://pear.horde.org" - } - ], "require": { "php": ">=5.3.0", "yiisoft/yii2": "dev-master", diff --git a/apps/basic/composer.json b/apps/basic/composer.json index f372912..dd50b69 100644 --- a/apps/basic/composer.json +++ b/apps/basic/composer.json @@ -13,12 +13,6 @@ "source": "https://github.com/yiisoft/yii2" }, "minimum-stability": "dev", - "repositories": [ - { - "type": "pear", - "url": "http://pear.horde.org" - } - ], "require": { "php": ">=5.3.0", "yiisoft/yii2": "dev-master", diff --git a/framework/composer.json b/framework/composer.json index 2258309..89d6064 100644 --- a/framework/composer.json +++ b/framework/composer.json @@ -63,17 +63,11 @@ "irc": "irc://irc.freenode.net/yii", "source": "https://github.com/yiisoft/yii2" }, - "repositories": [ - { - "type": "pear", - "url": "http://pear.horde.org" - } - ], "require": { "php": ">=5.3.7", "ext-mbstring": "*", "lib-pcre": "*", - "pear-pear.horde.org/horde_text_diff": "2.0.*", + "phpspec/php-diff": "1.0.*", "ezyang/htmlpurifier": "4.5.*" }, "autoload": { diff --git a/framework/yii/gii/CodeFile.php b/framework/yii/gii/CodeFile.php index bd77df6..d3dcd43 100644 --- a/framework/yii/gii/CodeFile.php +++ b/framework/yii/gii/CodeFile.php @@ -143,8 +143,7 @@ class CodeFile extends Object if (in_array($type, array('jpg', 'gif', 'png', 'exe'))) { return false; } elseif ($this->operation === self::OP_OVERWRITE) { - list ($diff, $addedLines, $deletedLines) = StringHelper::diff(file($this->path), $this->content); - return $diff; + return StringHelper::diff(file($this->path), $this->content); } else { return ''; } diff --git a/framework/yii/gii/assets/main.css b/framework/yii/gii/assets/main.css index 62d0972..11615a1 100644 --- a/framework/yii/gii/assets/main.css +++ b/framework/yii/gii/assets/main.css @@ -111,3 +111,88 @@ body { background: lightgreen; text-decoration: none; } + + +.Differences { + width: 100%; + border-collapse: collapse; + border-spacing: 0; + empty-cells: show; +} + +.Differences thead { + display: none; +} + +.Differences tbody th { + text-align: right; + background: #FAFAFA; + padding: 1px 2px; + border-right: 1px solid #eee; + vertical-align: top; + font-size: 13px; + font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; + font-weight: normal; + color: #999; + width: 5px; +} + +.Differences td { + padding: 1px 2px; + font-size: 13px; + font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; +} + +.DifferencesSideBySide .ChangeInsert td.Left { + background: #dfd; +} + +.DifferencesSideBySide .ChangeInsert td.Right { + background: #cfc; +} + +.DifferencesSideBySide .ChangeDelete td.Left { + background: #f88; +} + +.DifferencesSideBySide .ChangeDelete td.Right { + background: #faa; +} + +.DifferencesSideBySide .ChangeReplace .Left { + background: #fe9; +} + +.DifferencesSideBySide .ChangeReplace .Right { + background: #fd8; +} + +.Differences ins, .Differences del { + text-decoration: none; +} + +.DifferencesSideBySide .ChangeReplace ins, .DifferencesSideBySide .ChangeReplace del { + background: #fc0; +} + +.Differences .Skipped { + background: #f7f7f7; +} + +.DifferencesInline .ChangeReplace .Left, +.DifferencesInline .ChangeDelete .Left { + background: #fdd; +} + +.DifferencesInline .ChangeReplace .Right, +.DifferencesInline .ChangeInsert .Right { + background: #dfd; +} + +.DifferencesInline .ChangeReplace ins { + background: #9e9; +} + +.DifferencesInline .ChangeReplace del { + background: #e99; +} diff --git a/framework/yii/gii/views/default/diff.php b/framework/yii/gii/views/default/diff.php index 53763ab..6ec990d 100644 --- a/framework/yii/gii/views/default/diff.php +++ b/framework/yii/gii/views/default/diff.php @@ -10,8 +10,6 @@
Identical.
-
-
-
+ diff --git a/framework/yii/helpers/StringHelperBase.php b/framework/yii/helpers/StringHelperBase.php index c72fabc..54dabda 100644 --- a/framework/yii/helpers/StringHelperBase.php +++ b/framework/yii/helpers/StringHelperBase.php @@ -71,18 +71,17 @@ class StringHelperBase /** * Compares two strings or string arrays, and return their differences. - * This is a wrapper of the Horde_Text_Diff package. + * This is a wrapper of the [phpspec/php-diff](https://packagist.org/packages/phpspec/php-diff) package. * @param string|array $lines1 the first string or string array to be compared. If it is a string, * it will be converted into a string array by breaking at newlines. * @param string|array $lines2 the second string or string array to be compared. If it is a string, * it will be converted into a string array by breaking at newlines. - * @param string $format the output format. It must be 'context', 'inline', or 'unified'. - * @param string $engine the diff engine to be used. It must be 'auto', 'native', 'shell', 'string', or 'xdiff'. - * @return array the comparison result. The first element is a string representing the detailed comparison result. - * The second and the third elements represent the number of added lines and deleted lines, respectively. - * @throws InvalidParamException if the format or the engine is invalid. + * @param string $format the output format. It must be 'inline', 'unified', 'context', 'side-by-side', or 'array'. + * @return string|array the comparison result. An array is returned if `$format` is 'array'. For all other + * formats, a string is returned. + * @throws InvalidParamException if the format is invalid. */ - public static function diff($lines1, $lines2, $format = 'inline', $engine = 'auto') + public static function diff($lines1, $lines2, $format = 'inline') { if (!is_array($lines1)) { $lines1 = explode("\n", $lines1); @@ -90,27 +89,32 @@ class StringHelperBase if (!is_array($lines2)) { $lines2 = explode("\n", $lines2); } + foreach ($lines1 as $i => $line) { + $lines1[$i] = rtrim($line, "\r\n"); + } + foreach ($lines2 as $i => $line) { + $lines2[$i] = rtrim($line, "\r\n"); + } switch ($format) { - case 'context': - $renderer = new \Horde_Text_Diff_Renderer_Context(); - break; case 'inline': - $renderer = new \Horde_Text_Diff_Renderer_Inline(); + $renderer = new \Diff_Renderer_Html_Inline(); + break; + case 'array': + $renderer = new \Diff_Renderer_Html_Array(); + break; + case 'side-by-side': + $renderer = new \Diff_Renderer_Html_SideBySide(); + break; + case 'context': + $renderer = new \Diff_Renderer_Text_Context(); break; case 'unified': - $renderer = new \Horde_Text_Diff_Renderer_Unified(); + $renderer = new \Diff_Renderer_Text_Unified(); break; default: - throw new InvalidParamException("Output format must be 'context', 'inline' or 'unified'."); - } - if (!in_array($engine, array('auto', 'native', 'shell', 'string', 'xdiff'))) { - throw new InvalidParamException("Engine must be 'auto', 'native', 'shell', 'string' or 'xdiff'."); + throw new InvalidParamException("Output format must be 'inline', 'side-by-side', 'array', 'context' or 'unified'."); } - $diff = new \Horde_Text_Diff($engine, array($lines1, $lines2)); - return array( - $renderer->render($diff), - $diff->countAddedLines(), - $diff->countDeletedLines(), - ); + $diff = new \Diff($lines1, $lines2); + return $diff->render($renderer); } }