A multi-line diff calculation library based on Jetbrains' powerful IDE diff implementation.
https://github.com/JetBrains/intellij-community/tree/master/platform/util/diff/src/com/intellij/diff
composer require digitalrevolution/jbdiff
$textBefore
:
switch ($strategy) {
case RateLimiterConfig::FIXED_WINDOW:
return new FixedWindow($this->redisService->getConnection(), $config);
case RateLimiterConfig::SLIDING_WINDOW:
return new SlidingWindow($this->redisService->getConnection(), $config);
default:
throw new RuntimeException('Invalid Strategy name.', RuntimeException::UNKNOWN);
}
$textAfter
:
return match ($strategy) {
RateLimiterConfig::FIXED_WINDOW => new FixedWindow($this->redisService->getConnection(), $config),
RateLimiterConfig::SLIDING_WINDOW => new SlidingWindow($this->redisService->getConnection(), $config),
default => throw new RuntimeException('Invalid Strategy name.'),
};
To create the diff:
use DR\JBDiff\ComparisonPolicy;
use DR\JBDiff\JBDiff;
// line block will contain all the information to partition the strings in removed, unchanged and added parts.
$lineBlocks = (new JBDiff())->compare($textBefore, $textAfter, ComparisonPolicy::DEFAULT);
// to iterate over the string parts
$iterator = new LineBlockTextIterator($textBefore, $textAfter, $lineBlocks);
with ComparisonPolicy::IGNORE_WHITESPACES
DEFAULT
: the standard diff strategy and will take whitespace differences into account.TRIM_WHITESPACES
: will take leading and trailing whitespaces out of the diff.IGNORE_WHITESPACES
: will take all whitespace differences out of the diff.
To run the example page, start
composer run example
The page will be available at http://localhost:8000/
At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? We are looking for developers.