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