ENH Use symfony/validation logic

This commit is contained in:
Guy Sartorelli 2024-09-24 17:42:47 +12:00
parent 4f164fca78
commit c856dc2981
No known key found for this signature in database

View File

@ -30,7 +30,7 @@ class ContentReviewEmails extends BuildTask
*/ */
public function run($request) public function run($request)
{ {
if (!$this->isValidEmail($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) { if (!Email::is_valid_address($senderEmail = SiteConfig::current_site_config()->ReviewFrom)) {
throw new RuntimeException( throw new RuntimeException(
sprintf( sprintf(
'Provided sender email address is invalid: "%s".', 'Provided sender email address is invalid: "%s".',
@ -116,7 +116,7 @@ class ContentReviewEmails extends BuildTask
$siteConfig = SiteConfig::current_site_config(); $siteConfig = SiteConfig::current_site_config();
$owner = Member::get()->byID($ownerID); $owner = Member::get()->byID($ownerID);
if (!$this->isValidEmail($owner->Email)) { if (!Email::is_valid_address($owner->Email)) {
$this->invalid_emails[] = $owner->Name . ': ' . $owner->Email; $this->invalid_emails[] = $owner->Name . ': ' . $owner->Email;
return; return;
@ -188,12 +188,4 @@ class ContentReviewEmails extends BuildTask
'ToEmail' => $recipient->Email, 'ToEmail' => $recipient->Email,
]; ];
} }
/**
* Check validity of email
*/
protected function isValidEmail(?string $email): bool
{
return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
}
} }