- What Laravel versions does jfcherng/php-sequence-matcher support?
- The package requires PHP 8.4+, so it’s fully compatible with Laravel 11+ (released Nov 2023). Laravel 10.x users must upgrade PHP to 8.3+ first, as the package drops support for older versions. No Laravel-specific dependencies exist, making it framework-agnostic.
- How do I integrate this into a Laravel service?
- Create a wrapper class (e.g., `SequenceMatcherService`) that initializes the `SequenceMatcher` with your sequences and options. Register it as a singleton in Laravel’s container via `AppServiceProvider`. Inject it into controllers or commands like any other service. No facade or provider is required.
- Does this package work with Unicode strings or nested arrays?
- Yes, it handles Unicode strings natively and supports nested arrays. The matcher compares sequences recursively, but performance may degrade with deeply nested structures. For edge cases, test with your specific data types, as the package prioritizes flat sequences.
- What’s the performance like for large sequences (e.g., 50k+ elements)?
- No official benchmarks exist for PHP 8.3+, but the algorithm is optimized for subsequence matching. For very large sequences, consider chunking data or pre-filtering. Memory usage scales with sequence size, so test thoroughly in staging before production.
- How do I migrate from array-based options (pre-v5.0) to the new object-based API?
- Replace `new SequenceMatcher($seq1, $seq2, ['option' => 'value'])` with `new Options(option: 'value')` and pass the object. Use a wrapper class to abstract the transition. The package provides backward compatibility notes in its changelog for v5.0+ updates.
- Can I use this for diffing database records in Laravel?
- Yes, but structure your data as arrays or strings first. For Eloquent models, serialize collections to arrays using `toArray()` or `json_encode()`. Avoid complex relationships unless flattened, as nested objects may not match as expected.
- Are there alternatives to this package for Laravel?
- For Laravel-specific diffing, consider `spatie/laravel-diff` (Laravel-focused) or `chrisboulton/php-diff` (the original package this forked from). For general-purpose sequence matching, `rubix/ml-diff` (machine learning-based) is another option, though heavier. This package is lighter and difflib-aligned.
- Will the object-based Options class work with Laravel’s cache or queue systems?
- The `Options` class should serialize correctly, but test in your environment. For cached services, ensure the class implements `Serializable` or use `serialize()`/`unserialize()` explicitly. If issues arise, wrap options in a JSON string or use a DTO pattern.
- How do I handle non-string/non-array sequences (e.g., objects)?
- The package expects strings or arrays. Convert objects to arrays using `(array) $object` or `get_object_vars()`. For custom objects, implement `__toString()` or a `toArray()` method. Avoid passing mixed-type sequences, as they may cause unexpected behavior.
- What’s the support like for PHP 8.3+ edge cases or GitHub issues?
- Response times vary, but the maintainer is active (last release: May 2024). For PHP 8.3+ bugs, open a detailed issue with reproduction steps. The package has 9 GitHub stars but low adoption; prioritize testing in staging. Consider contributing fixes if critical issues arise.