Skip to content

Commit d445336

Browse files
authored
Merge pull request #21 from JBlond/DigiLive
Many code fixes, optimazations, cleanup, refactoring and commenting.
2 parents 57b8143 + 78a1658 commit d445336

28 files changed

+1860
-623
lines changed

.gitignore

+109-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,109 @@
1-
/vendor
1+
2+
# Created by https://www.gitignore.io/api/windows,eclipse,composer
3+
# Edit at https://www.gitignore.io/?templates=windows,eclipse,composer
4+
5+
### Composer ###
6+
composer.phar
7+
/vendor/
8+
9+
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
10+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
11+
# composer.lock
12+
13+
### Eclipse ###
14+
.metadata
15+
bin/
16+
tmp/
17+
*.tmp
18+
*.bak
19+
*.swp
20+
*~.nib
21+
local.properties
22+
.settings/
23+
.loadpath
24+
.recommenders
25+
26+
# External tool builders
27+
.externalToolBuilders/
28+
29+
# Locally stored "Eclipse launch configurations"
30+
*.launch
31+
32+
# PyDev specific (Python IDE for Eclipse)
33+
*.pydevproject
34+
35+
# CDT-specific (C/C++ Development Tooling)
36+
.cproject
37+
38+
# CDT- autotools
39+
.autotools
40+
41+
# Java annotation processor (APT)
42+
.factorypath
43+
44+
# PDT-specific (PHP Development Tools)
45+
.buildpath
46+
47+
# sbteclipse plugin
48+
.target
49+
50+
# Tern plugin
51+
.tern-project
52+
53+
# TeXlipse plugin
54+
.texlipse
55+
56+
# STS (Spring Tool Suite)
57+
.springBeans
58+
59+
# Code Recommenders
60+
.recommenders/
61+
62+
# Annotation Processing
63+
.apt_generated/
64+
65+
# Scala IDE specific (Scala & Java development for Eclipse)
66+
.cache-main
67+
.scala_dependencies
68+
.worksheet
69+
70+
### Eclipse Patch ###
71+
# Eclipse Core
72+
.project
73+
74+
# JDT-specific (Eclipse Java Development Tools)
75+
.classpath
76+
77+
# Annotation Processing
78+
.apt_generated
79+
80+
.sts4-cache/
81+
82+
### Windows ###
83+
# Windows thumbnail cache files
84+
Thumbs.db
85+
Thumbs.db:encryptable
86+
ehthumbs.db
87+
ehthumbs_vista.db
88+
89+
# Dump file
90+
*.stackdump
91+
92+
# Folder config file
93+
[Dd]esktop.ini
94+
95+
# Recycle Bin used on file shares
96+
$RECYCLE.BIN/
97+
98+
# Windows Installer files
99+
*.cab
100+
*.msi
101+
*.msix
102+
*.msm
103+
*.msp
104+
105+
# Windows shortcuts
106+
*.lnk
107+
108+
# End of https://www.gitignore.io/api/windows,eclipse,composer
109+
/composer.lock

README.md

+32-28
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
A comprehensive library for generating differences between
1010
two hashable objects (strings or arrays). Generated differences can be
1111
rendered in all of the standard formats including:
12-
* Unified
13-
* Context
14-
* Inline HTML
15-
* Side by Side HTML
12+
* Unified
13+
* Context
14+
* Inline HTML
15+
* Side by Side HTML
16+
* Unified HTML
1617

1718
The logic behind the core of the diff engine (ie, the sequence matcher)
1819
is primarily based on the Python difflib package. The reason for doing
@@ -21,38 +22,40 @@ so is primarily because of its high degree of accuracy.
2122

2223
## Install
2324

24-
```
25+
```shell
2526
composer require jblond/php-diff
2627
```
2728

2829
## Example Use
2930

3031
```PHP
3132
<?php
32-
// installed via composer
33+
// Installed via composer...
3334
require 'vendor/autoload.php';
34-
35-
// or installed manual
35+
// ...or installed manually.
3636
require dirname(__FILE__).'/../lib/Autoloader.php';
37+
3738
new \jblond\Autoloader();
3839

39-
$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
40-
$b = explode("\n", file_get_contents(dirname(__FILE__).'/b.txt'));
41-
// Options for generating the diff
42-
$options = array(
40+
$a = file_get_contents(dirname(__FILE__).'/a.txt');
41+
$b = file_get_contents(dirname(__FILE__).'/b.txt');
42+
43+
// Options for generating the diff.
44+
$options = [
4345
//'ignoreWhitespace' => true,
4446
//'ignoreCase' => true,
45-
);
46-
// Initialize the diff class
47+
];
48+
49+
// Initialize the diff class.
4750
$diff = new \jblond\Diff($a, $b, $options);
4851

49-
//choose renderer
50-
$renderer = new \jblond\Diff\Renderer\Html\SideBySide(array(
52+
// Choose Renderer.
53+
$renderer = new \jblond\Diff\Renderer\Html\SideBySide([
5154
'title_a' => 'Custom title for OLD version',
5255
'title_b' => 'Custom title for NEW version',
53-
));
56+
]);
5457

55-
//show it
58+
// Show it.
5659
echo $diff->Render($renderer);
5760
```
5861

@@ -66,8 +69,8 @@ example.php.
6669

6770
## Requirements
6871

69-
- PHP 7.1 or greater
70-
- PHP Multibyte String
72+
* PHP 7.2 or greater
73+
* PHP Multibyte String
7174

7275
## Merge files using jQuery
7376

@@ -76,24 +79,25 @@ files. Have a look at [jQuery-Merge-for-php-diff](https://github.com/Xiphe/jQuer
7679

7780
## Todo
7881

79-
* Ability to ignore blank line changes
80-
* 3 way diff support
82+
* Ability to ignore blank line changes
83+
* 3 way diff support
8184

82-
## Contributors
85+
## Contributors
8386

8487
Contributors since I forked the repo.
8588

86-
- maxxer
87-
- Creris
88-
- jfcherng
89+
* maxxer
90+
* Creris
91+
* jfcherng
92+
* DigiLive
8993

9094
### License (BSD License)
9195

9296
see [License](LICENSE)
9397

94-
## tests
98+
## Tests
9599

96-
```BASH
100+
```shell
97101
composer run-script phpunit
98102
composer run-script php_src
99103
composer run-script php_test

composer.json

+37-39
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
11
{
2-
"name": "jblond/php-diff",
3-
"type": "library",
4-
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
5-
"license": "BSD-3-Clause",
6-
"keywords": [
7-
"php",
8-
"diff"
9-
],
10-
"authors": [
11-
{
12-
"name": "Mario",
13-
"email": "[email protected]"
14-
},
15-
{
16-
"name": "Chris Boulton",
17-
"email": "[email protected]"
18-
}
19-
],
20-
"require": {
21-
"php" : ">= 7.1",
22-
"ext-mbstring": "*"
23-
},
24-
"require-dev": {
25-
"phpunit/phpunit": "8.*",
26-
"squizlabs/php_codesniffer": "*"
27-
},
28-
"autoload": {
29-
"psr-4": {
30-
"jblond\\": "lib/jblond"
31-
}
32-
},
33-
"config": {
34-
"classmap-authoritative": true
35-
},
36-
"scripts": {
37-
"phpunit": "phpunit ./tests/",
38-
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
39-
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/"
40-
}
2+
"name" : "jblond/php-diff",
3+
"type" : "library",
4+
"description" : "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
5+
"license" : "BSD-3-Clause",
6+
"keywords" : [
7+
"php",
8+
"diff"
9+
],
10+
"authors" : [{
11+
"name" : "Mario",
12+
"email" : "[email protected]"
13+
}, {
14+
"name" : "Chris Boulton",
15+
"email" : "[email protected]"
16+
}
17+
],
18+
"require" : {
19+
"php" : ">=7.2",
20+
"ext-mbstring" : "*"
21+
},
22+
"require-dev" : {
23+
"phpunit/phpunit" : "8.*",
24+
"squizlabs/php_codesniffer" : "*"
25+
},
26+
"autoload" : {
27+
"psr-4" : {
28+
"jblond\\" : "lib/jblond"
29+
}
30+
},
31+
"config" : {
32+
"classmap-authoritative" : true
33+
},
34+
"scripts" : {
35+
"phpunit" : "phpunit ./tests/",
36+
"php_src" : "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
37+
"php_test" : "phpcs --standard=phpcs.xml -s -p --colors ./tests/"
38+
}
4139
}

example/a.txt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<pre>
1111
构建具有中国特色的医学人才培养体系
1212
</pre>
13+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
14+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
1315
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
1416
<pre>
1517
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅

example/b.txt

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<pre>
1212
构建具有中国國的医学人才培养体系
1313
</pre>
14+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
15+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
1416
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
1517
<pre>
1618
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅

0 commit comments

Comments
 (0)