diff --git a/composer.json b/composer.json index 92a0697..bae9ae4 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,14 @@ "source": "https://git.leadmagnet.dev/LeadMagnet/leadmail-sdk" }, "require": { - "php": "^8.2", + "php": "^8.1", "guzzlehttp/guzzle": "^7.0", - "illuminate/mail": "^11.0|^12.0", - "illuminate/support": "^11.0|^12.0" + "illuminate/mail": "^9.0|^10.0", + "illuminate/support": "^9.0|^10.0" }, "require-dev": { - "orchestra/testbench": "^9.0|^10.0", - "pestphp/pest": "^3.0|^4.0" + "orchestra/testbench": "^7.0|^8.0", + "pestphp/pest": "^1.0|^2.0" }, "autoload": { "psr-4": { diff --git a/src/LeadMailServiceProvider.php b/src/LeadMailServiceProvider.php index 5ae0158..218482f 100644 --- a/src/LeadMailServiceProvider.php +++ b/src/LeadMailServiceProvider.php @@ -44,13 +44,8 @@ class LeadMailServiceProvider extends ServiceProvider Validator::extend('leadmail_verify', function (string $attribute, mixed $value) { $rule = $this->app->make(LeadMailVerify::class); - $passed = true; - $rule->validate($attribute, $value, function () use (&$passed) { - $passed = false; - }); - - return $passed; + return $rule->passes($attribute, $value); }, 'The :attribute email address could not be verified.'); } } diff --git a/src/Rules/LeadMailVerify.php b/src/Rules/LeadMailVerify.php index 6e38a72..262ec3d 100644 --- a/src/Rules/LeadMailVerify.php +++ b/src/Rules/LeadMailVerify.php @@ -2,23 +2,24 @@ namespace LeadM\LeadMail\Rules; -use Closure; -use Illuminate\Contracts\Validation\ValidationRule; +use Illuminate\Contracts\Validation\Rule; use LeadM\LeadMail\LeadMailClient; -class LeadMailVerify implements ValidationRule +class LeadMailVerify implements Rule { + protected string $failMessage = 'The :attribute email address could not be verified.'; + public function __construct( protected readonly LeadMailClient $client, protected readonly bool $allowDisposable = false, ) {} - public function validate(string $attribute, mixed $value, Closure $fail): void + public function passes($attribute, $value): bool { if (! is_string($value) || ! filter_var($value, FILTER_VALIDATE_EMAIL)) { - $fail('The :attribute must be a valid email address.'); + $this->failMessage = 'The :attribute must be a valid email address.'; - return; + return false; } try { @@ -26,10 +27,20 @@ class LeadMailVerify implements ValidationRule if (! ($result['data']['valid'] ?? true)) { $reason = $result['data']['reason'] ?? 'verification failed'; - $fail("The :attribute email address is not deliverable ({$reason})."); + $this->failMessage = "The :attribute email address is not deliverable ({$reason})."; + + return false; } + + return true; } catch (\Throwable) { // Fail open — if the verification service is down, allow the email through + return true; } } + + public function message(): string + { + return $this->failMessage; + } }