基于模糊字符串匹配执行操作
v1.0.0
2020-03-10 23:39 UTC
Requires
- php: >=7.1
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^7.0||^8.0
This package is auto-updated.
Last update: 2024-09-24 09:29:30 UTC
README
Fuzzy events 是一个 PHP 包,允许您根据模糊字符串匹配执行操作。
安装
使用以下 Composer 命令进行安装。
composer require divineomega/fuzzy-events
用法
请参考以下用法示例。
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 // ]