[Validator] Added a check DNS option on URL validator
This commit is contained in:
parent
193d69c4d1
commit
ad2f906daf
@ -24,5 +24,7 @@ use Symfony\Component\Validator\Constraint;
|
|||||||
class Url extends Constraint
|
class Url extends Constraint
|
||||||
{
|
{
|
||||||
public $message = 'This value is not a valid URL.';
|
public $message = 'This value is not a valid URL.';
|
||||||
|
public $dnsMessage = 'The host could not be resolved.';
|
||||||
public $protocols = array('http', 'https');
|
public $protocols = array('http', 'https');
|
||||||
|
public $checkDNS = false;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,18 @@ class UrlValidator extends ConstraintValidator
|
|||||||
$this->buildViolation($constraint->message)
|
$this->buildViolation($constraint->message)
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
->addViolation();
|
->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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,6 +302,10 @@
|
|||||||
<source>An empty file is not allowed.</source>
|
<source>An empty file is not allowed.</source>
|
||||||
<target>An empty file is not allowed.</target>
|
<target>An empty file is not allowed.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="79">
|
||||||
|
<source>The host could not be resolved.</source>
|
||||||
|
<target>The host could not be resolved.</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
@ -302,6 +302,10 @@
|
|||||||
<source>An empty file is not allowed.</source>
|
<source>An empty file is not allowed.</source>
|
||||||
<target>Un fichier vide n'est pas autorisé.</target>
|
<target>Un fichier vide n'est pas autorisé.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="79">
|
||||||
|
<source>The host could not be resolved.</source>
|
||||||
|
<target>Le nom de domaine n'a pas pu être résolu.</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
Reference in New Issue
Block a user