Implements the full identity matching engine: email matching (HIGH confidence), fuzzy name matching with Levenshtein distance (MEDIUM confidence, upgradable to HIGH with DOB tiebreaker), manual link/unlink, revert confirmed matches, and automatic detection via PersonObserver. Includes 33 comprehensive tests, frontend integration with confirm/dismiss/unlink UI, and match indicators in the persons list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
30 lines
702 B
PHP
30 lines
702 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Models\Person;
|
|
use App\Services\PersonIdentityService;
|
|
|
|
final class PersonObserver
|
|
{
|
|
public function __construct(
|
|
private readonly PersonIdentityService $identityService,
|
|
) {}
|
|
|
|
public function created(Person $person): void
|
|
{
|
|
if ($person->user_id === null && ($person->email || $person->first_name)) {
|
|
$this->identityService->detectMatches($person);
|
|
}
|
|
}
|
|
|
|
public function updated(Person $person): void
|
|
{
|
|
if ($person->wasChanged('email') && $person->user_id === null && $person->email) {
|
|
$this->identityService->detectMatches($person);
|
|
}
|
|
}
|
|
}
|