Skip to content

Commit e2863c0

Browse files
authored
Merge pull request #15 from JBlond/development
v1.12
2 parents d0431f1 + 2f11a9d commit e2863c0

12 files changed

+111
-73
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,36 @@ composer require jblond/php-diff
2727

2828
## Example Use
2929

30+
```PHP
31+
<?php
32+
// installed via composer
33+
require 'vendor/autoload.php';
34+
35+
// or installed manual
36+
require dirname(__FILE__).'/../lib/Autoloader.php';
37+
new \jblond\Autoloader();
38+
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(
43+
//'ignoreWhitespace' => true,
44+
//'ignoreCase' => true,
45+
);
46+
// Initialize the diff class
47+
$diff = new \jblond\Diff($a, $b, $options);
48+
49+
//choose renderer
50+
$renderer = new \jblond\Diff\Renderer\Html\SideBySide(array(
51+
'title_a' => 'Custom title for OLD version',
52+
'title_b' => 'Custom title for NEW version',
53+
));
54+
55+
//show it
56+
echo $diff->Render($renderer);
57+
```
58+
59+
### Example Output
3060
A quick usage example can be found in the example/ directory and under
3161
example.php.
3262

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

6292
see [License](LICENSE)
93+
94+
## tests
95+
96+
```BASH
97+
composer run-script phpunit
98+
composer run-script php_src
99+
composer run-script php_test
100+
```

composer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
"ext-mbstring": "*"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "7.*"
25+
"phpunit/phpunit": "7.*",
26+
"squizlabs/php_codesniffer": "*"
2627
},
2728
"autoload": {
2829
"psr-4": {
2930
"jblond\\": "lib/jblond"
3031
}
32+
},
33+
"scripts": {
34+
"phpunit": "phpunit ./tests/",
35+
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
36+
"php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/"
3137
}
3238
}

example/example.php

+50-50
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="utf-8"/>
5-
<title>PHP LibDiff - Examples</title>
6-
<link rel="stylesheet" href="styles.css" type="text/css" charset="utf-8"/>
7-
</head>
8-
<body>
9-
<h1>PHP LibDiff - Examples</h1>
10-
<hr />
11-
<?php
12-
// include autoloader
13-
require dirname(__FILE__).'/../lib/Autoloader.php';
14-
new \jblond\Autoloader();
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>PHP LibDiff - Examples</title>
6+
<link rel="stylesheet" href="styles.css" type="text/css" charset="utf-8"/>
7+
</head>
8+
<body>
9+
<h1>PHP LibDiff - Examples</h1>
10+
<hr />
11+
<?php
12+
// include autoloader
13+
require dirname(__FILE__).'/../lib/Autoloader.php';
14+
new \jblond\Autoloader();
1515

16-
// Include two sample files for comparison
17-
$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
18-
$b = explode("\n", file_get_contents(dirname(__FILE__).'/b.txt'));
16+
// Include two sample files for comparison
17+
$a = explode("\n", file_get_contents(dirname(__FILE__).'/a.txt'));
18+
$b = explode("\n", file_get_contents(dirname(__FILE__).'/b.txt'));
1919

20-
// Options for generating the diff
21-
$options = array(
22-
//'ignoreWhitespace' => true,
23-
//'ignoreCase' => true,
24-
);
20+
// Options for generating the diff
21+
$options = array(
22+
//'ignoreWhitespace' => true,
23+
//'ignoreCase' => true,
24+
);
2525

26-
// Initialize the diff class
27-
$diff = new \jblond\Diff($a, $b, $options);
26+
// Initialize the diff class
27+
$diff = new \jblond\Diff($a, $b, $options);
2828

29-
?>
30-
<h2>Side by Side Diff</h2>
31-
<?php
29+
?>
30+
<h2>Side by Side Diff</h2>
31+
<?php
3232

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

40-
?>
41-
<h2>Inline Diff</h2>
42-
<?php
40+
?>
41+
<h2>Inline Diff</h2>
42+
<?php
4343

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

48-
?>
49-
<h2>Unified Diff</h2>
50-
<pre><?php
48+
?>
49+
<h2>Unified Diff</h2>
50+
<pre><?php
5151

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

56-
?>
57-
</pre>
58-
<h2>Context Diff</h2>
59-
<pre><?php
56+
?>
57+
</pre>
58+
<h2>Context Diff</h2>
59+
<pre><?php
6060

61-
// Generate a context diff
62-
$renderer = new \jblond\Diff\Renderer\Text\Context;
63-
echo htmlspecialchars($diff->render($renderer));
64-
?>
65-
</pre>
66-
</body>
61+
// Generate a context diff
62+
$renderer = new \jblond\Diff\Renderer\Text\Context;
63+
echo htmlspecialchars($diff->render($renderer));
64+
?>
65+
</pre>
66+
</body>
6767
</html>

lib/Autoloader.php

+8-14
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,13 @@ class Autoloader
1313
*/
1414
public function __construct()
1515
{
16-
spl_autoload_register(array($this, '__autoload'));
17-
}
18-
19-
/**
20-
* @param string $class
21-
*/
22-
private function __autoload($class)
23-
{
24-
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
25-
$dir = str_replace('\\', '/', __DIR__);
26-
if (file_exists($dir . '/' . $class . '.php')) {
27-
/** @noinspection PhpIncludeInspection */
28-
require_once $dir . '/' . $class . '.php';
29-
}
16+
spl_autoload_register(function ($class) {
17+
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
18+
$dir = str_replace('\\', '/', __DIR__);
19+
if (file_exists($dir . '/' . $class . '.php')) {
20+
/** @noinspection PhpIncludeInspection */
21+
require_once $dir . '/' . $class . '.php';
22+
}
23+
});
3024
}
3125
}

lib/jblond/Diff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @author Chris Boulton <[email protected]>
1717
* @copyright (c) 2009 Chris Boulton
1818
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
19-
* @version 1.11
19+
* @version 1.12
2020
* @link https://github.com/JBlond/php-diff
2121
*/
2222
class Diff

lib/jblond/Diff/Renderer/Html/HtmlArray.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author Chris Boulton <[email protected]>
1414
* @copyright (c) 2009 Chris Boulton
1515
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
16-
* @version 1.11
16+
* @version 1.12
1717
* @link https://github.com/JBlond/php-diff
1818
*/
1919
class HtmlArray extends RendererAbstract

lib/jblond/Diff/Renderer/Html/Inline.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Chris Boulton <[email protected]>
1212
* @copyright (c) 2009 Chris Boulton
1313
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
14-
* @version 1.11
14+
* @version 1.12
1515
* @link https://github.com/JBlond/php-diff
1616
*/
1717
class Inline extends HtmlArray

lib/jblond/Diff/Renderer/Html/SideBySide.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Chris Boulton <[email protected]>
1212
* @copyright (c) 2009 Chris Boulton
1313
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
14-
* @version 1.11
14+
* @version 1.12
1515
* @link https://github.com/JBlond/php-diff
1616
*/
1717
class SideBySide extends HtmlArray

lib/jblond/Diff/Renderer/RendererAbstract.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author Chris Boulton <[email protected]>
1414
* @copyright (c) 2009 Chris Boulton
1515
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
16-
* @version 1.11
16+
* @version 1.12
1717
* @link https://github.com/JBlond/php-diff
1818
*/
1919
abstract class RendererAbstract

lib/jblond/Diff/Renderer/Text/Context.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author Chris Boulton <[email protected]>
1414
* @copyright (c) 2009 Chris Boulton
1515
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
16-
* @version 1.11
16+
* @version 1.12
1717
* @link https://github.com/JBlond/php-diff
1818
*/
1919
class Context extends RendererAbstract

lib/jblond/Diff/Renderer/Text/Unified.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author Chris Boulton <[email protected]>
1414
* @copyright (c) 2009 Chris Boulton
1515
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
16-
* @version 1.11
16+
* @version 1.12
1717
* @link https://github.com/JBlond/php-diff
1818
*/
1919

lib/jblond/Diff/SequenceMatcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author Chris Boulton <[email protected]>
1212
* @copyright (c) 2009 Chris Boulton
1313
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
14-
* @version 1.11
14+
* @version 1.12
1515
* @link https://github.com/JBlond/php-diff
1616
*/
1717
class SequenceMatcher

0 commit comments

Comments
 (0)