@@ -9,6 +9,7 @@ Validates that a value is a valid URL string.
9
9
| Options | - `message `_ |
10
10
| | - `protocols `_ |
11
11
| | - `payload `_ |
12
+ | | - `checkDNS `_ |
12
13
+----------------+---------------------------------------------------------------------+
13
14
| Class | :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Url ` |
14
15
+----------------+---------------------------------------------------------------------+
@@ -223,3 +224,80 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing
223
224
}
224
225
225
226
.. include :: /reference/constraints/_payload-option.rst.inc
227
+
228
+ checkDNS
229
+ ~~~~~~~~
230
+
231
+ .. versionadded :: 2.7
232
+ The ``checkDNS `` option was introduced in Symfony 2.7.
233
+
234
+ **type **: ``boolean `` **default **: ``false ``
235
+
236
+ By default, this constraint just validates the syntax of the given URL. If you
237
+ also need to check whether the associated host exists, set the ``checkDNS ``
238
+ option to ``true ``:
239
+
240
+ .. configuration-block ::
241
+
242
+ .. code-block :: php-annotations
243
+
244
+ // src/Acme/BlogBundle/Entity/Author.php
245
+ namespace Acme\BlogBundle\Entity;
246
+
247
+ use Symfony\Component\Validator\Constraints as Assert;
248
+
249
+ class Author
250
+ {
251
+ /**
252
+ * @Assert\Url(
253
+ * checkDNS = true
254
+ * )
255
+ */
256
+ protected $bioUrl;
257
+ }
258
+
259
+ .. code-block :: yaml
260
+
261
+ # src/Acme/BlogBundle/Resources/config/validation.yml
262
+ Acme\BlogBundle\Entity\Author :
263
+ properties :
264
+ bioUrl :
265
+ - Url : { checkDNS: true }
266
+
267
+ .. code-block :: xml
268
+
269
+ <!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
270
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
271
+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
272
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
273
+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
274
+
275
+ <class name =" Acme\BlogBundle\Entity\Author" >
276
+ <property name =" bioUrl" >
277
+ <constraint name =" Url" >
278
+ <option name =" checkDNS" >true</option >
279
+ </constraint >
280
+ </property >
281
+ </class >
282
+ </constraint-mapping >
283
+
284
+ .. code-block :: php
285
+
286
+ // src/Acme/BlogBundle/Entity/Author.php
287
+ namespace Acme\BlogBundle\Entity;
288
+
289
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
290
+ use Symfony\Component\Validator\Constraints as Assert;
291
+
292
+ class Author
293
+ {
294
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
295
+ {
296
+ $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
297
+ 'checkDNS' => true,
298
+ )));
299
+ }
300
+ }
301
+
302
+ This option uses the :phpfunction: `checkdnsrr ` PHP function to check the validity
303
+ of the ``ANY `` DNS record corresponding to the host associated with the given URL.
0 commit comments