diff --git a/README.md b/README.md index dd7464f4..88bfd1d8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,36 @@ composer require jblond/php-diff ## Example Use +```PHP + 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. @@ -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 +``` diff --git a/composer.json b/composer.json index a571509f..c3ab7814 100644 --- a/composer.json +++ b/composer.json @@ -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/" } } diff --git a/example/example.php b/example/example.php index 901091a6..6a6b516a 100644 --- a/example/example.php +++ b/example/example.php @@ -1,67 +1,67 @@ - + - - - PHP LibDiff - Examples - - - -

PHP LibDiff - Examples

-
- + + PHP LibDiff - Examples + + + +

PHP LibDiff - Examples

+
+ 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); - ?> -

Side by Side Diff

- +

Side by Side Diff

+ 'Custom title for OLD version', 'title_b' => 'Custom title for NEW version', )); - echo $diff->Render($renderer); + echo $diff->Render($renderer); - ?> -

Inline Diff

- +

Inline Diff

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

Unified Diff

-

+        

Unified Diff

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

Context Diff

-

+        
+

Context Diff

+
render($renderer));
-		?>
-		
- + // Generate a context diff + $renderer = new \jblond\Diff\Renderer\Text\Context; + echo htmlspecialchars($diff->render($renderer)); + ?> +
+ diff --git a/lib/Autoloader.php b/lib/Autoloader.php index 1cc14011..1341b1d6 100644 --- a/lib/Autoloader.php +++ b/lib/Autoloader.php @@ -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'; + } + }); } } diff --git a/lib/jblond/Diff.php b/lib/jblond/Diff.php index c8c973e5..48c50cff 100644 --- a/lib/jblond/Diff.php +++ b/lib/jblond/Diff.php @@ -16,7 +16,7 @@ * @author Chris Boulton * @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 diff --git a/lib/jblond/Diff/Renderer/Html/HtmlArray.php b/lib/jblond/Diff/Renderer/Html/HtmlArray.php index 8d80b3a3..696982d3 100644 --- a/lib/jblond/Diff/Renderer/Html/HtmlArray.php +++ b/lib/jblond/Diff/Renderer/Html/HtmlArray.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @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 diff --git a/lib/jblond/Diff/Renderer/Html/Inline.php b/lib/jblond/Diff/Renderer/Html/Inline.php index 8df07eda..a8cffc50 100644 --- a/lib/jblond/Diff/Renderer/Html/Inline.php +++ b/lib/jblond/Diff/Renderer/Html/Inline.php @@ -11,7 +11,7 @@ * @author Chris Boulton * @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 diff --git a/lib/jblond/Diff/Renderer/Html/SideBySide.php b/lib/jblond/Diff/Renderer/Html/SideBySide.php index a801d772..44c2144d 100644 --- a/lib/jblond/Diff/Renderer/Html/SideBySide.php +++ b/lib/jblond/Diff/Renderer/Html/SideBySide.php @@ -11,7 +11,7 @@ * @author Chris Boulton * @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 diff --git a/lib/jblond/Diff/Renderer/RendererAbstract.php b/lib/jblond/Diff/Renderer/RendererAbstract.php index 0a3599ad..f3a0afc6 100644 --- a/lib/jblond/Diff/Renderer/RendererAbstract.php +++ b/lib/jblond/Diff/Renderer/RendererAbstract.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @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 diff --git a/lib/jblond/Diff/Renderer/Text/Context.php b/lib/jblond/Diff/Renderer/Text/Context.php index 8dbaa035..42d0b0a9 100644 --- a/lib/jblond/Diff/Renderer/Text/Context.php +++ b/lib/jblond/Diff/Renderer/Text/Context.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @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 diff --git a/lib/jblond/Diff/Renderer/Text/Unified.php b/lib/jblond/Diff/Renderer/Text/Unified.php index 8848d322..33088c9e 100644 --- a/lib/jblond/Diff/Renderer/Text/Unified.php +++ b/lib/jblond/Diff/Renderer/Text/Unified.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @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 */ diff --git a/lib/jblond/Diff/SequenceMatcher.php b/lib/jblond/Diff/SequenceMatcher.php index 93b376c6..7c61b0e2 100644 --- a/lib/jblond/Diff/SequenceMatcher.php +++ b/lib/jblond/Diff/SequenceMatcher.php @@ -11,7 +11,7 @@ * @author Chris Boulton * @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