diff --git a/src/Symfony/Component/Validator/Constraints/Url.php b/src/Symfony/Component/Validator/Constraints/Url.php index e867ee1f0a..7b8ef3fb62 100644 --- a/src/Symfony/Component/Validator/Constraints/Url.php +++ b/src/Symfony/Component/Validator/Constraints/Url.php @@ -24,5 +24,7 @@ use Symfony\Component\Validator\Constraint; class Url extends Constraint { public $message = 'This value is not a valid URL.'; + public $dnsMessage = 'The host could not be resolved.'; public $protocols = array('http', 'https'); + public $checkDNS = false; } diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 3d184775ac..66b0c7bab9 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -62,6 +62,18 @@ class UrlValidator extends ConstraintValidator $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->addViolation(); + + return; + } + + if ($constraint->checkDNS) { + $host = parse_url($value, PHP_URL_HOST); + + if (!checkdnsrr($host, 'ANY')) { + $this->buildViolation($constraint->dnsMessage) + ->setParameter('{{ value }}', $this->formatValue($host)) + ->addViolation(); + } } } } diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf index 346ad0fd34..c348f9fd15 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.en.xlf @@ -302,6 +302,10 @@ An empty file is not allowed. An empty file is not allowed. + + The host could not be resolved. + The host could not be resolved. + diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf index 2bb9348a3e..fdd0f4d9a0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf @@ -302,6 +302,10 @@ An empty file is not allowed. Un fichier vide n'est pas autorisé. + + The host could not be resolved. + Le nom de domaine n'a pas pu être résolu. +