- How do I install php-diff in a Laravel project?
- Run `composer require jfcherng/php-diff` in your project root. Ensure your Laravel app uses PHP 8.3+ (required for v7.0.0). The package has no framework dependencies and integrates seamlessly via Composer autoloading.
- What Laravel versions does php-diff v7 support?
- This version requires Laravel 10.x+ due to the PHP 8.3+ dependency. For Laravel 9.x or older, downgrade to v6.x or upgrade your PHP/Laravel stack. The package itself has no Laravel-specific dependencies.
- How do I generate a side-by-side HTML diff in Blade?
- Use the `RendererFactory` to create a side-by-side renderer, then pass the diff result to Blade. Example: `$renderer = RendererFactory::createSideBySideRenderer(); $html = $renderer->render($differ->calculate($oldText, $newText));` Include `DiffHelper::getStyleSheet()` in your layout for styling.
- Does php-diff automatically escape HTML output to prevent XSS?
- No, the HTML renderer does not auto-escape user input. Always sanitize content before passing it to the diff library. For Blade, use `|e` or `{{ }}` to escape rendered output manually.
- What are the breaking changes in v7 for custom Differ/Renderer implementations?
- v7 introduces `DifferOptions` and `RendererOptions` value objects, requiring constructor updates (e.g., `new Differ(new DifferOptions())`). Check the UPGRADING guide for method signature changes in custom implementations.
- How does php-diff handle memory usage for large files (e.g., 1GB+)?
- The core diffing algorithm remains unchanged, so memory usage scales linearly with input size. For files >100MB, consider chunking the content or using streaming approaches. No built-in memory optimizations exist for large datasets.
- Can I use php-diff with Laravel’s service container for dependency injection?
- Yes, bind the `Differ` and `RendererFactory` classes to the container explicitly. Example: `app()->bind(Differ::class, fn() => new Differ(new DifferOptions()));` The new value objects integrate cleanly with Laravel’s DI system.
- Are there performance benchmarks for the new DifferOptions/RendererOptions?
- No official benchmarks are provided in the release notes. The new options objects add minimal overhead; performance should remain comparable to v6.x for typical use cases. Test with your workload if precision is critical.
- How do I migrate from v6.x to v7.0.0 in a Laravel app?
- 1) Update `composer.json` to require `^7.0`. 2) Upgrade PHP to 8.3+. 3) Replace direct `Differ`/`Renderer` instantiations with the new options objects. 4) Test Blade templates and edge cases. Use the UPGRADING guide for constructor/method changes.
- What alternatives exist for generating diffs in Laravel?
- Consider `sebastianbergmann/diff` (simpler, no HTML), `phpoffice/phpdiff` (file-level diffs), or `league/html-to-markdown` for hybrid use cases. php-diff stands out for its HTML rendering flexibility and Laravel compatibility.