Skip to content

Commit

Permalink
Merge pull request #11 from snebes/docs
Browse files Browse the repository at this point in the history
readme update and namespace change
  • Loading branch information
snebes authored Jan 30, 2019
2 parents 0d07bf0 + 8003f47 commit dd46161
Show file tree
Hide file tree
Showing 86 changed files with 235 additions and 203 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
## PHP DaisyDiff
# php-daisydiff

[![PHP Version](https://img.shields.io/packagist/php-v/snebes/php-daisydiff.svg?maxAge=3600)](https://packagist.org/packages/snebes/php-daisydiff)
[![Latest Version](https://img.shields.io/packagist/v/snebes/php-daisydiff.svg?maxAge=3600)](https://packagist.org/packages/snebes/php-daisydiff)
[![Build Status](https://img.shields.io/scrutinizer/build/g/snebes/php-daisydiff.svg?maxAge=3600)](https://scrutinizer-ci.com/g/snebes/php-daisydiff)
[![Code Quality](https://img.shields.io/scrutinizer/g/snebes/php-daisydiff.svg?maxAge=3600)](https://scrutinizer-ci.com/g/snebes/php-daisydiff)
[![Test Coverage](https://img.shields.io/scrutinizer/coverage/g/snebes/php-daisydiff.svg?maxAge=3600)](https://scrutinizer-ci.com/g/snebes/php-daisydiff)

PHP HTML Diff Engine - DaisyDiff Port
Daisy Diff is a PHP implementation of the [Java library](https://github.com/DaisyDiff/DaisyDiff) that diffs (compares) HTML files. It highlights added and removed words and annotates changes to the styling.

## Installation

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

```
composer require snebes/php-daisydiff
```

### Usage

The `DaisyDiff` class can be used to generate a textual representation of the difference between two HTML strings:

```php
<?php

use SN\DaisyDiff\DaisyDiff;

$daisyDiff = new DaisyDiff();
\printf("%s\n", $daisyDiff->diff('<html><body>The original document</body></html>', '<html><body>The changed document</body></html>'));
```

The code above yields the output below:

```html
<html>The <del class="diff-html-removed">original </del><ins class="diff-html-added">changed </ins>document</html>
```
## Thanks

Many thanks to:

- [Java DaisyDiff](https://github.com/DaisyDiff/DaisyDiff), the original Java version of the DaisyDiff library.
- [gdevanla/assist](https://github.com/gdevanla/assist) from which many of the tests of this library are extracted.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
],
"autoload": {
"psr-4": {
"DaisyDiff\\": "src/"
"SN\\DaisyDiff\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DaisyDiff\\": "tests/"
"SN\\DaisyDiff\\": "tests/"
}
},
"license": "MIT",
"require": {
"php": ">=7.1.0",
"ext-mbstring": "*",
"ext-xml": "*",
"psr/log": "^1.0"
"ext-xml": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
Expand Down
16 changes: 8 additions & 8 deletions src/DaisyDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

declare(strict_types=1);

namespace DaisyDiff;

use DaisyDiff\Html\ChangeText;
use DaisyDiff\Html\Dom\DomTreeBuilder;
use DaisyDiff\Html\HtmlDiffer;
use DaisyDiff\Html\HtmlSaxDiffOutput;
use DaisyDiff\Html\TextNodeComparator;
use DaisyDiff\Xml\XMLReader;
namespace SN\DaisyDiff;

use SN\DaisyDiff\Html\ChangeText;
use SN\DaisyDiff\Html\Dom\DomTreeBuilder;
use SN\DaisyDiff\Html\HtmlDiffer;
use SN\DaisyDiff\Html\HtmlSaxDiffOutput;
use SN\DaisyDiff\Html\TextNodeComparator;
use SN\DaisyDiff\Xml\XMLReader;

/**
* Daisy Diff is a library that diffs (compares) HTML.
Expand Down
10 changes: 5 additions & 5 deletions src/Html/Ancestor/AncestorComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor;
namespace SN\DaisyDiff\Html\Ancestor;

use DaisyDiff\Html\Dom\TagNode;
use DaisyDiff\RangeDifferencer\RangeComparatorInterface;
use DaisyDiff\RangeDifferencer\RangeDifference;
use DaisyDiff\RangeDifferencer\RangeDifferencer;
use SN\DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\RangeDifferencer\RangeComparatorInterface;
use SN\DaisyDiff\RangeDifferencer\RangeDifference;
use SN\DaisyDiff\RangeDifferencer\RangeDifferencer;

/**
* A comparator used when calculating the difference in ancestry of two Nodes.
Expand Down
4 changes: 2 additions & 2 deletions src/Html/Ancestor/AncestorComparatorResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor;
namespace SN\DaisyDiff\Html\Ancestor;

use DaisyDiff\Html\Modification\HtmlLayoutChange;
use SN\DaisyDiff\Html\Modification\HtmlLayoutChange;

/**
* AncestorComparatorResult model.
Expand Down
12 changes: 6 additions & 6 deletions src/Html/Ancestor/ChangeTextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor;
namespace SN\DaisyDiff\Html\Ancestor;

use DaisyDiff\Html\Ancestor\TagToString\TagToStringFactory;
use DaisyDiff\Html\ChangeText;
use DaisyDiff\Html\Dom\TagNode;
use DaisyDiff\Html\Modification\HtmlLayoutChange;
use DaisyDiff\RangeDifferencer\RangeDifference;
use SN\DaisyDiff\Html\Ancestor\TagToString\TagToStringFactory;
use SN\DaisyDiff\Html\ChangeText;
use SN\DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\Html\Modification\HtmlLayoutChange;
use SN\DaisyDiff\RangeDifferencer\RangeDifference;

/**
* ChangeTextGenerator
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Ancestor/TagChangeSemantic.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor;
namespace SN\DaisyDiff\Html\Ancestor;

/**
* Semantic types.
Expand Down
4 changes: 2 additions & 2 deletions src/Html/Ancestor/TagToString/AnchorToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor\TagToString;
namespace SN\DaisyDiff\Html\Ancestor\TagToString;

use DaisyDiff\Html\ChangeText;
use SN\DaisyDiff\Html\ChangeText;

/**
* Anchor <a> tag to string.
Expand Down
4 changes: 2 additions & 2 deletions src/Html/Ancestor/TagToString/NoContentTagToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor\TagToString;
namespace SN\DaisyDiff\Html\Ancestor\TagToString;

use DaisyDiff\Html\ChangeText;
use SN\DaisyDiff\Html\ChangeText;

/**
* Image <img> tag to string.
Expand Down
10 changes: 5 additions & 5 deletions src/Html/Ancestor/TagToString/TagToString.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor\TagToString;
namespace SN\DaisyDiff\Html\Ancestor\TagToString;

use DaisyDiff\Html\Ancestor\TagChangeSemantic;
use DaisyDiff\Html\ChangeText;
use DaisyDiff\Html\Dom\TagNode;
use DaisyDiff\Html\Modification\HtmlLayoutChange;
use SN\DaisyDiff\Html\Ancestor\TagChangeSemantic;
use SN\DaisyDiff\Html\ChangeText;
use SN\DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\Html\Modification\HtmlLayoutChange;

/**
* TagToString
Expand Down
6 changes: 3 additions & 3 deletions src/Html/Ancestor/TagToString/TagToStringFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor\TagToString;
namespace SN\DaisyDiff\Html\Ancestor\TagToString;

use DaisyDiff\Html\Ancestor\TagChangeSemantic;
use DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\Html\Ancestor\TagChangeSemantic;
use SN\DaisyDiff\Html\Dom\TagNode;

/**
* TagToString Factory
Expand Down
12 changes: 6 additions & 6 deletions src/Html/Ancestor/TextOnlyComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Ancestor;
namespace SN\DaisyDiff\Html\Ancestor;

use DaisyDiff\Html\Dom\TagNode;
use DaisyDiff\Html\Dom\TextNode;
use DaisyDiff\RangeDifferencer\Core\LCSSettings;
use DaisyDiff\RangeDifferencer\RangeComparatorInterface;
use DaisyDiff\RangeDifferencer\RangeDifferencer;
use SN\DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\Html\Dom\TextNode;
use SN\DaisyDiff\RangeDifferencer\Core\LCSSettings;
use SN\DaisyDiff\RangeDifferencer\RangeComparatorInterface;
use SN\DaisyDiff\RangeDifferencer\RangeDifferencer;

/**
* A comparator that compares only the elements of text inside a given tag.
Expand Down
4 changes: 2 additions & 2 deletions src/Html/ChangeText.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

declare(strict_types=1);

namespace DaisyDiff\Html;
namespace SN\DaisyDiff\Html;

use DaisyDiff\Xml\ContentHandlerInterface;
use SN\DaisyDiff\Xml\ContentHandlerInterface;

/**
* ChangeText model.
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Dom/BodyNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

/**
* Represents the root of a HTML document.
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Dom/DomTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

/**
* Creates a DOM tree from SAX-like events.
Expand Down
4 changes: 2 additions & 2 deletions src/Html/Dom/Helper/LastCommonParentResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom\Helper;
namespace SN\DaisyDiff\Html\Dom\Helper;

use DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\Html\Dom\TagNode;

/**
* When detecting the last common parent of two nodes, all results are stored as a LastCommonParentResult.
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Dom/ImageNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

/**
* Represents an image in HTML. Even though images do not contain any text they are single visible objects on the page.
Expand Down
4 changes: 2 additions & 2 deletions src/Html/Dom/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

use DaisyDiff\Html\Dom\Helper\LastCommonParentResult;
use SN\DaisyDiff\Html\Dom\Helper\LastCommonParentResult;

/**
* Represents any element in the DOM tree of a HTML file.
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Dom/SeparatingNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

/**
* This is an artificial text node whose sole purpose is to separate text nodes, so that they cannot be treated as a
Expand Down
4 changes: 2 additions & 2 deletions src/Html/Dom/TagNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

use ArrayIterator;
use DaisyDiff\Html\Ancestor\TextOnlyComparator;
use SN\DaisyDiff\Html\Ancestor\TextOnlyComparator;
use IteratorAggregate;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Html/Dom/TextNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

use DaisyDiff\Html\Modification\Modification;
use DaisyDiff\Html\Modification\ModificationType;
use SN\DaisyDiff\Html\Modification\Modification;
use SN\DaisyDiff\Html\Modification\ModificationType;

/**
* Represents a piece of text in the HTML file.
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Dom/WhiteSpaceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Dom;
namespace SN\DaisyDiff\Html\Dom;

/**
* Represents whitespace in the HTML file.
Expand Down
12 changes: 6 additions & 6 deletions src/Html/HtmlDiffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

declare(strict_types=1);

namespace DaisyDiff\Html;
namespace SN\DaisyDiff\Html;

use DaisyDiff\Html\Modification\ModificationType;
use DaisyDiff\Output\DiffOutputInterface;
use DaisyDiff\RangeDifferencer\Core\LCSSettings;
use DaisyDiff\RangeDifferencer\RangeDifference;
use DaisyDiff\RangeDifferencer\RangeDifferencer;
use SN\DaisyDiff\Html\Modification\ModificationType;
use SN\DaisyDiff\Output\DiffOutputInterface;
use SN\DaisyDiff\RangeDifferencer\Core\LCSSettings;
use SN\DaisyDiff\RangeDifferencer\RangeDifference;
use SN\DaisyDiff\RangeDifferencer\RangeDifferencer;

/**
* Takes TextNodeComparator instances, computes the difference between them, marks the changes, and outputs a merged
Expand Down
18 changes: 9 additions & 9 deletions src/Html/HtmlSaxDiffOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

declare(strict_types=1);

namespace DaisyDiff\Html;

use DaisyDiff\Html\Dom\ImageNode;
use DaisyDiff\Html\Dom\TagNode;
use DaisyDiff\Html\Dom\TextNode;
use DaisyDiff\Html\Modification\Modification;
use DaisyDiff\Html\Modification\ModificationType;
use DaisyDiff\Output\DiffOutputInterface;
use DaisyDiff\Xml\ContentHandlerInterface;
namespace SN\DaisyDiff\Html;

use SN\DaisyDiff\Html\Dom\ImageNode;
use SN\DaisyDiff\Html\Dom\TagNode;
use SN\DaisyDiff\Html\Dom\TextNode;
use SN\DaisyDiff\Html\Modification\Modification;
use SN\DaisyDiff\Html\Modification\ModificationType;
use SN\DaisyDiff\Output\DiffOutputInterface;
use SN\DaisyDiff\Xml\ContentHandlerInterface;

/**
* Takes a branch root and creates an HTML file for it.
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Modification/HtmlLayoutChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Modification;
namespace SN\DaisyDiff\Html\Modification;

/**
* This class holds the removal or addition of HTML tags around text. It contains the same information that is presented
Expand Down
2 changes: 1 addition & 1 deletion src/Html/Modification/Modification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

declare(strict_types=1);

namespace DaisyDiff\Html\Modification;
namespace SN\DaisyDiff\Html\Modification;

/**
* Modification model.
Expand Down
Loading

0 comments on commit dd46161

Please sign in to comment.