Skip to content

Commit

Permalink
feature #5804 Added documentation for dnsMessage option (BenjaminPaap)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

Added documentation for dnsMessage option

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.7
| Fixed tickets | #5802

Commits
-------

e67beb2 Added missing comma after array element
368576b Fixed Yaml syntax
bffb90d Fixed all comments from @xabbuh
4cc4bae Added documentation for dnsMessage option
  • Loading branch information
weaverryan committed Nov 5, 2015
2 parents 567419a + e67beb2 commit 5494f15
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions reference/constraints/Url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Validates that a value is a valid URL string.
| | - `protocols`_ |
| | - `payload`_ |
| | - `checkDNS`_ |
| | - `dnsMessage`_ |
+----------------+---------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
+----------------+---------------------------------------------------------------------+
Expand Down Expand Up @@ -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
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="AppBundle\Entity\Author">
<property name="bioUrl">
<constraint name="Url">
<option name="dnsMessage">The host "{{ value }}" could not be resolved.</option>
</constraint>
</property>
</class>
</constraint-mapping>
.. 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.',
)));
}
}

0 comments on commit 5494f15

Please sign in to comment.