Skip to content

Commit 4ef9034

Browse files
committed
[Validator] Updated documentation of URL validator
Updated the documentation regarding the Pull Request on Symfony : symfony/symfony#12956
1 parent fc3e50b commit 4ef9034

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

reference/constraints/Url.rst

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Validates that a value is a valid URL string.
88
+----------------+---------------------------------------------------------------------+
99
| Options | - `message`_ |
1010
| | - `protocols`_ |
11+
| | _ `checkDNS`_ |
1112
+----------------+---------------------------------------------------------------------+
1213
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` |
1314
+----------------+---------------------------------------------------------------------+
@@ -26,6 +27,9 @@ Basic Usage
2627
properties:
2728
bioUrl:
2829
- Url: ~
30+
message: The url "{{ value }}" is not a valid url.
31+
protocols: [http, https]
32+
checkDNS: true
2933
3034
.. code-block:: php-annotations
3135
@@ -37,7 +41,11 @@ Basic Usage
3741
class Author
3842
{
3943
/**
40-
* @Assert\Url()
44+
* @Assert\Url(
45+
* message = "The url '{{ value }}' is not a valid url",
46+
* protocols = {"http", "https"}
47+
* checkDNS = true
48+
* )
4149
*/
4250
protected $bioUrl;
4351
}
@@ -52,7 +60,14 @@ Basic Usage
5260
5361
<class name="Acme\BlogBundle\Entity\Author">
5462
<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>
5671
</property>
5772
</class>
5873
</constraint-mapping>
@@ -69,7 +84,11 @@ Basic Usage
6984
{
7085
public static function loadValidatorMetadata(ClassMetadata $metadata)
7186
{
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+
)));
7392
}
7493
}
7594
@@ -91,3 +110,11 @@ protocols
91110
The protocols that will be considered to be valid. For example, if you also
92111
needed ``ftp://`` type URLs to be valid, you'd redefine the ``protocols``
93112
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

Comments
 (0)