Static variables are persisted during script execution, therefore it is not possible to validate several emails using different configuration.
The static $disposableEmailListProviders;
in DisposableEmailValidator.php
and static $freeEmailListProviders;
in FreeEmailValidator.php
are set on first class initialization and it is not possible to change them. These variables should be replaces with properties on the class e.g. private ?array $freeEmailListProviders = null;
remove_static_variables.patch.txt
Use case: there are two email fields one for personal and another for work email. Personal email has one set of free email providers while work email has different set.
$freeListSet = [
'yandex.com',
'yandex.ru'
// ....
];
$personalEmailValidator = new EmailValidator([
'checkMxRecords' => false,
'checkBannedListedEmail' => false.
'checkDisposableEmail' => true,
'checkFreeEmail' => true,
'bannedList' => [],
'disposableList' => [],
'freeList' => $freeListSet,
'LocalDisposableOnly' => false,
'LocalFreeOnly' => true,
]);
$workFreeListSet = ['gmail.com', ...$freeListSet];
$workEmailValidator = new EmailValidator([
'checkMxRecords' => false,
'checkBannedListedEmail' => false.
'checkDisposableEmail' => true,
'checkFreeEmail' => true,
'bannedList' => [],
'disposableList' => [],
'freeList' => $workFreeListSet,
'LocalDisposableOnly' => false,
'LocalFreeOnly' => true,
]);
var_dump($personalEmailValidator->validate('[email protected]')); // true - ok
var_dump($workEmailValidator->validate('[email protected]')); // true - should be false as gmail.com is included in freeList