From 3395e025f127a320d8c32dc57db674c4860dd2eb Mon Sep 17 00:00:00 2001 From: Sarah KHALIL Date: Fri, 12 Dec 2014 00:19:14 +0100 Subject: [PATCH 1/6] [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 | 36 ++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 26715d55c02..b207fe5dc28 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -19,6 +19,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 @@ -29,19 +39,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 @@ -52,7 +57,13 @@ Basic Usage - + + + + @@ -69,7 +80,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'), + ))); } } From 07628c962433ab7ac4aedfce1a994ff4a794ec07 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 23 Jun 2015 13:26:47 +0200 Subject: [PATCH 2/6] 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 b207fe5dc28..0fc7bf8c6e0 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -17,6 +17,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 @@ -27,7 +93,6 @@ Basic Usage bioUrl: - Url: ~ message: The url "{{ value }}" is not a valid url. - protocols: [http, https] .. code-block:: php-annotations @@ -41,7 +106,6 @@ Basic Usage /** * @Assert\Url( * message = "The url '{{ value }}' is not a valid url", - * protocols = {"http", "https"} * ) */ protected $bioUrl; @@ -59,10 +123,6 @@ Basic Usage - @@ -82,26 +142,82 @@ 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'), + ))); + } + } From fa7ca6d670f95ebbdb838b900c68d3fb22ad676b Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 24 Jun 2015 16:37:38 +0200 Subject: [PATCH 3/6] Fixed the order of the examples --- reference/constraints/Url.rst | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 0fc7bf8c6e0..9871fa8aba1 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -85,15 +85,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 @@ -111,6 +102,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 @@ -157,15 +157,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 @@ -183,6 +174,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 From f13625b22a89a511a54cf6fda6ba4ac39b624932 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 24 Jun 2015 16:38:33 +0200 Subject: [PATCH 4/6] Added the "payload" option back (was removed by mistake) --- reference/constraints/Url.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 9871fa8aba1..245192afc76 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -8,6 +8,11 @@ Validates that a value is a valid URL string. +----------------+---------------------------------------------------------------------+ | Options | - `message`_ | | | - `protocols`_ | +<<<<<<< HEAD +======= +| | - `payload`_ | +| | - `checkDNS`_ | +>>>>>>> Added the "payload" option back (was removed by mistake) +----------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` | +----------------+---------------------------------------------------------------------+ From 5d7b2a1346881bddda2a08d40a56ee1ee8ba3bc5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 26 Jun 2015 09:30:25 +0200 Subject: [PATCH 5/6] Fixed some errors and made some simplifications --- reference/constraints/Url.rst | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 245192afc76..e168c13dd31 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -8,11 +8,6 @@ Validates that a value is a valid URL string. +----------------+---------------------------------------------------------------------+ | Options | - `message`_ | | | - `protocols`_ | -<<<<<<< HEAD -======= -| | - `payload`_ | -| | - `checkDNS`_ | ->>>>>>> Added the "payload" option back (was removed by mistake) +----------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\Url` | +----------------+---------------------------------------------------------------------+ @@ -113,7 +108,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 @@ -185,8 +180,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 From 1135910c83a115582330de9264a5789c46b263ca Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 26 Jun 2015 09:46:30 +0200 Subject: [PATCH 6/6] 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 e168c13dd31..2a4cace9c86 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -19,14 +19,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 @@ -42,6 +34,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