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