@@ -8,7 +8,7 @@ Validates that a value is a valid URL string.
8
8
+----------------+---------------------------------------------------------------------+
9
9
| Options | - `message `_ |
10
10
| | - `protocols `_ |
11
- | | _ `checkDNS `_ |
11
+ | | - `checkDNS `_ |
12
12
+----------------+---------------------------------------------------------------------+
13
13
| Class | :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Url ` |
14
14
+----------------+---------------------------------------------------------------------+
@@ -29,7 +29,6 @@ Basic Usage
29
29
- Url : ~
30
30
message : The url "{{ value }}" is not a valid url.
31
31
protocols : [http, https]
32
- checkDNS : true
33
32
34
33
.. code-block :: php-annotations
35
34
@@ -44,7 +43,6 @@ Basic Usage
44
43
* @Assert\Url(
45
44
* message = "The url '{{ value }}' is not a valid url",
46
45
* protocols = {"http", "https"}
47
- * checkDNS = true
48
46
* )
49
47
*/
50
48
protected $bioUrl;
@@ -66,7 +64,6 @@ Basic Usage
66
64
<value >http</value >
67
65
<value >https</value >
68
66
</option >
69
- <option name =" checkDNS" >true</option >
70
67
</constraint >
71
68
</property >
72
69
</class >
@@ -87,7 +84,6 @@ Basic Usage
87
84
$metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
88
85
'message' => 'The url "{{ value }}" is not a valid url.',
89
86
'protocols' => array('http', 'https'),
90
- 'checkDNS' => true,
91
87
)));
92
88
}
93
89
}
@@ -116,5 +112,83 @@ checkDNS
116
112
117
113
**type **: ``Boolean `` **default **: ``false ``
118
114
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.
115
+ By default, this constraint just validates the syntax of the given URL. If you
116
+ also need to check whether the associated host exists, set the ``checkDNS ``
117
+ option to ``true ``:
118
+
119
+ .. configuration-block ::
120
+
121
+ .. code-block :: yaml
122
+
123
+ # src/Acme/BlogBundle/Resources/config/validation.yml
124
+ Acme\BlogBundle\Entity\Author :
125
+ properties :
126
+ bioUrl :
127
+ - Url : ~
128
+ message : The url "{{ value }}" is not a valid url.
129
+ protocols : [http, https]
130
+ checkDNS : true
131
+
132
+ .. code-block :: php-annotations
133
+
134
+ // src/Acme/BlogBundle/Entity/Author.php
135
+ namespace Acme\BlogBundle\Entity;
136
+
137
+ use Symfony\Component\Validator\Constraints as Assert;
138
+
139
+ class Author
140
+ {
141
+ /**
142
+ * @Assert\Url(
143
+ * message = "The url '{{ value }}' is not a valid url",
144
+ * protocols = {"http", "https"}
145
+ * checkDNS = true
146
+ * )
147
+ */
148
+ protected $bioUrl;
149
+ }
150
+
151
+ .. code-block :: xml
152
+
153
+ <!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
154
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
155
+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
156
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
157
+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
158
+
159
+ <class name =" Acme\BlogBundle\Entity\Author" >
160
+ <property name =" bioUrl" >
161
+ <constraint name =" Url" >
162
+ <option name =" message" >The url "{{ value }}" is not a valid url.</option >
163
+ <option name =" protocols" >
164
+ <value >http</value >
165
+ <value >https</value >
166
+ </option >
167
+ <option name =" checkDNS" >true</option >
168
+ </constraint >
169
+ </property >
170
+ </class >
171
+ </constraint-mapping >
172
+
173
+ .. code-block :: php
174
+
175
+ // src/Acme/BlogBundle/Entity/Author.php
176
+ namespace Acme\BlogBundle\Entity;
177
+
178
+ use Symfony\Component\Validator\Mapping\ClassMetadata;
179
+ use Symfony\Component\Validator\Constraints as Assert;
180
+
181
+ class Author
182
+ {
183
+ public static function loadValidatorMetadata(ClassMetadata $metadata)
184
+ {
185
+ $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
186
+ 'message' => 'The url "{{ value }}" is not a valid url.',
187
+ 'protocols' => array('http', 'https'),
188
+ 'checkDNS' => true,
189
+ )));
190
+ }
191
+ }
192
+
193
+ This option uses the :phpfunction: `checkdnsrr ` PHP function to check the validity
194
+ of the ``ANY `` DNS record corresponding to the host associated with the given URL.
0 commit comments