jord-jd/fuzzy-events

Perform actions based on fuzzy string matches

Maintainers

Package info

github.com/Jord-JD/fuzzy-events

pkg:composer/jord-jd/fuzzy-events

Transparency log

Fund package maintenance!

DivineOmega

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v4.1.0 2026-07-18 09:16 UTC

This package is auto-updated.

Last update: 2026-07-18 09:17:29 UTC


README

Tests

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);