diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..fdade2f6
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,4 @@
+tests export-ignore
+.editorconfig export-ignore
+.gitattributes export-ignore
+phpcs.xml export-ignore
diff --git a/.gitignore b/.gitignore
index 9e1ec532..ddbe8d8f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,7 +4,11 @@
### Composer ###
composer.phar
+/codeCoverage
/vendor/
+/composer.lock
+/.phpunit.result.cache
+
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
@@ -72,4 +76,3 @@ local.properties
# End of https://www.gitignore.io/api/windows,eclipse,composer
-/composer.lock
diff --git a/LICENSE b/LICENSE
index 88d00098..78654c0d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -12,7 +12,7 @@ modification, are permitted provided that the following conditions are met:
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- - Neither the name of the Chris Boulton nor the names of its contributors
+ - Neither the name of the Mario Brandt nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
diff --git a/README.md b/README.md
index 67be32fa..349971fd 100644
--- a/README.md
+++ b/README.md
@@ -1,21 +1,25 @@
# PHP Diff Class
-[](https://insight.sensiolabs.com/projects/aa609edb-cdb1-45cf-ad51-afbdab48f6a1) [](https://www.codacy.com/app/leet31337/php-diff)
-
-[](https://github.com/JBlond/php-diff/releases) [](https://packagist.org/packages/jblond/php-diff)
+[](https://app.codacy.com/gh/JBlond/php-diff/dashboard)
+[](https://github.com/JBlond/php-diff/releases)
+[](https://packagist.org/packages/jblond/php-diff)
## Introduction
-A comprehensive library for generating differences between two hashable objects (strings or arrays).
-Generated differences can be rendered in all of the standard formats including:
+A comprehensive library for generating differences between two hashable
+objects (strings or arrays). Generated differences can be rendered in all the
+standard formats including:
+
* Unified
* Context
-* Inline HTML
* Side by Side HTML
* Unified HTML
+* Unified Commandline colored output
+* JSON
-The logic behind the core of the diff engine (ie, the sequence matcher) is primarily based on the Python difflib
-package. The reason for doing so is primarily because of its high degree of accuracy.
+The logic behind the core of the diff engine (ie, the sequence matcher) is
+primarily based on the Python difflib package. The reason for doing so is
+primarily because of its high degree of accuracy.
## Install
@@ -23,81 +27,131 @@ package. The reason for doing so is primarily because of its high degree of accu
composer require jblond/php-diff
```
+### Install for cli support
+
+For cli usage you need to install the suggested `jblond/php-cli` package.
+
+## Documentation
+
+See the [Wiki](https://github.com/JBlond/php-diff/wiki) for
+
+* [Getting started](https://github.com/JBlond/php-diff/wiki/1.-Getting-Started)
+* [Parameters and Options](https://github.com/JBlond/php-diff/wiki/2.-Parameters-and-Options)
+* [Custom Renderer](https://github.com/JBlond/php-diff/wiki/3.-Custom-Renderer)
+* [Styling](https://github.com/JBlond/php-diff/wiki/4.-Styling)
+
+## Changelog
+
+[Changelog](changelog.md)
+
## Example Use
```PHP
true,
'ignoreCase' => true,
'context' => 2,
+ 'cliColor' => true, // for cli output
+ 'ignoreLines' => Diff::DIFF_IGNORE_LINE_BLANK,
];
// Initialize the diff class.
-$diff = new Diff($a, $b /*, $options */);
+$diff = new Diff($sampleA, $sampleB /*, $options */);
// Choose Renderer.
$renderer = new SideBySide([
- 'title1' => 'Custom title for OLD version',
- 'title2' => 'Custom title for NEW version',
+ 'title1' => 'Custom title for sample A',
+ 'title2' => 'Custom title for sample B',
]);
-// Show it.
+// Show the output of the difference renderer.
echo $diff->Render($renderer);
+
+// Alternative
+// Show the differences or a message.
+echo $diff->isIdentical() ? 'No differences found.' : '
' . htmlspecialchars($diff->render($renderer)) . ' ' ;
+
```
### Example Output
-A quick usage example can be found in the `example/` directory and under example.php.
+
+File `example.php` contains a quick demo and can be found in the `example/`
+directory. Included is a light and a dark theme.
#### HTML Side By Side Example
-
-#### HTML Inline Example
-
+
+
+
+More Example Pictures
+
#### HTML Unified Example
-
+
+
+
#### Text Unified Example
-
+
+
+
#### Text Context Example
-
+
+
+
+#### Text Unified Console Example
+
+
+
+
+
+HTML Side By Side Dark Theme Example
+
+
+
+
## Requirements
-* PHP 7.2 or greater
+* PHP 7.3 or greater
* PHP Multibyte String
+* [jblond/php-cli](https://github.com/jblond/php-cli) (suggested)
+
+## Contribution, Issues and feature requests
+
+If you found a bug, or have an idea for new functionality, feel free to report
+it on the issue tracker - just use search beforehand.
+[Issue tracker](https://github.com/JBlond/php-diff/issues)
+
+You can also fork this repository and open a PR.
## Merge files using jQuery
-Xiphe has build a jQuery plugin with that you can merge the compared files.
-Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuery-Merge-for-php-diff).
+Xiphe has build a jQuery plugin with that you can merge the compared files. Have
+a look
+at [jQuery-Merge-for-php-diff](https://github.com/DigiLive/jQuery-Merge-for-php-diff)
+.
## Todo
-* Ability to ignore blank line changes
* 3 way diff support
-
+
## Contributors
Contributors since I forked the repo.
-* maxxer
-* Creris
-* jfcherng
-* DigiLive
+* [maxxer](https://github.com/maxxer)
+* [Creris](https://github.com/Creris)
+* [jfcherng](https://github.com/jfcherng)
+* [DigiLive](https://github.com/DigiLive)
### License (BSD License)
diff --git a/htmlSideBySide.png b/assets/htmlSideBySide.png
similarity index 100%
rename from htmlSideBySide.png
rename to assets/htmlSideBySide.png
diff --git a/assets/htmlSidebySideDarkTheme.png b/assets/htmlSidebySideDarkTheme.png
new file mode 100644
index 00000000..2e5ede8a
Binary files /dev/null and b/assets/htmlSidebySideDarkTheme.png differ
diff --git a/assets/htmlUnified.png b/assets/htmlUnified.png
new file mode 100644
index 00000000..a7c100f2
Binary files /dev/null and b/assets/htmlUnified.png differ
diff --git a/textContext.png b/assets/textContext.png
similarity index 100%
rename from textContext.png
rename to assets/textContext.png
diff --git a/textUnified.png b/assets/textUnified.png
similarity index 100%
rename from textUnified.png
rename to assets/textUnified.png
diff --git a/assets/textUnifiedCli.png b/assets/textUnifiedCli.png
new file mode 100644
index 00000000..88058081
Binary files /dev/null and b/assets/textUnifiedCli.png differ
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 00000000..a9ef3e4d
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,216 @@
+# Changelog
+
+## 2.4.0 (2021-08-23)
+
+* Add deprecation notice for missing method ([f494b3a](https://github.com/JBlond/php-diff/commit/f494b3a), [9403eba](https://github.com/JBlond/php-diff/commit/9403eba))
+* Add generator for ignored lines ([6b8662e](https://github.com/JBlond/php-diff/commit/6b8662e), [4dec4ad](https://github.com/JBlond/php-diff/commit/4dec4ad))
+* Add method `generateLinesIgnore` ([6ef61bc](https://github.com/JBlond/php-diff/commit/6ef61bc), [75f5ce0](https://github.com/JBlond/php-diff/commit/75f5ce0))
+* Bump library version und update Changelog ([e88dffb](https://github.com/JBlond/php-diff/commit/e88dffb))
+* Document methods ([9699b5b](https://github.com/JBlond/php-diff/commit/9699b5b), [7d973d3](https://github.com/JBlond/php-diff/commit/7d973d3))
+* Document option `ignoreLines` ([0849a1e](https://github.com/JBlond/php-diff/commit/0849a1e), [19634bb](https://github.com/JBlond/php-diff/commit/19634bb))
+* Document update grammar in the comments ([3f44195](https://github.com/JBlond/php-diff/commit/3f44195))
+* Fix PSR-12 code style ([0bf1a08](https://github.com/JBlond/php-diff/commit/0bf1a08))
+* Optimize Sequence renderer ([576830c](https://github.com/JBlond/php-diff/commit/576830c), [bb0eed4](https://github.com/JBlond/php-diff/commit/bb0eed4))
+* Optimize colorize is only used here ([02cf114](https://github.com/JBlond/php-diff/commit/02cf114))
+* Optimize constant usage ([d0cede3](https://github.com/JBlond/php-diff/commit/d0cede3), [3591515](https://github.com/JBlond/php-diff/commit/3591515))
+* Optimize stripping empty/blank lines ([ea6a2e4](https://github.com/JBlond/php-diff/commit/ea6a2e4), [a239f17](https://github.com/JBlond/php-diff/commit/a239f17))
+
+## v2.3.3 (2021-08-23)
+
+* Bump library version und update Changelog ([f5ce6bc](https://github.com/JBlond/php-diff/commit/f5ce6bc))
+* Fix Autoload test classes only in development ([31b4222](https://github.com/JBlond/php-diff/commit/31b4222))
+
+## v2.3.2 (2021-03-27)
+
+* Bump library version und update Changelog ([8a83b39](https://github.com/JBlond/php-diff/commit/8a83b39))
+* Fix [#90](https://github.com/JBlond/php-diff/issues/90) - Merged Diff shows result only partially ([acbfd7d](https://github.com/JBlond/php-diff/commit/acbfd7d))
+* Fix colors ([7eba340](https://github.com/JBlond/php-diff/commit/7eba340))
+* Fix repeating class assignment of line header ([fb32453](https://github.com/JBlond/php-diff/commit/fb32453))
+* Fix title attribute values ([533a6bf](https://github.com/JBlond/php-diff/commit/533a6bf))
+
+## v2.3.1 (2021-02-03)
+
+* Add DigiLive/gitChangelog for change log generation ([0a6a84f](https://github.com/JBlond/php-diff/commit/0a6a84f))
+* Bump library version ([013f862](https://github.com/JBlond/php-diff/commit/013f862))
+* Cut HTML Unified Renderer ([1ba255f](https://github.com/JBlond/php-diff/commit/1ba255f))
+* Document PhpUnit Similarity Test ([7ec484c](https://github.com/JBlond/php-diff/commit/7ec484c))
+* Document Update Changelog ([28e1dc0](https://github.com/JBlond/php-diff/commit/28e1dc0), [c9881d3](https://github.com/JBlond/php-diff/commit/c9881d3))
+* Document disabled inspection ([909e195](https://github.com/JBlond/php-diff/commit/909e195))
+* Document generateLinesEqual() ([8a193c9](https://github.com/JBlond/php-diff/commit/8a193c9))
+* Document methods ([94c8bd5](https://github.com/JBlond/php-diff/commit/94c8bd5))
+* Fix [#83](https://github.com/JBlond/php-diff/issues/83) - Lines not properly marked ([6fcafe1](https://github.com/JBlond/php-diff/commit/6fcafe1))
+* Fix HTML Merged Renderer ([07da484](https://github.com/JBlond/php-diff/commit/07da484))
+* Fix constructor DocBlocks ([b13ff84](https://github.com/JBlond/php-diff/commit/b13ff84))
+* Fix html syntax error ([11ec623](https://github.com/JBlond/php-diff/commit/11ec623))
+* Fix namespace and unused code ([77a7b59](https://github.com/JBlond/php-diff/commit/77a7b59))
+* Fix probably undefined variable ([3954a2b](https://github.com/JBlond/php-diff/commit/3954a2b))
+* Fix property visibility and method docBlocks ([3bc0839](https://github.com/JBlond/php-diff/commit/3bc0839))
+* Fix property visibility and unused code ([34a032f](https://github.com/JBlond/php-diff/commit/34a032f))
+* Fix redundant and unused code. ([73f6776](https://github.com/JBlond/php-diff/commit/73f6776))
+* add phpunit config file ([7382ee8](https://github.com/JBlond/php-diff/commit/7382ee8))
+
+## v2.3.0 (2020-11-19)
+
+* Add Html Merged renderer. ([d70eaf6](https://github.com/JBlond/php-diff/commit/d70eaf6))
+* Add PhpUnit test for html merged renderer ([4512c03](https://github.com/JBlond/php-diff/commit/4512c03))
+* Add calculation for similarity ratio. ([3e4bbe6](https://github.com/JBlond/php-diff/commit/3e4bbe6))
+* Add choosing marking levels to html example ([c27035a](https://github.com/JBlond/php-diff/commit/c27035a))
+* Add new marking levels for inline differences ([75358da](https://github.com/JBlond/php-diff/commit/75358da))
+* Document properties and constructor ([6c95ccd](https://github.com/JBlond/php-diff/commit/6c95ccd))
+* Fix: Html SideBySide renders equal lines of version 1 at both sides. ([ccfc465](https://github.com/JBlond/php-diff/commit/ccfc465))
+* Fix Merged::generateLinesReplace() ([cef85b5](https://github.com/JBlond/php-diff/commit/cef85b5))
+* Fix PSR-4 Auto loading Typo ([6e2ad47](https://github.com/JBlond/php-diff/commit/6e2ad47))
+* Fix PhpUnit test ([3ccaa10](https://github.com/JBlond/php-diff/commit/3ccaa10))
+* Fix Undefined offset notice ([b10fd38](https://github.com/JBlond/php-diff/commit/b10fd38))
+* Fixes [#64](https://github.com/JBlond/php-diff/issues/64) - maxLineMarkerWidth only calculated for input format plain. ([c5f6d72](https://github.com/JBlond/php-diff/commit/c5f6d72))
+* Fix generateBlockHeader docBlocks ([b5cfbd5](https://github.com/JBlond/php-diff/commit/b5cfbd5))
+* Fix visibility of removed lines ([ec0918b](https://github.com/JBlond/php-diff/commit/ec0918b))
+* add changelog ([4b7a56f](https://github.com/JBlond/php-diff/commit/4b7a56f))
+* add changelog to Readme file ([09aea70](https://github.com/JBlond/php-diff/commit/09aea70))
+* add date ([c64c0cc](https://github.com/JBlond/php-diff/commit/c64c0cc))
+* add declaration ([cff7db1](https://github.com/JBlond/php-diff/commit/cff7db1))
+* add wiki links to README.md ([ccd5a6d](https://github.com/JBlond/php-diff/commit/ccd5a6d))
+
+## v2.2.1 (2020-08-06)
+
+* Fix [#58](https://github.com/JBlond/php-diff/issues/58) - Side by side diff shows empty diff ([0946d59](https://github.com/JBlond/php-diff/commit/0946d59), [369b146](https://github.com/JBlond/php-diff/commit/369b146), [02695d5](https://github.com/JBlond/php-diff/commit/02695d5))
+* add to dev for unit tests ([acd12cb](https://github.com/JBlond/php-diff/commit/acd12cb))
+
+## v2.2.0 (2020-07-23)
+
+* Fix code quality. ([0ef6def](https://github.com/JBlond/php-diff/commit/0ef6def))
+* add line for readabiltity ([e28511b](https://github.com/JBlond/php-diff/commit/e28511b))
+
+## v2.1.1 (2020-07-17)
+
+* Fix [#50](https://github.com/JBlond/php-diff/issues/50). ([47d6288](https://github.com/JBlond/php-diff/commit/47d6288))
+* add unit test for cli output ([0c75757](https://github.com/JBlond/php-diff/commit/0c75757))
+
+## v2.1.0 (2020-07-13)
+
+* add plain output for cli ([d7bbe12](https://github.com/JBlond/php-diff/commit/d7bbe12))
+
+## v2.0.0 (2020-07-09)
+
+* Add Cli color support ([4192d8b](https://github.com/JBlond/php-diff/commit/4192d8b))
+* Add dark theme example ([6f41894](https://github.com/JBlond/php-diff/commit/6f41894))
+* Add example picture ([ee37a28](https://github.com/JBlond/php-diff/commit/ee37a28))
+* add composer scripts descriptions. Update key words ([6bfd4f9](https://github.com/JBlond/php-diff/commit/6bfd4f9))
+* add missing tag from merge ([639f3cc](https://github.com/JBlond/php-diff/commit/639f3cc))
+
+## v1.18 (2020-07-01)
+
+* add author ([e132cdb](https://github.com/JBlond/php-diff/commit/e132cdb))
+* add dark theme example ([b9d0ef6](https://github.com/JBlond/php-diff/commit/b9d0ef6))
+
+## v1.17 (2020-06-08)
+
+* Fix issue [#32](https://github.com/JBlond/php-diff/issues/32). ([7ef67e6](https://github.com/JBlond/php-diff/commit/7ef67e6))
+* fix typo in phpdoc ([db259fc](https://github.com/JBlond/php-diff/commit/db259fc))
+
+## v1.16 (2020-03-02)
+
+* Add composer package PHP Mess Detector v2.* ([3e527d1](https://github.com/JBlond/php-diff/commit/3e527d1))
+* Add contributor to author lists. ([4c2cbb7](https://github.com/JBlond/php-diff/commit/4c2cbb7), [c11b4ba](https://github.com/JBlond/php-diff/commit/c11b4ba))
+* Add trimEqual option. ([98d993e](https://github.com/JBlond/php-diff/commit/98d993e))
+* Add types of elements for renderer ([4d1b4a0](https://github.com/JBlond/php-diff/commit/4d1b4a0), [83b4104](https://github.com/JBlond/php-diff/commit/83b4104))
+* Fix PHPMD Violation. ([5d03eae](https://github.com/JBlond/php-diff/commit/5d03eae))
+* Fix expected value for HtmlRendererTest::testUnified() ([fbda2bd](https://github.com/JBlond/php-diff/commit/fbda2bd))
+
+## v1.15 (2020-01-24)
+
+* fix notation ([795fe20](https://github.com/JBlond/php-diff/commit/795fe20))
+
+## v1.14 (2019-12-03)
+
+* No changes.
+
+## v1.13 (2019-10-08)
+
+* No changes.
+
+## v1.12 (2019-03-18)
+
+* add more files to .gitignore ([27b21eb](https://github.com/JBlond/php-diff/commit/27b21eb))
+* add phpunit test to composer ([e8a3f71](https://github.com/JBlond/php-diff/commit/e8a3f71))
+* add tests ([6d165a6](https://github.com/JBlond/php-diff/commit/6d165a6))
+
+## v1.11 (2019-02-22)
+
+* No changes.
+
+## v1.10 (2019-02-20)
+
+* fix codacy warnings of unused functions ([8037d99](https://github.com/JBlond/php-diff/commit/8037d99))
+* fix example ([9207f73](https://github.com/JBlond/php-diff/commit/9207f73))
+
+## v1.9 (2019-02-19)
+
+* add comment like in the other file ([8b68a5d](https://github.com/JBlond/php-diff/commit/8b68a5d))
+* add stronger type hinting ([3a6ef42](https://github.com/JBlond/php-diff/commit/3a6ef42))
+
+## v1.8 (2019-02-13)
+
+* fix test ([b4cfce1](https://github.com/JBlond/php-diff/commit/b4cfce1))
+
+## v1.7 (2019-01-19)
+
+* add code sniffer PSR2 file ([6fa3c76](https://github.com/JBlond/php-diff/commit/6fa3c76))
+* adding curly brackets ([148e787](https://github.com/JBlond/php-diff/commit/148e787))
+* fix PSR1.Files.SideEffects.FoundWithSymbols ([fe21917](https://github.com/JBlond/php-diff/commit/fe21917))
+* fix tabs ([354bf5c](https://github.com/JBlond/php-diff/commit/354bf5c))
+
+## v1.6 (2019-01-19)
+
+* Fix warning with PHP 7.2 when trying to count NULL ([fe69c4f](https://github.com/JBlond/php-diff/commit/fe69c4f))
+* add ci file ([add8165](https://github.com/JBlond/php-diff/commit/add8165))
+* add dock block ([2aafad1](https://github.com/JBlond/php-diff/commit/2aafad1))
+* add unit tests ([0db511d](https://github.com/JBlond/php-diff/commit/0db511d))
+* fix tests ([44a6ab0](https://github.com/JBlond/php-diff/commit/44a6ab0))
+
+## v1.5 (2019-01-15)
+
+* No changes.
+
+## v1.4 (2019-01-14)
+
+* Add PSR4 autoloader ([bda1da9](https://github.com/JBlond/php-diff/commit/bda1da9))
+* add badge ([0fac082](https://github.com/JBlond/php-diff/commit/0fac082))
+* add keywords ([e64716d](https://github.com/JBlond/php-diff/commit/e64716d))
+* add name spacing ([1d15164](https://github.com/JBlond/php-diff/commit/1d15164))
+
+## v1.3 (2019-01-11)
+
+* Fixed lengths of functions ([3591789](https://github.com/JBlond/php-diff/commit/3591789))
+* Fix some typos ([5ca2257](https://github.com/JBlond/php-diff/commit/5ca2257))
+* added missing doc block ([c6f3745](https://github.com/JBlond/php-diff/commit/c6f3745))
+* add lang to html ([1623626](https://github.com/JBlond/php-diff/commit/1623626))
+* add second image ([176b647](https://github.com/JBlond/php-diff/commit/176b647))
+
+## v1.2 (2018-01-23)
+
+* added example code from https://github.com/JBlond/php-diff/issues/1 ([258b976](https://github.com/JBlond/php-diff/commit/258b976))
+* add image to README.md ([0432f78](https://github.com/JBlond/php-diff/commit/0432f78))
+
+## v1.1 (2017-05-05)
+
+* Add ability not to expand tabs ([f5da126](https://github.com/JBlond/php-diff/commit/f5da126))
+* Added note about https://github.com/Xiphe/jQuery-Merge-for-php-diff ([2ebc51f](https://github.com/JBlond/php-diff/commit/2ebc51f))
+* Add in working ignoreWhitespace and ignoreCase options (self-describing), fix up an issue where a diff of two files exactly the same would show the last $context lines, general cleanup ([690419d](https://github.com/JBlond/php-diff/commit/690419d))
+* Add mbstring extension as package dependency ([a929467](https://github.com/JBlond/php-diff/commit/a929467))
+* Add missing docblock. Rename isLineDifferent to linesAreDifferent ([516c4be](https://github.com/JBlond/php-diff/commit/516c4be))
+* Fix ' ([c81931f](https://github.com/JBlond/php-diff/commit/c81931f))
+* Fix an issue with insertions being skipped. ([b13d23d](https://github.com/JBlond/php-diff/commit/b13d23d))
+* Fix links ([2c38d0e](https://github.com/JBlond/php-diff/commit/2c38d0e))
+* Fix tab expansion and deprecated preg_replace use on fixSpaces. ([f0aba03](https://github.com/JBlond/php-diff/commit/f0aba03))
+* Fix the ignoring of option context ([60de296](https://github.com/JBlond/php-diff/commit/60de296))
+* add composer file ([be8dc58](https://github.com/JBlond/php-diff/commit/be8dc58))
+* added ' ([09d0c4c](https://github.com/JBlond/php-diff/commit/09d0c4c))
+* added License ([3b5b338](https://github.com/JBlond/php-diff/commit/3b5b338))
+* added widget ([d1a5e18](https://github.com/JBlond/php-diff/commit/d1a5e18))
+* adding composer manifest to distribute as a library ([9083bd6](https://github.com/JBlond/php-diff/commit/9083bd6))
+* add missing doc blocks ([d3b9a63](https://github.com/JBlond/php-diff/commit/d3b9a63))
+
+## v1.0 (2010-03-11)
+
+* No changes.
diff --git a/composer.json b/composer.json
index 818e62eb..59c9d4c4 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,12 @@
"license": "BSD-3-Clause",
"keywords": [
"php",
- "diff"
+ "diff",
+ "side-by-sidediff",
+ "unified",
+ "udiff",
+ "unidiff",
+ "unified diff"
],
"authors": [
{
@@ -22,26 +27,55 @@
}
],
"require": {
- "php": ">=7.2",
- "ext-mbstring": "*"
+ "php": ">=7.3",
+ "ext-mbstring": "*",
+ "ext-pcre": "*",
+ "symfony/polyfill-mbstring": "^1"
},
"require-dev": {
- "phpunit/phpunit": "8.*",
+ "phpunit/phpunit": "^8 || ^9",
"squizlabs/php_codesniffer": "*",
- "phpmd/phpmd": "2.*"
+ "phpmd/phpmd": "2.*",
+ "jblond/php-cli": "^1.0",
+ "digilive/git-changelog": "^2"
+ },
+ "suggest": {
+ "ext-json": "*",
+ "jblond/php-cli": "^1.0"
},
"autoload": {
"psr-4": {
"jblond\\": "lib/jblond"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "Tests\\": "tests"
+ }
+ },
"config": {
"classmap-authoritative": true
},
"scripts": {
- "phpunit": "phpunit ./tests/",
+ "phpunit": "phpunit",
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/",
- "phpmd": "phpmd ./ ansi cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor"
+ "phpmd": "phpmd ./ ansi cleancode,codesize,controversial,design,naming,unusedcode --exclude vendor",
+ "changelog": "php generateChangelog.php",
+ "test": [
+ "@php_src",
+ "@php_test",
+ "phpunit --colors=always --testdox"
+ ],
+ "coverage": "phpunit --colors=always --coverage-html codeCoverage"
+ },
+ "scripts-descriptions": {
+ "phpunit": "Run PHPUnit tests",
+ "php_src": "Run code sniffer on lib directory",
+ "php_test": "Run code sniffer on tests directory",
+ "phpmd": "Run php mess detector",
+ "changelog": "generate changelog from commits",
+ "test": "Run code formatting test and phpunit",
+ "coverage": "Run phpunit code overage"
}
}
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..c4a37646
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,20 @@
+# For all options see
+# https://dockerfile.readthedocs.io/en/latest/content/DockerImages/dockerfiles/php-nginx-dev.html
+services:
+ php:
+ image: webdevops/php-nginx-dev:8.2
+ container_name: diff
+ working_dir: /app
+ environment:
+ - WEB_DOCUMENT_ROOT=/app/example
+ - WEB_DOCUMENT_INDEX=example.php
+ - PHP_DISPLAY_ERRORS=1
+ - PHP_MEMORY_LIMIT=2048M
+ - PHP_MAX_EXECUTION_TIME=-1
+ - PHP_DATE_TIMEZONE=Europe/Berlin
+ - XDEBUG_IDE_KEY=PHPSTORM
+ ports:
+ - "88:80"
+ - "9000:9000"
+ volumes:
+ - ./:/app:rw,cached
diff --git a/example/a.txt b/example/a.txt
index eab1ced5..9dddb84c 100644
--- a/example/a.txt
+++ b/example/a.txt
@@ -8,7 +8,7 @@
This line is removed from version2.
This line is also removed from version2.
This line is the same for both versions.
- This line has inline differences between both versions.
+ this line has inline differences between both versions.
This line is the same for both versions.
This line also has inline differences between both versions.
This line is the same for both versions.
diff --git a/example/cli.php b/example/cli.php
new file mode 100644
index 00000000..6c456acd
--- /dev/null
+++ b/example/cli.php
@@ -0,0 +1,75 @@
+';
+ echo 'Please execute it from a cli interpreter.';
+ throw new RuntimeException('Script for CLI use only!');
+}
+
+
+// Include and instantiate autoloader.
+require '../vendor/autoload.php';
+
+// Include two sample files for comparison.
+$sampleA = file_get_contents(__DIR__ . '/a.txt');
+$sampleB = file_get_contents(__DIR__ . '/b.txt');
+
+$customOptions = [
+ 'context' => 2,
+ 'trimEqual' => false,
+ 'ignoreWhitespace' => true,
+ 'ignoreCase' => true,
+];
+
+// Choose one of the initializations.
+$diff = new Diff($sampleA, $sampleB);
+//$diff = new Diff($a, $b, $customOptions); // Initialize the diff class with custom options.
+
+// Instantiate Cli wrapper
+$cli = new Cli();
+
+// Generate a unified diff.
+$renderer = new UnifiedCli();
+echo "-= Unified Default =-\n\n";
+$cli->output($diff->render($renderer));
+
+echo "\n\n-= Unified Colored =-\n\n";
+
+$renderer = new UnifiedCli(
+// Define renderer options.
+ [
+ 'cliColor' => true,
+ ]
+);
+
+$cli->output($diff->render($renderer));
+
+
+// Generate an inline diff.
+$renderer = new InlineCli(
+// Define renderer options.
+ [
+ 'deleteMarkers' => ['-', '-'],
+ 'insertMarkers' => ['+', '+'],
+ 'equalityMarkers' => ['=', 'x'],
+ ]
+);
+echo "-= Inline Marked =-\n\n";
+$cli->output($diff->render($renderer));
+
+echo "-= Inline Colored =-\n\n";
+
+$coloredRenderer = new InlineCli(
+// Define renderer options.
+ [
+ 'cliColor' => true,
+ ]
+);
+
+$cli->output($diff->render($coloredRenderer));
diff --git a/example/dark-theme.css b/example/dark-theme.css
index 1c0408bb..7fa98403 100644
--- a/example/dark-theme.css
+++ b/example/dark-theme.css
@@ -1,13 +1,13 @@
body {
background: #3A3B46;
- color: #F8F8F2;
+ color: #F8F8F2;
font-family: Arial, serif;
font-size: 12px;
}
pre {
- width: 100%;
overflow: auto;
+ width: 100%;
}
a, a:visited {
@@ -19,75 +19,77 @@ a, a:visited {
*/
.Differences {
- width: 100%;
border-collapse: collapse;
border-spacing: 0;
empty-cells: show;
+ width: 100%;
}
.Differences thead th {
- text-align: left;
- border-bottom: 1px solid #000000;
background: #AAAAAA;
+ border-bottom: 1px solid #000000;
color: #000000;
padding: 4px;
+ text-align: left;
}
.Differences tbody th {
- text-align: right;
background: #AAAAAA;
- color: #272822;
- width: 4em;
- padding: 1px 2px;
border-right: 1px solid #000000;
- vertical-align: top;
+ color: #272822;
font-size: 13px;
+ padding: 1px 2px;
+ text-align: right;
+ vertical-align: top;
+ width: 4em;
}
.Differences td {
- padding: 1px 2px;
font-family: Consolas, monospace;
font-size: 13px;
+ padding: 1px 2px;
}
.Differences .Skipped {
background: #F7F7F7;
+ color: #000000;
+ display: block;
+}
+
+.Differences ins,
+.Differences del {
+ text-decoration: none;
}
/*
* HTML Side by Side Diff
*/
.DifferencesSideBySide .ChangeInsert td.Left {
- background: green;
+ background: #DDFFDD;
}
.DifferencesSideBySide .ChangeInsert td.Right {
- background: green;
+ background: #008000;
}
.DifferencesSideBySide .ChangeDelete td.Left {
background: #FF8888;
- color: #272822;
+ color: #272822;
}
.DifferencesSideBySide .ChangeDelete td.Right {
background: #FFAAAA;
- color: #272822;
+ color: #272822;
}
.DifferencesSideBySide .ChangeReplace .Left {
- background: #FFEE99;
- color: #272822;
+ background: #FFDD88;
+ color: #272822;
}
.DifferencesSideBySide .ChangeReplace .Right {
background: #FFDD88;
- color: #272822;
-}
-
-.Differences ins,
-.Differences del {
- text-decoration: none;
+ color: #272822;
}
.DifferencesSideBySide .ChangeReplace ins,
@@ -95,92 +97,94 @@ a, a:visited {
background: #EEBB00;
}
+.DifferencesSideBySide .ChangeIgnore .Left,
+.DifferencesSideBySide .ChangeIgnore .Right {
+ background: #FBF2BF;
+}
+
+.DifferencesSideBySide .ChangeIgnore .Left.Ignore {
+ background: #4B4C57;
+}
+
+.DifferencesSideBySide .ChangeIgnore .Right.Ignore {
+ background: #4B4C57;
+}
+
/*
- * HTML Inline Diff
+ * HTML Unified Diff
*/
-.DifferencesInline .ChangeReplace {
+.DifferencesUnified .ChangeReplace {
color: #272822;
}
-.DifferencesInline .ChangeReplace .Left,
-.DifferencesInline .ChangeDelete .Left {
+.DifferencesUnified .ChangeReplace .Left,
+.DifferencesUnified .ChangeDelete .Left {
background: #FFDDDD;
- color: #272822;
+ color: #272822;
}
-.DifferencesInline .ChangeReplace .Right,
-.DifferencesInline .ChangeInsert .Right {
+.DifferencesUnified .ChangeReplace .Right,
+.DifferencesUnified .ChangeInsert .Right {
background: #DDFFDD;
+ color: #272822;
}
-.DifferencesInline .ChangeReplace ins {
- background: green;
-}
-
-.DifferencesInline .ChangeReplace del {
- background: #EE9999;
- color: #272822;
-}
-
-/*
- * HTML Unified Diff
- */
-
-/* Line removed in new */
-.DifferencesUnified .ChangeDelete .Left::before {
- content: "- \00a0";
+.DifferencesUnified .ChangeReplace ins {
+ background: #008000;
+ color: #272822;
}
-.DifferencesUnified .ChangeDelete .Left {
+.DifferencesUnified .ChangeReplace del {
background: #EE9999;
- color: #272822;
+ color: #272822;
}
-/* Line modified in old and new */
-.DifferencesUnified .ChangeReplace {
- background: #FFEE99;
- color: #272822;
- display: table;
+.DifferencesUnified .ChangeIgnore .Left,
+.DifferencesUnified .ChangeIgnore .Right {
+ background: #FBF2BF;
}
-/* Line in old replaced by line in new */
-.DifferencesUnified .ChangeReplace .Left:first-child:before {
- content: "\250C \00a0";
+.DifferencesUnified .ChangeIgnore .Left.Ignore {
+ background: #4B4C57;
}
-.DifferencesUnified .ChangeReplace .Left:before {
- content: "\251C \00a0";
+.DifferencesUnified .ChangeIgnore .Right.Ignore {
+ background: #4B4C57;
}
-.DifferencesUnified .ChangeReplace .Left {
- background: #FFEE99;
+/*
+ * HTML Merged Diff
+ */
+.DifferencesMerged td.ChangeReplace {
+ background: #FFDD88;
+ color: #272822;
}
-/* Line in new replaced line in old */
-.DifferencesUnified .ChangeReplace .Right:last-of-type:before {
- content: "\2514 \00a0";
+.DifferencesMerged .ChangeDelete {
+ background: #FFDDDD;
+ color: #272822;
}
-.DifferencesUnified .ChangeReplace .Right:before {
- content: "\251C \00a0";
+.DifferencesMerged .ChangeInsert {
+ background: #DDFFDD;
+ color: #272822;
}
-.DifferencesUnified .ChangeReplace .Right {
- background: #FFEE99;
+.DifferencesMerged .ChangeReplace ins {
+ background: #008000;
+ color: #272822;
}
-/* Line inserted in new */
-.DifferencesUnified .ChangeInsert .Right:before {
- content: "+ \00A0";
+.DifferencesMerged .ChangeReplace del {
+ background: #EE9999;
+ color: #272822;
}
-/* Character inserted in line of new */
-.DifferencesUnified .ChangeReplace ins {
- background: #99EE99;
+.DifferencesMerged th.ChangeDelete {
+ background-image: linear-gradient(-45deg, #AAAAAA 0%, #EE9999 100%);
}
-/* Character removed from line in old */
-.DifferencesUnified .ChangeReplace del {
- background: #EE9999;
+.DifferencesMerged th.ChangeReplace {
+ background-image: linear-gradient(-45deg, #CCCCCC 0%, #FFDD88 100%);
}
diff --git a/example/example.php b/example/example.php
index 681f6869..8b8b6cd8 100644
--- a/example/example.php
+++ b/example/example.php
@@ -1,105 +1,123 @@
2,
'trimEqual' => false,
'ignoreWhitespace' => true,
'ignoreCase' => true,
+ 'ignoreLines' => Diff::DIFF_IGNORE_LINE_EMPTY,
];
// Choose one of the initializations.
-$diff = new Diff($a, $b); // Initialize the diff class with default options.
-//$diff = new Diff($a, $b, $customOptions); // Initialize the diff class with custom options.
-?>
+$diff = new Diff($sampleA, $sampleB); // Initialize the diff class with default options.
+//$diff = new Diff($sampleA, $sampleB, $diffOptions); // Initialize the diff class with custom options.
+
+// Options for rendering the diff.
+$rendererOptions = [
+ 'inlineMarking' => $_GET['inlineMarking'] ?? Diff\Renderer\MainRenderer::CHANGE_LEVEL_LINE,
+]
+?>
+
-
-
- PHP LibDiff - Examples
-
-
+
+
+PHP LibDiff - Examples
+
+
+
+
+
+ Informational
+ Between the two versions, there's a
+ getStatistics();
+ echo round($diff->getSimilarity(), 2) * 100;
+ ?>% match.
+ Inserted lines:
+ Deleted lines:
+ Not modified lines:
+ Lines with replacement:
+
+
+
+HTML Side by Side Diff
- var oldLink = document.getElementsByTagName("link").item(cssLinkIndex);
-
- var newLink = document.createElement("link");
- newLink.setAttribute("rel", "stylesheet");
- newLink.setAttribute("type", "text/css");
- newLink.setAttribute("href", cssFile);
-
- document.getElementsByTagName("head").item(0).replaceChild(newLink, oldLink);
- }
-
-
-
- PHP LibDiff - Examples
-
-
-
- HTML Side by Side Diff
-
- 'Custom title for version1',
- 'title2' => 'Custom title for version2',
- ]);
- echo $diff->Render($renderer);
- ?>
-
- HTML Inline Diff
-
- isIdentical() ? 'No differences found.' : $diff->Render($renderer);
+?>
- // Generate an inline diff.
- // \jblond\Diff\Renderer\Html
- $renderer = new Inline();
- echo $diff->render($renderer);
- ?>
+HTML Unified Diff
+isIdentical() ? 'No differences found.' : $diff->Render($renderer);
+?>
- HTML Unified Diff
- {$diff->render($renderer)}";
- ?>
+HTML Merged Diff
+isIdentical() ? 'No differences found.' : $diff->Render($renderer);
+?>
- Text Unified Diff
- ' . htmlspecialchars($diff->render($renderer)) . '';
- ?>
+Text Unified Diff
+isIdentical() ?
+ 'No differences found.' : '' . htmlspecialchars($diff->render($renderer)) . ' ';
+?>
- Text Context Diff
- ' . htmlspecialchars($diff->render($renderer)) . '';
- ?>
-
+Text Context Diff
+isIdentical() ?
+ 'No differences found.' : '' . htmlspecialchars($diff->render($renderer)) . ' ';
+?>
+