Skip to content

v1.12 #15

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 10 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Chris Boulton <[email protected]>
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Chris Boulton <[email protected]>
* @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