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 3 commits
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`_ |
+----------------+---------------------------------------------------------------------+
| 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.'
Copy link
Member

Choose a reason for hiding this comment

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

We usually add a comma after each array entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. Am I supposed to add one on this pr or just keeping this in mind for upcoming pr's?

Copy link
Member

Choose a reason for hiding this comment

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

If you want to, you can make that change. Otherwise we will just apply this when merging. :)

)));
}
}