24 lines
517 B
PHP
24 lines
517 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
final class EmailRecipients
|
|
{
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function parse(?string $value): array
|
|
{
|
|
if (!$value) {
|
|
return [];
|
|
}
|
|
|
|
return collect(preg_split('/[,;]+/', $value) ?: [])
|
|
->map(fn ($email) => trim((string) $email))
|
|
->filter(fn ($email) => $email !== '' && filter_var($email, FILTER_VALIDATE_EMAIL))
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
}
|
|
}
|