Installation
composer require atm/fingerprintbundle
Add to config/bundles.php:
return [
// ...
Atm\FingerprintBundle\AtmFingerprintBundle::class => ['all' => true],
];
Configuration Publish the default config:
php artisan config:publish atm/fingerprint
Update config/packages/atm_fingerprint.yaml with your fingerprint device settings (e.g., device_path, timeout, log_level).
First Use Case Capture a fingerprint in a controller:
use Atm\FingerprintBundle\Service\FingerprintService;
public function captureFingerprint(FingerprintService $fingerprint)
{
$fingerprintData = $fingerprint->capture();
return response()->json($fingerprintData);
}
Enrollment Workflow
// Enroll a new fingerprint
$fingerprint->enroll('user_id', 'template_id');
// Returns: ['status' => 'success', 'template_id' => '12345']
Verification Workflow
// Verify against an existing template
$result = $fingerprint->verify('template_id');
// Returns: ['status' => 'matched'/'no_match', 'confidence' => 85]
Template Management
// Delete a template
$fingerprint->deleteTemplate('template_id');
// List all templates
$templates = $fingerprint->listTemplates();
Event Listeners
Bind to fingerprint.captured or fingerprint.verified events in EventServiceProvider:
protected $listen = [
'Atm\FingerprintBundle\Events\FingerprintCaptured' => [
'App\Listeners\LogFingerprintCapture',
],
];
Middleware for Auth Use middleware to enforce fingerprint verification for sensitive routes:
public function handle($request, Closure $next)
{
if (!$request->user()->hasVerifiedFingerprint()) {
return redirect()->route('verify.fingerprint');
}
return $next($request);
}
Queue Jobs
Offload fingerprint processing to queues (e.g., FingerprintEnrollJob):
dispatch(new FingerprintEnrollJob($userId, $templateId));
Device Communication
$attempts = 3;
while ($attempts--) {
try {
return $fingerprint->capture();
} catch (\Atm\FingerprintBundle\Exception\DeviceException $e) {
if ($attempts === 0) throw $e;
sleep(2 ** $attempts);
}
}
Template ID Collisions
$templateId = 'user_' . $userId . '_' . $fingerprint->generateTemplateId();
Permission Handling
public function enroll($userId, $templateId)
{
if (!auth()->user()->can('enroll_fingerprint')) {
throw new \RuntimeException('Unauthorized');
}
// ...
}
Enable Verbose Logging
Set log_level: debug in config and check storage/logs/fingerprint.log.
Simulate Device Errors
Use the Atm\FingerprintBundle\Tests\MockDevice in tests to simulate failures:
$fingerprint = new FingerprintService(new MockDevice(['error' => 'device_offline']));
Custom Device Drivers
Extend Atm\FingerprintBundle\Device\AbstractDevice to support new hardware:
class CustomDevice extends AbstractDevice
{
public function capture(): array
{
// Custom implementation
}
}
Template Storage Override the default template storage (e.g., switch from DB to Redis):
$fingerprint->setTemplateStorage(new RedisTemplateStorage());
Fallback Mechanisms Implement a fallback for when the fingerprint device is unavailable:
try {
return $fingerprint->verify($templateId);
} catch (DeviceException $e) {
return $this->fallbackVerification($templateId);
}
How can I help you explore Laravel packages today?