[Validator] added less-strict email host verification
New checkHost attribute in email constraint will make the validator check for only one of MX, A or AAAA DNS resource records to verify it as a valid email address.
This commit is contained in:
parent
0ccb6fa48d
commit
f617e02a96
@ -22,4 +22,5 @@ class Email extends Constraint
|
||||
{
|
||||
public $message = 'This value is not a valid email address';
|
||||
public $checkMX = false;
|
||||
public $checkHost = false;
|
||||
}
|
||||
|
@ -51,9 +51,11 @@ class EmailValidator extends ConstraintValidator
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
// Check MX records
|
||||
// Check for host DNS resource records
|
||||
if ($valid && $constraint->checkMX) {
|
||||
$valid = $this->checkMX($host);
|
||||
} else if ($valid && $constraint->checkHost) {
|
||||
$valid = $this->checkHost($host);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,4 +79,16 @@ class EmailValidator extends ConstraintValidator
|
||||
{
|
||||
return checkdnsrr($host, 'MX');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if one of MX, A or AAAA DNS RR exists.
|
||||
*
|
||||
* @param string $host Hostname
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
private function checkHost($host)
|
||||
{
|
||||
return $this->checkMX($host) || (checkdnsrr($host, "A") || checkdnsrr($host, "AAAA"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user