Skip to content

Added documentation for dnsMessage option #5804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a | character in this line to end the cell (at the same position as on the other lines).

+----------------+---------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
+----------------+---------------------------------------------------------------------+
Expand Down Expand Up @@ -299,5 +300,78 @@ option to ``true``:
}
}

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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to enclose the message in single quotes to have valid YAML here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, and what do you think to end the message with a period (in all examples) to have a complete sentence?


.. 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'
)));
}
}

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph belongs to the previously described checkDNS option.