Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static variables prevents running validation with different configuration #5

Closed
linkkaro opened this issue Jan 30, 2024 · 2 comments
Closed
Assignees

Comments

@linkkaro
Copy link

linkkaro commented Jan 30, 2024

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
@stymiee stymiee self-assigned this Mar 23, 2024
@darvanen
Copy link

I've come up against this too, I started looking into creating a PR but there are so many ways to approach it. Let me know if I can help.

@stymiee
Copy link
Owner

stymiee commented Apr 6, 2024

@linkkaro Thank you for the patch. I applied it and added some tests. This will be in the upcoming 1.1.4 release.

stymiee added a commit that referenced this issue Apr 6, 2024
@stymiee stymiee closed this as completed Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants