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 longest sequence matcher inspired by Python difflib. Compare arrays or strings to find matching blocks and measure similarity, useful for diffing and change detection. Lightweight, modern PHP (8.4+) package.

View on GitHub
Deep Wiki
Context7

jfcherng/php-sequence-matcher is a PHP 8.4+ library for finding the longest matching subsequences between two sequences (strings, arrays, etc.). Its matching logic is primarily based on Python’s difflib, making it useful for diff tooling, similarity checks, and change detection.

Extracted and refined from chrisboulton/php-diff, it provides a lightweight, focused sequence-matching core you can embed in your own comparison workflows.

  • Longest sequence matcher inspired by difflib
  • Works with common PHP sequence types (e.g., strings/arrays)
  • Useful for building diff and similarity features
  • Minimal API surface; easy to integrate via Composer
  • Modern baseline with PHP ≥ 8.4 support
Frequently asked questions about Php Sequence Matcher
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.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport