From 75da2f33448f4d22a13ab406c8ffe325a72c7883 Mon Sep 17 00:00:00 2001 From: Sarah KHALIL Date: Fri, 12 Dec 2014 00:19:14 +0100 Subject: [PATCH 1/7] [Validator] Updated documentation of URL validator Updated the documentation regarding the Pull Request on Symfony : https://github.com/symfony/symfony/pull/12956 --- reference/constraints/Url.rst | 126 ++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 14 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index a1ca08a4a34..5094161fa0c 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -8,7 +8,7 @@ Validates that a value is a valid URL string. +----------------+---------------------------------------------------------------------+ | Options | - `message`_ | | | - `protocols`_ | -| | - `payload`_ | +| | - `checkDNS`_ | +----------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` | +----------------+---------------------------------------------------------------------+ @@ -20,6 +20,16 @@ Basic Usage .. configuration-block:: + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + message: The url "{{ value }}" is not a valid url. + protocols: [http, https] + .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -30,19 +40,14 @@ Basic Usage class Author { /** - * @Assert\Url() + * @Assert\Url( + * message = "The url '{{ value }}' is not a valid url", + * protocols = {"http", "https"} + * ) */ protected $bioUrl; } - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioUrl: - - Url: ~ - .. code-block:: xml @@ -53,7 +58,13 @@ Basic Usage - + + + + @@ -70,7 +81,10 @@ Basic Usage { public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addPropertyConstraint('bioUrl', new Assert\Url()); + $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array( + 'message' => 'The url "{{ value }}" is not a valid url.', + 'protocols' => array('http', 'https'), + ))); } } @@ -91,6 +105,90 @@ protocols The protocols that will be considered to be valid. For example, if you also needed ``ftp://`` type URLs to be valid, you'd redefine the ``protocols`` -array, listing ``http``, ``https`` and also ``ftp``. +array, listing ``http``, ``https``, and also ``ftp``. + +checkDNS +~~~~~~~~ + +**type**: ``Boolean`` **default**: ``false`` + +By default, this constraint just validates the syntax of the given URL. If you +also need to check whether the associated host exists, set the ``checkDNS`` +option to ``true``: + +.. configuration-block:: + + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + message: The url "{{ value }}" is not a valid url. + protocols: [http, https] + checkDNS: true + + .. code-block:: php-annotations + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\Url( + * message = "The url '{{ value }}' is not a valid url", + * protocols = {"http", "https"} + * checkDNS = true + * ) + */ + protected $bioUrl; + } + + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array( + 'message' => 'The url "{{ value }}" is not a valid url.', + 'protocols' => array('http', 'https'), + 'checkDNS' => true, + ))); + } + } -.. include:: /reference/constraints/_payload-option.rst.inc +This option uses the :phpfunction:`checkdnsrr` PHP function to check the validity +of the ``ANY`` DNS record corresponding to the host associated with the given URL. From bb3dd4e6d83272f1fb2d723ad0518e0c6d0fc923 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 23 Jun 2015 13:26:47 +0200 Subject: [PATCH 2/7] Simplified the first example and added more examples --- reference/constraints/Url.rst | 154 +++++++++++++++++++++++++++++----- 1 file changed, 135 insertions(+), 19 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 5094161fa0c..dd3b3080577 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -18,6 +18,72 @@ Validates that a value is a valid URL string. Basic Usage ----------- +.. configuration-block:: + + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + + .. code-block:: php-annotations + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\Url() + */ + protected $bioUrl; + } + + .. code-block:: xml + + + + + + + + + + + + + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('bioUrl', new Assert\Url()); + } + } + +Options +------- + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value is not a valid URL.`` + +This message is shown if the URL is invalid. + .. configuration-block:: .. code-block:: yaml @@ -28,7 +94,6 @@ Basic Usage bioUrl: - Url: ~ message: The url "{{ value }}" is not a valid url. - protocols: [http, https] .. code-block:: php-annotations @@ -42,7 +107,6 @@ Basic Usage /** * @Assert\Url( * message = "The url '{{ value }}' is not a valid url", - * protocols = {"http", "https"} * ) */ protected $bioUrl; @@ -60,10 +124,6 @@ Basic Usage - @@ -83,29 +143,85 @@ Basic Usage { $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array( 'message' => 'The url "{{ value }}" is not a valid url.', - 'protocols' => array('http', 'https'), ))); } } -Options -------- +protocols +~~~~~~~~~ -message -~~~~~~~ +**type**: ``array`` **default**: ``array('http', 'https')`` -**type**: ``string`` **default**: ``This value is not a valid URL.`` +The protocols considered to be valid for the URL. For example, if you also consider +the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing +``http``, ``https``, and also ``ftp``. -This message is shown if the URL is invalid. +.. configuration-block:: -protocols -~~~~~~~~~ + .. code-block:: yaml -**type**: ``array`` **default**: ``array('http', 'https')`` + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + protocols: [http, https, ftp] + + .. code-block:: php-annotations + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\Url( + * protocols = {"http", "https", "ftp"} + * ) + */ + protected $bioUrl; + } + + .. code-block:: xml -The protocols that will be considered to be valid. For example, if you also -needed ``ftp://`` type URLs to be valid, you'd redefine the ``protocols`` -array, listing ``http``, ``https``, and also ``ftp``. + + + + + + + + + + + + + + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array( + 'protocols' => array('http', 'https', 'ftp'), + ))); + } + } checkDNS ~~~~~~~~ From 1d3b192f8a71b263970bb6adb7261855425fd1c4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 24 Jun 2015 16:36:10 +0200 Subject: [PATCH 3/7] Boolean -> boolean --- reference/constraints/Url.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index dd3b3080577..f1fff02ceb1 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -226,7 +226,7 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing checkDNS ~~~~~~~~ -**type**: ``Boolean`` **default**: ``false`` +**type**: ``boolean`` **default**: ``false`` By default, this constraint just validates the syntax of the given URL. If you also need to check whether the associated host exists, set the ``checkDNS`` From a2fd9ef3439c057d2b8a9cf2f5b208a13ae56ff2 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 24 Jun 2015 16:37:38 +0200 Subject: [PATCH 4/7] Fixed the order of the examples --- reference/constraints/Url.rst | 58 +++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index f1fff02ceb1..f03f5bb1187 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -86,15 +86,6 @@ This message is shown if the URL is invalid. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioUrl: - - Url: ~ - message: The url "{{ value }}" is not a valid url. - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -112,6 +103,15 @@ This message is shown if the URL is invalid. protected $bioUrl; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + message: The url "{{ value }}" is not a valid url. + .. code-block:: xml @@ -158,15 +158,6 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioUrl: - - Url: ~ - protocols: [http, https, ftp] - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -184,6 +175,15 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing protected $bioUrl; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + protocols: [http, https, ftp] + .. code-block:: xml @@ -234,17 +234,6 @@ option to ``true``: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioUrl: - - Url: ~ - message: The url "{{ value }}" is not a valid url. - protocols: [http, https] - checkDNS: true - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -264,6 +253,17 @@ option to ``true``: protected $bioUrl; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + message: The url "{{ value }}" is not a valid url. + protocols: [http, https] + checkDNS: true + .. code-block:: xml From 5bcd48d2a47ec1325315ab4e6b67e3d0abd25b59 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 24 Jun 2015 16:38:33 +0200 Subject: [PATCH 5/7] Added the "payload" option back (was removed by mistake) --- reference/constraints/Url.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index f03f5bb1187..66dbc424690 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -8,6 +8,7 @@ Validates that a value is a valid URL string. +----------------+---------------------------------------------------------------------+ | Options | - `message`_ | | | - `protocols`_ | +| | - `payload`_ | | | - `checkDNS`_ | +----------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` | @@ -223,6 +224,8 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing } } +.. include:: /reference/constraints/_payload-option.rst.inc + checkDNS ~~~~~~~~ From a04b4acadf6822248677378c5cd4e309177a50bd Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 26 Jun 2015 09:30:25 +0200 Subject: [PATCH 6/7] Fixed some errors and made some simplifications --- reference/constraints/Url.rst | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 66dbc424690..7dec7589015 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -110,7 +110,7 @@ This message is shown if the URL is invalid. Acme\BlogBundle\Entity\Author: properties: bioUrl: - - Url: ~ + - Url: message: The url "{{ value }}" is not a valid url. .. code-block:: xml @@ -182,8 +182,7 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing Acme\BlogBundle\Entity\Author: properties: bioUrl: - - Url: ~ - protocols: [http, https, ftp] + - Url: { protocols: [http, https, ftp] } .. code-block:: xml @@ -248,8 +247,6 @@ option to ``true``: { /** * @Assert\Url( - * message = "The url '{{ value }}' is not a valid url", - * protocols = {"http", "https"} * checkDNS = true * ) */ @@ -262,10 +259,7 @@ option to ``true``: Acme\BlogBundle\Entity\Author: properties: bioUrl: - - Url: ~ - message: The url "{{ value }}" is not a valid url. - protocols: [http, https] - checkDNS: true + - Url: { checkDNS: true } .. code-block:: xml @@ -278,11 +272,6 @@ option to ``true``: - - @@ -302,9 +291,7 @@ option to ``true``: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array( - 'message' => 'The url "{{ value }}" is not a valid url.', - 'protocols' => array('http', 'https'), - 'checkDNS' => true, + 'checkDNS' => true, ))); } } From 2becf60dcbafc593ed984b050db3dc65e924abf7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 26 Jun 2015 09:46:30 +0200 Subject: [PATCH 7/7] Reordered the configuration blocks of the first example --- reference/constraints/Url.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 7dec7589015..a30c1f31ce1 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -21,14 +21,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioUrl: - - Url: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -44,6 +36,14 @@ Basic Usage protected $bioUrl; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + .. code-block:: xml pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy