death-notifier/src/main/php/com/fwdekker/deathnotifier/validator/IsEmailRule.php

27 lines
871 B
PHP

<?php
namespace com\fwdekker\deathnotifier\validator;
use com\fwdekker\deathnotifier\ValidationException;
/**
* Verifies that the input is an email address.
*/
class IsEmailRule extends Rule
{
/**
* Verifies that the input is an email address.
*
* @param array<string, mixed> $inputs the list of inputs in which the value at `key` should be checked
* @param string $key the key in `inputs` of the input to check
* @return void if `$inputs[$key]` is an email address
* @throws ValidationException if `$inputs[$key]` is not set or is not an email address
*/
public function check(array $inputs, string $key): void
{
if (!isset($inputs[$key]) || !filter_var($inputs[$key], FILTER_VALIDATE_EMAIL))
throw new ValidationException($this->override_message ?? "Enter a valid email address.", $key);
}
}