[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 $message = 'This value is not a valid email address';
|
||||||
public $checkMX = false;
|
public $checkMX = false;
|
||||||
|
public $checkHost = false;
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,11 @@ class EmailValidator extends ConstraintValidator
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check MX records
|
// Check for host DNS resource records
|
||||||
if ($valid && $constraint->checkMX) {
|
if ($valid && $constraint->checkMX) {
|
||||||
$valid = $this->checkMX($host);
|
$valid = $this->checkMX($host);
|
||||||
|
} else if ($valid && $constraint->checkHost) {
|
||||||
|
$valid = $this->checkHost($host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ class EmailValidator extends ConstraintValidator
|
|||||||
/**
|
/**
|
||||||
* Check DNS Records for MX type.
|
* Check DNS Records for MX type.
|
||||||
*
|
*
|
||||||
* @param string $host Host name
|
* @param string $host Hostname
|
||||||
*
|
*
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
@ -77,4 +79,16 @@ class EmailValidator extends ConstraintValidator
|
|||||||
{
|
{
|
||||||
return checkdnsrr($host, 'MX');
|
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