Skip to content

Commit

Permalink
[symfony#5426] Porting the checkDNS option to 2.7 only
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Jul 7, 2015
1 parent 6daf19f commit cc4c448
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions reference/constraints/Url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Validates that a value is a valid URL string.
| Options | - `message`_ |
| | - `protocols`_ |
| | - `payload`_ |
| | - `checkDNS`_ |
+----------------+---------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
+----------------+---------------------------------------------------------------------+
Expand Down Expand Up @@ -223,3 +224,80 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing
}
.. include:: /reference/constraints/_payload-option.rst.inc

checkDNS
~~~~~~~~

.. versionadded:: 2.7
The ``checkDNS`` option was introduced in Symfony 2.7.

**type**: ``boolean`` **default**: ``false``

By default, this constraint just validates the syntax of the given URL. If you
also need to check whether the associated host exists, set the ``checkDNS``
option to ``true``:

.. configuration-block::

.. code-block:: php-annotations
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Url(
* checkDNS = true
* )
*/
protected $bioUrl;
}
.. code-block:: yaml
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
properties:
bioUrl:
- Url: { checkDNS: true }
.. code-block:: xml
<!-- src/Acme/BlogBundle/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="Acme\BlogBundle\Entity\Author">
<property name="bioUrl">
<constraint name="Url">
<option name="checkDNS">true</option>
</constraint>
</property>
</class>
</constraint-mapping>
.. code-block:: php
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\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(
'checkDNS' => 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.

0 comments on commit cc4c448

Please sign in to comment.