@@ -8,6 +8,7 @@ Validates that a value is a valid URL string.
8
8
+----------------+---------------------------------------------------------------------+
9
9
| Options | - `message `_ |
10
10
| | - `protocols `_ |
11
+ | | _ `checkDNS `_ |
11
12
+----------------+---------------------------------------------------------------------+
12
13
| Class | :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Url ` |
13
14
+----------------+---------------------------------------------------------------------+
@@ -26,6 +27,9 @@ Basic Usage
26
27
properties :
27
28
bioUrl :
28
29
- Url : ~
30
+ message : The url "{{ value }}" is not a valid url.
31
+ protocols : [http, https]
32
+ checkDNS : true
29
33
30
34
.. code-block :: php-annotations
31
35
@@ -37,7 +41,11 @@ Basic Usage
37
41
class Author
38
42
{
39
43
/**
40
- * @Assert\Url()
44
+ * @Assert\Url(
45
+ * message = "The url '{{ value }}' is not a valid url",
46
+ * protocols = {"http", "https"}
47
+ * checkDNS = true
48
+ * )
41
49
*/
42
50
protected $bioUrl;
43
51
}
@@ -52,7 +60,14 @@ Basic Usage
52
60
53
61
<class name =" Acme\BlogBundle\Entity\Author" >
54
62
<property name =" bioUrl" >
55
- <constraint name =" Url" />
63
+ <constraint name =" Url" >
64
+ <option name =" message" >The url "{{ value }}" is not a valid url.</option >
65
+ <option name =" protocols" >
66
+ <value >http</value >
67
+ <value >https</value >
68
+ </option >
69
+ <option name =" checkDNS" >true</option >
70
+ </constraint >
56
71
</property >
57
72
</class >
58
73
</constraint-mapping >
@@ -69,7 +84,11 @@ Basic Usage
69
84
{
70
85
public static function loadValidatorMetadata(ClassMetadata $metadata)
71
86
{
72
- $metadata->addPropertyConstraint('bioUrl', new Assert\Url());
87
+ $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
88
+ 'message' => 'The url "{{ value }}" is not a valid url.',
89
+ 'protocols' => array('http', 'https'),
90
+ 'checkDNS' => true,
91
+ )));
73
92
}
74
93
}
75
94
@@ -91,3 +110,11 @@ protocols
91
110
The protocols that will be considered to be valid. For example, if you also
92
111
needed ``ftp:// `` type URLs to be valid, you'd redefine the ``protocols ``
93
112
array, listing ``http ``, ``https ``, and also ``ftp ``.
113
+
114
+ checkDNS
115
+ ~~~~~~~~
116
+
117
+ **type **: ``Boolean `` **default **: ``false ``
118
+
119
+ If true, then the :phpfunction: `checkdnsrr ` PHP function will be used to check
120
+ the validity of ANY record of the host of the given url.
0 commit comments