Skip to content

Removed checkDNS option in Url constraint #8921

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
Update Url.rst
  • Loading branch information
ro0NL authored Dec 22, 2017
commit e7fdf1efaea16fbe6d08e7921cc7ad76c1b67baf
146 changes: 0 additions & 146 deletions reference/constraints/Url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Validates that a value is a valid URL string.
| Options | - `message`_ |
| | - `protocols`_ |
| | - `payload`_ |
| | - `checkDNS`_ |
| | - `dnsMessage`_ |
+----------------+---------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
+----------------+---------------------------------------------------------------------+
Expand Down Expand Up @@ -225,147 +223,3 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing
}

.. include:: /reference/constraints/_payload-option.rst.inc

checkDNS
~~~~~~~~

**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/Entity/Author.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Author
{
/**
* @Assert\Url(
* checkDNS = true
* )
*/
protected $bioUrl;
}

.. code-block:: yaml

# config/validator/validation.yaml
App\Entity\Author:
properties:
bioUrl:
- Url: { checkDNS: true }

.. code-block:: xml

<!-- config/validator/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="App\Entity\Author">
<property name="bioUrl">
<constraint name="Url">
<option name="checkDNS">true</option>
</constraint>
</property>
</class>
</constraint-mapping>

.. code-block:: php

// src/Entity/Author.php
namespace App\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.

dnsMessage
~~~~~~~~~~

**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/Entity/Author.php
namespace App\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

# config/validator/validation.yaml
App\Entity\Author:
properties:
bioUrl:
- Url: { dnsMessage: 'The host "{{ value }}" could not be resolved.' }

.. code-block:: xml

<!-- config/validator/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="App\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/Entity/Author.php
namespace App\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.',
)));
}
}