Skip to content

Commit

Permalink
Merge pull request #15 from JBlond/development
Browse files Browse the repository at this point in the history
v1.12
  • Loading branch information
JBlond committed Mar 18, 2019
2 parents d0431f1 + 2f11a9d commit e2863c0
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 73 deletions.
38 changes: 38 additions & 0 deletions README.md
Expand Up @@ -27,6 +27,36 @@ composer require jblond/php-diff

## Example Use

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

// or installed manual
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(
//'ignoreWhitespace' => true,
//'ignoreCase' => true,
);
// Initialize the diff class
$diff = new \jblond\Diff($a, $b, $options);

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

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

### Example Output
A quick usage example can be found in the example/ directory and under
example.php.

Expand Down Expand Up @@ -60,3 +90,11 @@ Contributors since I forked the repo.
### License (BSD License)

see [License](LICENSE)

## tests

```BASH
composer run-script phpunit
composer run-script php_src
composer run-script php_test
```
8 changes: 7 additions & 1 deletion composer.json
Expand Up @@ -22,11 +22,17 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "7.*"
"phpunit/phpunit": "7.*",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
"jblond\\": "lib/jblond"
}
},
"scripts": {
"phpunit": "phpunit ./tests/",
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/"
}
}
100 changes: 50 additions & 50 deletions example/example.php
@@ -1,67 +1,67 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>PHP LibDiff - Examples</title>
<link rel="stylesheet" href="styles.css" type="text/css" charset="utf-8"/>
</head>
<body>
<h1>PHP LibDiff - Examples</h1>
<hr />
<?php
// include autoloader
require dirname(__FILE__).'/../lib/Autoloader.php';
new \jblond\Autoloader();
<head>
<meta charset="utf-8"/>
<title>PHP LibDiff - Examples</title>
<link rel="stylesheet" href="styles.css" type="text/css" charset="utf-8"/>
</head>
<body>
<h1>PHP LibDiff - Examples</h1>
<hr />
<?php
// include autoloader
require dirname(__FILE__).'/../lib/Autoloader.php';
new \jblond\Autoloader();

// Include two sample files for comparison
$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
$b = explode("\n", file_get_contents(dirname(__FILE__).'/b.txt'));
// Include two sample files for comparison
$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(
//'ignoreWhitespace' => true,
//'ignoreCase' => true,
);
// Options for generating the diff
$options = array(
//'ignoreWhitespace' => true,
//'ignoreCase' => true,
);

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

?>
<h2>Side by Side Diff</h2>
<?php
?>
<h2>Side by Side Diff</h2>
<?php

// Generate a side by side diff
// Generate a side by side diff
$renderer = new \jblond\Diff\Renderer\Html\SideBySide(array(
'title_a' => 'Custom title for OLD version',
'title_b' => 'Custom title for NEW version',
));
echo $diff->Render($renderer);
echo $diff->Render($renderer);

?>
<h2>Inline Diff</h2>
<?php
?>
<h2>Inline Diff</h2>
<?php

// Generate an inline diff
$renderer = new \jblond\Diff\Renderer\Html\Inline;
echo $diff->render($renderer);
// Generate an inline diff
$renderer = new \jblond\Diff\Renderer\Html\Inline;
echo $diff->render($renderer);

?>
<h2>Unified Diff</h2>
<pre><?php
?>
<h2>Unified Diff</h2>
<pre><?php

// Generate a unified diff
$renderer = new \jblond\Diff\Renderer\Text\Unified();
echo htmlspecialchars($diff->render($renderer));
// Generate a unified diff
$renderer = new \jblond\Diff\Renderer\Text\Unified();
echo htmlspecialchars($diff->render($renderer));

?>
</pre>
<h2>Context Diff</h2>
<pre><?php
?>
</pre>
<h2>Context Diff</h2>
<pre><?php

// Generate a context diff
$renderer = new \jblond\Diff\Renderer\Text\Context;
echo htmlspecialchars($diff->render($renderer));
?>
</pre>
</body>
// Generate a context diff
$renderer = new \jblond\Diff\Renderer\Text\Context;
echo htmlspecialchars($diff->render($renderer));
?>
</pre>
</body>
</html>
22 changes: 8 additions & 14 deletions lib/Autoloader.php
Expand Up @@ -13,19 +13,13 @@ class Autoloader
*/
public function __construct()
{
spl_autoload_register(array($this, '__autoload'));
}

/**
* @param string $class
*/
private function __autoload($class)
{
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
$dir = str_replace('\\', '/', __DIR__);
if (file_exists($dir . '/' . $class . '.php')) {
/** @noinspection PhpIncludeInspection */
require_once $dir . '/' . $class . '.php';
}
spl_autoload_register(function ($class) {
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
$dir = str_replace('\\', '/', __DIR__);
if (file_exists($dir . '/' . $class . '.php')) {
/** @noinspection PhpIncludeInspection */
require_once $dir . '/' . $class . '.php';
}
});
}
}
2 changes: 1 addition & 1 deletion lib/jblond/Diff.php
Expand Up @@ -16,7 +16,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
class Diff
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/HtmlArray.php
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
class HtmlArray extends RendererAbstract
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/Inline.php
Expand Up @@ -11,7 +11,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
class Inline extends HtmlArray
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/SideBySide.php
Expand Up @@ -11,7 +11,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
class SideBySide extends HtmlArray
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/RendererAbstract.php
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
abstract class RendererAbstract
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Text/Context.php
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
class Context extends RendererAbstract
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Text/Unified.php
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/SequenceMatcher.php
Expand Up @@ -11,7 +11,7 @@
* @author Chris Boulton <chris.boulton@interspire.com>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.11
* @version 1.12
* @link https://github.com/JBlond/php-diff
*/
class SequenceMatcher
Expand Down

0 comments on commit e2863c0

Please sign in to comment.