File: /home/xedaptot/be.naniguide.com/app/Verification/Drivers/AbstractVerificationDriver.php
<?php
namespace App\Verification\Drivers;
use App\Model\EmailVerificationServer;
/**
* Optional base class — encapsulates 95% boilerplate (server composition + config helper).
*
* Vendors who want raw control can implement VerificationDriver directly without extending.
*/
abstract class AbstractVerificationDriver implements VerificationDriver
{
protected EmailVerificationServer $server;
public function __construct(EmailVerificationServer $server)
{
$this->server = $server;
}
/**
* Read a key from $server->options JSON (cast 'array' on model).
*/
protected function config(string $key, mixed $default = null): mixed
{
return data_get($this->server->options ?? [], $key, $default);
}
/**
* Default test() — call getCredits() and surface result. Vendor có check rõ ràng hơn
* (vd ping endpoint dedicated) thì override.
*/
public function test(): TestResult
{
try {
$credits = $this->getCredits();
return TestResult::ok('Credits: ' . ($credits ?? 'unknown'));
} catch (\Throwable $e) {
return TestResult::fail($e->getMessage());
}
}
}