Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b22fea2

Browse files
committed
[Validator] Added a check DNS option on URL validator
1 parent 9ca3e8b commit b22fea2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Symfony/Component/Validator/Constraints/Url.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ class Url extends Constraint
2525
{
2626
public $message = 'This value is not a valid URL.';
2727
public $protocols = array('http', 'https');
28+
public $checkDNS = false;
2829
}

src/Symfony/Component/Validator/Constraints/UrlValidator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ public function validate($value, Constraint $constraint)
6262
$this->buildViolation($constraint->message)
6363
->setParameter('{{ value }}', $this->formatValue($value))
6464
->addViolation();
65+
66+
return;
67+
}
68+
69+
$host = parse_url($value, PHP_URL_HOST);
70+
71+
if ($constraint->checkDNS && !checkdnsrr($host, 'ANY')) {
72+
$this->buildViolation($constraint->message)
73+
->setParameter('{{ value }}', $this->formatValue($host))
74+
->addViolation();
6575
}
6676
}
6777
}

0 commit comments

Comments
 (0)