diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index c33351d16cf..14380b00f94 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -10,6 +10,7 @@ Validates that a value is a valid URL string. | | - `protocols`_ | | | - `payload`_ | | | - `checkDNS`_ | +| | - `dnsMessage`_ | +----------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` | +----------------+---------------------------------------------------------------------+ @@ -301,3 +302,76 @@ option to ``true``: This option uses the :phpfunction:`checkdnsrr` PHP function to check the validity of the ``ANY`` DNS record corresponding to the host associated with the given URL. + +dnsMessage +~~~~~~~~~~ + +.. versionadded:: 2.7 + The ``dnsMessage`` option was introduced in Symfony 2.7. + +**type**: ``string`` **default**: ``The host could not be resolved.`` + +This message is shown when the ``checkDNS`` option is set to ``true`` and the +DNS check failed. + +.. configuration-block:: + + .. code-block:: php-annotations + + // src/AppBundle/Entity/Author.php + namespace AppBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\Url( + * dnsMessage = "The host '{{ value }}' could not be resolved." + * ) + */ + protected $bioUrl; + } + + .. code-block:: yaml + + # src/AppBundle/Resources/config/validation.yml + AppBundle\Entity\Author: + properties: + bioUrl: + - Url: { dnsMessage: 'The host "{{ value }}" could not be resolved.' } + + .. code-block:: xml + + + + + + + + + + + + + + + .. code-block:: php + + // src/AppBundle/Entity/Author.php + namespace AppBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array( + 'dnsMessage' => 'The host "{{ value }}" could not be resolved.', + ))); + } + }