Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Php Sequence Matcher

Php Sequence Matcher Laravel Package

jfcherng/php-sequence-matcher

PHP 8.4+ longest sequence matcher inspired by Python difflib. Compare strings or arrays to find matching blocks and similarities for diffing, change detection, and text analysis. Lightweight library extracted from php-diff with improvements.

View on GitHub
Deep Wiki
Context7

A longest sequence matcher. The logic is primarily based on the Python difflib package.

Frequently asked questions about Php Sequence Matcher
How do I use this package to compare two strings or arrays in Laravel?
Install via Composer (`composer require jfcherng/php-sequence-matcher`), then use the `SequenceMatcher` class. For example, `$matcher = new SequenceMatcher(); $result = $matcher->match('old string', 'new string');` returns an array of matching blocks. Works with arrays too—just pass them as arguments.
Does this package support Laravel 10.x or only Laravel 11+?
This package requires PHP 8.4+, which blocks Laravel 10.x (PHP 8.3+). For Laravel 10.x, you’d need to downgrade PHP or use an alternative like `chrisboulton/php-diff`. Laravel 11+ (PHP 8.4+) is fully supported.
Can I use this for diffing database records or audit logs in Laravel?
Yes, it’s ideal for diffing arrays (e.g., Eloquent model attributes or audit log changes). The `getMatchingBlocks()` method returns structured diffs, which you can integrate into Laravel’s `HasDiffable` traits or custom validation logic.
How does the object-based Options API (v5.0+) work, and should I migrate from array-based options?
The new `Options` class (e.g., `new Options(autojunk: false)`) replaces array-based configs for better type safety. Migration is straightforward but required for new projects. Existing code may need updates if using array-based options, though no deprecation timeline is set.
Will this package work with Laravel’s cache or queue systems?
The `Options` class may not serialize cleanly by default. For caching (Redis/file) or queues, convert options to an array or JSON before storing, or implement `__serialize()`/`__unserialize()` in a custom DTO wrapper.
Are there performance issues with large sequences (e.g., 100k+ elements)?
No benchmarks exist for PHP 8.3+, but the algorithm’s time complexity is O(n²) in worst cases. For large sequences, consider chunking data or preprocessing (e.g., hashing) to reduce comparison load. Test with your specific dataset.
How does Unicode/multibyte string support work?
The package handles Unicode strings natively, as PHP’s string functions (used internally) support multibyte characters. No special configuration is needed for internationalized text, but edge cases (e.g., grapheme clusters) may require manual testing.
What alternatives exist if I need a Laravel-specific diffing solution?
For Laravel, consider `spatie/laravel-diff` (database-aware) or `chrisboulton/php-diff` (older but more mature). If you need Git-like diffs, `knplabs/git` integrates with Git repositories. This package is best for standalone sequence matching.
How do I integrate this with Laravel’s service container or testing?
Bind the `SequenceMatcher` to the container in `AppServiceProvider` (e.g., `app->bind(SequenceMatcher::class, fn() => new SequenceMatcher())`). For testing, mock the class or use dependency injection. No Laravel-specific dependencies exist.
Is this package actively maintained? What’s the risk of breaking changes?
Updates are infrequent (last release: May 2024), and adoption is low (9 stars, 0 dependents). The v5.0+ API is stable, but future changes could occur. For critical projects, consider forking or adding tests to catch regressions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope