@@ -8,7 +8,7 @@ Validates that a value is a valid URL string.
88+----------------+---------------------------------------------------------------------+
99| Options | - `message `_ |
1010| | - `protocols `_ |
11- | | _ `checkDNS `_ |
11+ | | - `checkDNS `_ |
1212+----------------+---------------------------------------------------------------------+
1313| Class | :class: `Symfony\\ Component\\ Validator\\ Constraints\\ Url ` |
1414+----------------+---------------------------------------------------------------------+
@@ -29,7 +29,6 @@ Basic Usage
2929 - Url : ~
3030 message : The url "{{ value }}" is not a valid url.
3131 protocols : [http, https]
32- checkDNS : true
3332
3433 .. code-block :: php-annotations
3534
@@ -44,7 +43,6 @@ Basic Usage
4443 * @Assert\Url(
4544 * message = "The url '{{ value }}' is not a valid url",
4645 * protocols = {"http", "https"}
47- * checkDNS = true
4846 * )
4947 */
5048 protected $bioUrl;
@@ -66,7 +64,6 @@ Basic Usage
6664 <value >http</value >
6765 <value >https</value >
6866 </option >
69- <option name =" checkDNS" >true</option >
7067 </constraint >
7168 </property >
7269 </class >
@@ -87,7 +84,6 @@ Basic Usage
8784 $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
8885 'message' => 'The url "{{ value }}" is not a valid url.',
8986 'protocols' => array('http', 'https'),
90- 'checkDNS' => true,
9187 )));
9288 }
9389 }
@@ -116,5 +112,83 @@ checkDNS
116112
117113**type **: ``Boolean `` **default **: ``false ``
118114
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