jord-jd / fuzzy-events
Perform actions based on fuzzy string matches
Fund package maintenance!
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.5 || ^8.5 || ^9.6
Replaces
- divineomega/fuzzy-events: v4.1.0
This package is auto-updated.
Last update: 2026-07-18 09:17:29 UTC
README
Fuzzy events is a PHP package that allows you to perform actions based on a fuzzy string matches.
Installation
Install using the following Composer command.
composer require jord-jd/fuzzy-events
Usage
See the following usage example.
class Greeting implements FuzzyListenerInterface { public function handle(string $query) { return 'Hello there!'; } }
$listeners = [ Greeting::class => [ 'Hello', 'Hi', 'Hey', 'Greetings', 'Howdy', 'Hello there', 'Hi there', ], ]; $confidenceThreshold = 75; $dispatcher = new FuzzyDispatcher($listeners, $confidenceThreshold); $response = $dispatcher->fire('Greetingz!'); // $response = 'Hello there!' try { $dispatcher->fire('Goodbye!'); } catch (ConfidenceTooLowException $e) { // No matches within specified confidence threshold! } $confidences = $dispatcher->getConfidences('Hi!'); // $confidences = [ // Greeting::class => 80 // ]
Ranked matches
Use getRankedConfidences() when you want every candidate sorted from best to worst, or getMatches() to keep only candidates above the dispatcher's threshold (or an explicit minimum).
$ranked = $dispatcher->getRankedConfidences('Hello'); $matches = $dispatcher->getMatches('Hello'); $strictMatches = $dispatcher->getMatches('Hello', 95);
Confidence and match thresholds must be between 0 and 100. Listener classes and phrases are validated when the dispatcher is constructed, so configuration errors fail before a query is handled.
Matching remains case-sensitive by default. Pass false as the optional third constructor argument to compare case-insensitively.
$dispatcher = new FuzzyDispatcher($listeners, 75, false);