cogpowered/finediff
FineDiff (archived; see d4h/php-finediff) is a PHP library for generating and applying fine-grained diffs between strings. Render changes as HTML or text, choose character/word granularity, and work with compact opcode instructions to transform content.
Strengths:
c7d3i3:two), enabling client-side diff rendering (e.g., in JavaScript via API) or offline processing.Character, Word, Line) aligns with use cases requiring custom diff logic (e.g., semantic diffs for code or structured data).Weaknesses:
0.3.x opcode changes) risk data corruption if stored opcodes exist.Laravel Compatibility:
composer require cogpowered/finediff:0.3.* in a fresh Laravel project.$this->app->singleton(Diff::class, fn() => new Diff(new Word()));
FineDiff::render()).Database/Storage:
0.3.x).TEXT or JSON columns.Frontend Sync:
diff2html).Critical:
phpunit/phpunit@^9 and phpstan/extension-installer.0.3.0) to avoid future breaks.Medium:
Character mode is precise but slower; Word may miss sub-word changes.Granularity classes.Low:
Word sufficient?egulias/email-validator for text diffs, or php-diff/php-diff) if maintenance is a concern.Laravel Ecosystem:
php-diff for files).Tech Stack Compatibility:
| Component | Compatibility | Notes |
|---|---|---|
| PHP 7.4–8.1 | ✅ High | Tested in README. |
| PHP 8.2+ | ⚠️ Low | May require patches. |
| Laravel 8+ | ✅ High | Service container/facade integration. |
| MySQL/PostgreSQL | ✅ High | Store opcodes as TEXT or JSON. |
| Vue/React | ✅ High | Opcodes can be sent to frontend. |
| Queue Workers | ⚠️ Medium | Async diffing may need custom logic. |
Assessment Phase:
cogpowered/finediff:0.3.* in a staging Laravel environment.Integration:
// config/app.php
'aliases' => [
'FineDiff' => App\Services\FineDiffFacade::class,
];
use cogpowered\FineDiff\Diff;
use cogpowered\FineDiff\Granularity\Word;
public function showDiff(Request $request) {
$diff = new Diff(new Word());
$html = $diff->render($request->oldText, $request->newText);
return view('diff', ['html' => $html]);
}
Granularity for custom rules (e.g., ignore whitespace).Artisan::command('diff:generate', function () {
$files = Storage::files('old_revisions');
// Process files...
});
Data Migration (if applicable):
0.3.x opcodes, rewrite them during a maintenance window:
$oldOpcodes = 'c7d3i3:two'; // Example old format
$diff = new Diff();
$newOpcodes = $diff->getOpcodes('string one', 'string two');
// Update database records
PHP Extensions:
Laravel Features:
Cache::remember).diff.generated events for side effects (e.g., notifications).Frontend:
$opcodes = json_encode($diff->getOpcodes($old, $new));
diff2html for rich UI.Phase 1 (1–2 weeks):
Phase 2 (1 week):
Phase 3 (Ongoing):
How can I help you explore Laravel packages today?