HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
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());
        }
    }
}