merged branch kmohrf/ticket_2827_validator_mail_A_RR_DNS_hostcheck (PR #3799)
Commits
-------
f617e02
[Validator] added less-strict email host verification
Discussion
----------
[Validator] added less-strict email host verification
uhhhhh, my first pull request :>. uhm... tell me if i did something wrong :)
#### Request info
Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes... well,not really (i guess master branch is not passing - at least i didnt broke the email test)
Fixes the following tickets: #2827
#### Description
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:
commit
3469713d90
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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