Skip to content

Commit 5494f15

Browse files
committed
feature #5804 Added documentation for dnsMessage option (BenjaminPaap)
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
2 parents 567419a + e67beb2 commit 5494f15

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

reference/constraints/Url.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Validates that a value is a valid URL string.
1010
| | - `protocols`_ |
1111
| | - `payload`_ |
1212
| | - `checkDNS`_ |
13+
| | - `dnsMessage`_ |
1314
+----------------+---------------------------------------------------------------------+
1415
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
1516
+----------------+---------------------------------------------------------------------+
@@ -301,3 +302,76 @@ option to ``true``:
301302
302303
This option uses the :phpfunction:`checkdnsrr` PHP function to check the validity
303304
of the ``ANY`` DNS record corresponding to the host associated with the given URL.
305+
306+
dnsMessage
307+
~~~~~~~~~~
308+
309+
.. versionadded:: 2.7
310+
The ``dnsMessage`` option was introduced in Symfony 2.7.
311+
312+
**type**: ``string`` **default**: ``The host could not be resolved.``
313+
314+
This message is shown when the ``checkDNS`` option is set to ``true`` and the
315+
DNS check failed.
316+
317+
.. configuration-block::
318+
319+
.. code-block:: php-annotations
320+
321+
// src/AppBundle/Entity/Author.php
322+
namespace AppBundle\Entity;
323+
324+
use Symfony\Component\Validator\Constraints as Assert;
325+
326+
class Author
327+
{
328+
/**
329+
* @Assert\Url(
330+
* dnsMessage = "The host '{{ value }}' could not be resolved."
331+
* )
332+
*/
333+
protected $bioUrl;
334+
}
335+
336+
.. code-block:: yaml
337+
338+
# src/AppBundle/Resources/config/validation.yml
339+
AppBundle\Entity\Author:
340+
properties:
341+
bioUrl:
342+
- Url: { dnsMessage: 'The host "{{ value }}" could not be resolved.' }
343+
344+
.. code-block:: xml
345+
346+
<!-- src/AppBundle/Resources/config/validation.xml -->
347+
<?xml version="1.0" encoding="UTF-8" ?>
348+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
349+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
350+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
351+
352+
<class name="AppBundle\Entity\Author">
353+
<property name="bioUrl">
354+
<constraint name="Url">
355+
<option name="dnsMessage">The host "{{ value }}" could not be resolved.</option>
356+
</constraint>
357+
</property>
358+
</class>
359+
</constraint-mapping>
360+
361+
.. code-block:: php
362+
363+
// src/AppBundle/Entity/Author.php
364+
namespace AppBundle\Entity;
365+
366+
use Symfony\Component\Validator\Mapping\ClassMetadata;
367+
use Symfony\Component\Validator\Constraints as Assert;
368+
369+
class Author
370+
{
371+
public static function loadValidatorMetadata(ClassMetadata $metadata)
372+
{
373+
$metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
374+
'dnsMessage' => 'The host "{{ value }}" could not be resolved.',
375+
)));
376+
}
377+
}

0 commit comments

Comments
 (0)