@@ -84,13 +84,142 @@ message
8484
8585This message is shown if the URL is invalid.
8686
87+ .. configuration-block ::
88+
89+ .. code-block :: php-annotations
90+
91+ // src/Acme/BlogBundle/Entity/Author.php
92+ namespace Acme\BlogBundle\Entity;
93+
94+ use Symfony\Component\Validator\Constraints as Assert;
95+
96+ class Author
97+ {
98+ /**
99+ * @Assert\Url(
100+ * message = "The url '{{ value }}' is not a valid url",
101+ * )
102+ */
103+ protected $bioUrl;
104+ }
105+
106+ .. code-block :: yaml
107+
108+ # src/Acme/BlogBundle/Resources/config/validation.yml
109+ Acme\BlogBundle\Entity\Author :
110+ properties :
111+ bioUrl :
112+ - Url :
113+ message : The url "{{ value }}" is not a valid url.
114+
115+ .. code-block :: xml
116+
117+ <!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
118+ <?xml version =" 1.0" encoding =" UTF-8" ?>
119+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
120+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
121+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
122+
123+ <class name =" Acme\BlogBundle\Entity\Author" >
124+ <property name =" bioUrl" >
125+ <constraint name =" Url" >
126+ <option name =" message" >The url "{{ value }}" is not a valid url.</option >
127+ </constraint >
128+ </property >
129+ </class >
130+ </constraint-mapping >
131+
132+ .. code-block :: php
133+
134+ // src/Acme/BlogBundle/Entity/Author.php
135+ namespace Acme\BlogBundle\Entity;
136+
137+ use Symfony\Component\Validator\Mapping\ClassMetadata;
138+ use Symfony\Component\Validator\Constraints as Assert;
139+
140+ class Author
141+ {
142+ public static function loadValidatorMetadata(ClassMetadata $metadata)
143+ {
144+ $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
145+ 'message' => 'The url "{{ value }}" is not a valid url.',
146+ )));
147+ }
148+ }
149+
87150 protocols
88151~~~~~~~~~
89152
90153**type **: ``array `` **default **: ``array('http', 'https') ``
91154
92- The protocols that will be considered to be valid. For example, if you also
93- needed ``ftp:// `` type URLs to be valid, you'd redefine the ``protocols ``
94- array, listing ``http ``, ``https `` and also ``ftp ``.
155+ The protocols considered to be valid for the URL. For example, if you also consider
156+ the ``ftp:// `` type URLs to be valid, redefine the ``protocols `` array, listing
157+ ``http ``, ``https ``, and also ``ftp ``.
158+
159+ .. configuration-block ::
160+
161+ .. code-block :: php-annotations
162+
163+ // src/Acme/BlogBundle/Entity/Author.php
164+ namespace Acme\BlogBundle\Entity;
165+
166+ use Symfony\Component\Validator\Constraints as Assert;
167+
168+ class Author
169+ {
170+ /**
171+ * @Assert\Url(
172+ * protocols = {"http", "https", "ftp"}
173+ * )
174+ */
175+ protected $bioUrl;
176+ }
177+
178+ .. code-block :: yaml
179+
180+ # src/Acme/BlogBundle/Resources/config/validation.yml
181+ Acme\BlogBundle\Entity\Author :
182+ properties :
183+ bioUrl :
184+ - Url : { protocols: [http, https, ftp] }
185+
186+ .. code-block :: xml
187+
188+ <!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
189+ <?xml version =" 1.0" encoding =" UTF-8" ?>
190+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
191+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
192+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
193+
194+ <class name =" Acme\BlogBundle\Entity\Author" >
195+ <property name =" bioUrl" >
196+ <constraint name =" Url" >
197+ <option name =" protocols" >
198+ <value >http</value >
199+ <value >https</value >
200+ <value >ftp</value >
201+ </option >
202+ </constraint >
203+ </property >
204+ </class >
205+ </constraint-mapping >
206+
207+ .. code-block :: php
208+
209+ // src/Acme/BlogBundle/Entity/Author.php
210+ namespace Acme\BlogBundle\Entity;
211+
212+ use Symfony\Component\Validator\Mapping\ClassMetadata;
213+ use Symfony\Component\Validator\Constraints as Assert;
214+
215+ class Author
216+ {
217+ public static function loadValidatorMetadata(ClassMetadata $metadata)
218+ {
219+ $metadata->addPropertyConstraint('bioUrl', new Assert\Url(array(
220+ 'protocols' => array('http', 'https', 'ftp'),
221+ )));
222+ }
223+ }
95224
96225 .. include :: /reference/constraints/_payload-option.rst.inc
0 commit comments