- Can I use aldaflux/fine-diff-bundle directly in Laravel, or is it only for Symfony?
- This bundle is designed for Symfony, but you can use its underlying library, PHP-FineDiff (gorhill/PHP-FineDiff), directly in Laravel via Composer. Install it with `composer require gorhill/php-finediff` and use the `Diff` class programmatically. For Twig integration, you’d need a bridge like `twigbridge/twig-laravel`.
- What Laravel versions does this package support?
- The bundle itself is Symfony-focused, but the PHP-FineDiff library it depends on has no Laravel-specific constraints. Ensure your Laravel version (5.5+) supports the underlying PHP-FineDiff library (tested on PHP 7.2+). For Laravel integration, you’ll need to manually wrap the library in a service provider or facade.
- How do I configure granularity (character/word/sentence) in Laravel?
- Since this is a Symfony bundle, Laravel won’t use `config.yml`. Instead, create a Laravel service provider to register the `Diff` class with your desired granularity (e.g., `new Diff($oldText, $newText, 'word')`). Store the default granularity in `config/services.php` or environment variables for consistency.
- Will this bundle break HTML tags when rendering diffs?
- Yes, `renderHtmlTextDiff()` uses `strip_tags()` to clean input before diffing, which may strip semantic HTML (e.g., `<span>` for styling). Preprocess your HTML with a custom parser or use `renderDiff()` on sanitized text if you need to preserve structure. For complex HTML, consider alternatives like `league/html-diff`.
- Are there performance concerns for large texts (e.g., long articles or code)?
- Diff algorithms can be CPU-intensive for large texts. Benchmark with your specific use case (e.g., 10K+ characters). For real-time applications, cache diff results (e.g., Redis) or limit granularity to `paragraph` or `sentence` levels. The bundle doesn’t include built-in caching, so implement it manually.
- How do I integrate Twig diff rendering in Laravel?
- Laravel doesn’t natively support Symfony Twig functions. Install `twigbridge/twig-laravel` to bridge Twig, then publish the `renderDiff` and `renderHtmlTextDiff` functions as custom Twig extensions. Alternatively, render diffs in PHP and pass HTML to Blade views. Example: `echo app('fine_diff')->render($old, $new);`.
- What alternatives exist for Laravel if this bundle isn’t a good fit?
- For Laravel, consider `league/html-diff` (HTML-aware diffing), `diff-match-patch` (Google’s diff library), or `spatie/laravel-html` for custom solutions. If you need Twig-like syntax, wrap any of these libraries in a Laravel package with facades. PHP-FineDiff is lightweight but lacks Laravel-specific tooling.
- Is this bundle actively maintained? Should I use the original webtown-php/fine-diff-bundle instead?
- This fork (`aldaflux/fine-diff-bundle`) shows minimal activity, and the original `webtown-php/fine-diff-bundle` is abandoned. Check the GitHub issues for unresolved dependencies or bugs. For critical projects, consider forking the repo yourself or using a more maintained alternative like `league/html-diff`.
- Can I use this for diffing structured data like JSON or YAML?
- This bundle is text-focused and doesn’t support structured data natively. For JSON/YAML, use libraries like `symfony/yaml` or `nette/utils` to convert data to strings first, then diff. For programmatic analysis (e.g., API change detection), consider `diff-match-patch` or custom logic with `gorhill/php-finediff`.
- How do I test diff functionality in Laravel unit tests?
- Mock the `Diff` class or use dependency injection to swap implementations. Test edge cases like empty strings, identical content, or large payloads. Example: `$diff = $this->app->make('fine_diff'); $result = $diff->render($oldText, $newText); $this->assertStringContainsString('diff', $result);`. For Twig tests, use Laravel’s `TwigView` helper.