Skip to content

Many code fixes, optimazations, cleanup, refactoring and commenting. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9700db7
raise version number
JBlond Dec 3, 2019
4352698
Preperation for local developement.
DigiLive Dec 19, 2019
e6cd9e0
Code commenting.
DigiLive Dec 19, 2019
0d8c872
Code Optimization, cleanup, refactoring and commenting.
DigiLive Dec 19, 2019
122a72c
PHPUnit test added for diff-view renderers.
DigiLive Dec 19, 2019
0c5e1a4
HTML Unified Renderer added, Code optimization, cleanup and commenting.
DigiLive Dec 20, 2019
611dc21
PHPUnit test for HTML Unified Renderer added.
DigiLive Dec 20, 2019
71b63a1
Code cleanup, bumped required PHP version to >= 7.2 and updated readme.
DigiLive Dec 20, 2019
5e7ddf3
Code Style Fixes.
DigiLive Dec 28, 2019
6bc3f7c
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 10, 2020
d1c724c
Code Fixes.
DigiLive Jan 10, 2020
42b1ace
valid html can have no white space before the first tag
JBlond Jan 10, 2020
7c75b07
PSR12.Files.DeclareStatement
JBlond Jan 10, 2020
2a01869
PSR12 fixes
JBlond Jan 10, 2020
6bfc5e7
Correct paths for composer run-script phpunit
JBlond Jan 10, 2020
ec0e0a6
ignore composer lock file
JBlond Jan 10, 2020
e227356
PSR12 fixes
DigiLive Jan 14, 2020
c984365
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 14, 2020
3b2c367
Update PHPUnit tests
DigiLive Jan 14, 2020
795fe20
fix notation
JBlond Jan 14, 2020
c017af5
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 15, 2020
3a1c258
Code reformatting and minor optimization, Typo fixes
DigiLive Jan 16, 2020
7f87ce3
Code reformatting and minor optimization, Typo fixes
DigiLive Jan 16, 2020
7748252
Code Optimization, cleanup, refactoring and commenting.
DigiLive Jan 22, 2020
f5f11a3
Merge branch 'DigiLive' of https://github.com/JBlond/php-diff into Di…
DigiLive Jan 22, 2020
78a1658
Code Fixes, Optimization, cleanup, refactoring and commenting.
DigiLive Jan 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 109 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,109 @@
/vendor

# Created by https://www.gitignore.io/api/windows,eclipse,composer
# Edit at https://www.gitignore.io/?templates=windows,eclipse,composer

### Composer ###
composer.phar
/vendor/

# 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
# composer.lock

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Annotation Processing
.apt_generated/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Annotation Processing
.apt_generated

.sts4-cache/

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/windows,eclipse,composer
/composer.lock
60 changes: 32 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
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:
* Unified
* Context
* Inline HTML
* Side by Side HTML
* Unified
* Context
* Inline HTML
* Side by Side HTML
* Unified HTML

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
Expand All @@ -21,38 +22,40 @@ so is primarily because of its high degree of accuracy.

## Install

```
```shell
composer require jblond/php-diff
```

## Example Use

```PHP
<?php
// installed via composer
// Installed via composer...
require 'vendor/autoload.php';

// or installed manual
// ...or installed manually.
require dirname(__FILE__).'/../lib/Autoloader.php';

new \jblond\Autoloader();

$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
$b = explode("\n", file_get_contents(dirname(__FILE__).'/b.txt'));
// Options for generating the diff
$options = array(
$a = file_get_contents(dirname(__FILE__).'/a.txt');
$b = file_get_contents(dirname(__FILE__).'/b.txt');

// Options for generating the diff.
$options = [
//'ignoreWhitespace' => true,
//'ignoreCase' => true,
);
// Initialize the diff class
];

// Initialize the diff class.
$diff = new \jblond\Diff($a, $b, $options);

//choose renderer
$renderer = new \jblond\Diff\Renderer\Html\SideBySide(array(
// Choose Renderer.
$renderer = new \jblond\Diff\Renderer\Html\SideBySide([
'title_a' => 'Custom title for OLD version',
'title_b' => 'Custom title for NEW version',
));
]);

//show it
// Show it.
echo $diff->Render($renderer);
```

Expand All @@ -66,8 +69,8 @@ example.php.

## Requirements

- PHP 7.1 or greater
- PHP Multibyte String
* PHP 7.2 or greater
* PHP Multibyte String

## Merge files using jQuery

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

## Todo

* Ability to ignore blank line changes
* 3 way diff support
* Ability to ignore blank line changes
* 3 way diff support

## Contributors
## Contributors

Contributors since I forked the repo.

- maxxer
- Creris
- jfcherng
* maxxer
* Creris
* jfcherng
* DigiLive

### License (BSD License)

see [License](LICENSE)

## tests
## Tests

```BASH
```shell
composer run-script phpunit
composer run-script php_src
composer run-script php_test
Expand Down
76 changes: 37 additions & 39 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
{
"name": "jblond/php-diff",
"type": "library",
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
"license": "BSD-3-Clause",
"keywords": [
"php",
"diff"
],
"authors": [
{
"name": "Mario",
"email": "[email protected]"
},
{
"name": "Chris Boulton",
"email": "[email protected]"
}
],
"require": {
"php" : ">= 7.1",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "8.*",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
"jblond\\": "lib/jblond"
}
},
"config": {
"classmap-authoritative": true
},
"scripts": {
"phpunit": "phpunit ./tests/",
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/"
}
"name" : "jblond/php-diff",
"type" : "library",
"description" : "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
"license" : "BSD-3-Clause",
"keywords" : [
"php",
"diff"
],
"authors" : [{
"name" : "Mario",
"email" : "[email protected]"
}, {
"name" : "Chris Boulton",
"email" : "[email protected]"
}
],
"require" : {
"php" : ">=7.2",
"ext-mbstring" : "*"
},
"require-dev" : {
"phpunit/phpunit" : "8.*",
"squizlabs/php_codesniffer" : "*"
},
"autoload" : {
"psr-4" : {
"jblond\\" : "lib/jblond"
}
},
"config" : {
"classmap-authoritative" : true
},
"scripts" : {
"phpunit" : "phpunit ./tests/",
"php_src" : "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
"php_test" : "phpcs --standard=phpcs.xml -s -p --colors ./tests/"
}
}
2 changes: 2 additions & 0 deletions example/a.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<pre>
构建具有中国特色的医学人才培养体系
</pre>
<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>
<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>
<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>
<pre>
另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
Expand Down
2 changes: 2 additions & 0 deletions example/b.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<pre>
构建具有中国國的医学人才培养体系
</pre>
<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>
<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>
<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>
<pre>
另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革” 😅😅
Expand Down
Loading