Skip to content

Commit 9cabf0d

Browse files
committed
Added namespaces to examples
1 parent aad2668 commit 9cabf0d

19 files changed

+144
-55
lines changed

reference/constraints/All.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ entry in that array:
3434
3535
.. code-block:: php-annotations
3636
37-
// src/Acme/UserBundle/Entity/User.php
38-
namespace Acme\UserBundle\Entity;
39-
40-
use Symfony\Component\Validator\Constraints as Assert;
41-
42-
class User
43-
{
44-
/**
45-
* @Assert\All({
46-
* @Assert\NotBlank
47-
* @Assert\MinLength(5),
48-
* })
49-
*/
50-
protected $favoriteColors = array();
51-
}
37+
// src/Acme/UserBundle/Entity/User.php
38+
namespace Acme\UserBundle\Entity;
39+
40+
use Symfony\Component\Validator\Constraints as Assert;
41+
42+
class User
43+
{
44+
/**
45+
* @Assert\All({
46+
* @Assert\NotBlank
47+
* @Assert\MinLength(5),
48+
* })
49+
*/
50+
protected $favoriteColors = array();
51+
}
5252
5353
.. code-block:: xml
5454
@@ -69,6 +69,8 @@ entry in that array:
6969
.. code-block:: php
7070
7171
// src/Acme/UserBundle/Enttiy/User.php
72+
namespace Acme\UserBundle\Entity;
73+
7274
use Symfony\Component\Validator\Mapping\ClassMetadata;
7375
use Symfony\Component\Validator\Constraints as Assert;
7476

reference/constraints/Blank.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ of an ``Author`` class were blank, you could do the following:
2626

2727
.. code-block:: yaml
2828
29-
properties:
30-
firstName:
31-
- Blank: ~
29+
# src/BlogBundle/Resources/config/validation.yml
30+
Acme\BlogBundle\Entity\Author:
31+
properties:
32+
firstName:
33+
- Blank: ~
3234
3335
.. code-block:: php-annotations
3436
3537
// src/Acme/BlogBundle/Entity/Author.php
38+
namespace Acme\BlogBundle\Entity;
39+
3640
use Symfony\Component\Validator\Constraints as Assert;
3741
3842
class Author
@@ -55,6 +59,8 @@ of an ``Author`` class were blank, you could do the following:
5559
.. code-block:: php
5660
5761
// src/Acme/BlogBundle/Entity/Author.php
62+
namespace Acme\BlogBundle\Entity;
63+
5864
use Symfony\Component\Validator\Mapping\ClassMetadata;
5965
use Symfony\Component\Validator\Constraints as Assert;
6066

reference/constraints/Callback.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Setup
4343
.. code-block:: php-annotations
4444
4545
// src/Acme/BlogBundle/Entity/Author.php
46+
namespace Acme\BlogBundle\Entity;
47+
4648
use Symfony\Component\Validator\Constraints as Assert;
4749
4850
/**
@@ -66,6 +68,8 @@ Setup
6668
.. code-block:: php
6769
6870
// src/Acme/BlogBundle/Entity/Author.php
71+
namespace Acme\BlogBundle\Entity;
72+
6973
use Symfony\Component\Validator\Mapping\ClassMetadata;
7074
use Symfony\Component\Validator\Constraints as Assert;
7175

reference/constraints/Choice.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ If your valid choice list is simple, you can pass them in directly via the
6464
.. code-block:: php-annotations
6565
6666
// src/Acme/BlogBundle/Entity/Author.php
67+
namespace Acme\BlogBundle\Entity;
68+
6769
use Symfony\Component\Validator\Constraints as Assert;
6870
6971
class Author
@@ -77,6 +79,8 @@ If your valid choice list is simple, you can pass them in directly via the
7779
.. code-block:: php
7880
7981
// src/Acme/BlogBundle/EntityAuthor.php
82+
namespace Acme\BlogBundle\Entity;
83+
8084
use Symfony\Component\Validator\Mapping\ClassMetadata;
8185
use Symfony\Component\Validator\Constraints as Assert;
8286

reference/constraints/Collection.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,25 @@ blank but is no longer than 100 characters in length, you would do the following
5353

5454
.. code-block:: yaml
5555
56-
properties:
57-
profileData:
58-
- Collection:
59-
fields:
60-
personal_email: Email
61-
short_bio:
62-
- NotBlank
63-
- MaxLength:
64-
limit: 100
65-
message: Your short bio is too long!
66-
allowMissingFields: true
56+
# src/BlogBundle/Resources/config/validation.yml
57+
Acme\BlogBundle\Entity\Author:
58+
properties:
59+
profileData:
60+
- Collection:
61+
fields:
62+
personal_email: Email
63+
short_bio:
64+
- NotBlank
65+
- MaxLength:
66+
limit: 100
67+
message: Your short bio is too long!
68+
allowMissingFields: true
6769
6870
.. code-block:: php-annotations
6971
7072
// src/Acme/BlogBundle/Entity/Author.php
73+
namespace Acme\BlogBundle\Entity;
74+
7175
use Symfony\Component\Validator\Constraints as Assert;
7276
7377
class Author
@@ -119,6 +123,8 @@ blank but is no longer than 100 characters in length, you would do the following
119123
.. code-block:: php
120124
121125
// src/Acme/BlogBundle/Entity/Author.php
126+
namespace Acme\BlogBundle\Entity;
127+
122128
use Symfony\Component\Validator\Mapping\ClassMetadata;
123129
use Symfony\Component\Validator\Constraints as Assert;
124130

reference/constraints/Country.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Basic Usage
2929
.. code-block:: php-annotations
3030
3131
// src/Acme/UserBundle/Entity/User.php
32+
namespace Acme\UserBundle\Entity;
33+
3234
use Symfony\Component\Validator\Constraints as Assert;
3335
3436
class User
@@ -51,6 +53,8 @@ Basic Usage
5153
.. code-block:: php
5254
5355
// src/Acme/UserBundle/Entity/User.php
56+
namespace Acme\UserBundle\Entity;
57+
5458
use Symfony\Component\Validator\Mapping\ClassMetadata;
5559
use Symfony\Component\Validator\Constraints as Assert;
5660

reference/constraints/Date.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Basic Usage
3131
.. code-block:: php-annotations
3232
3333
// src/Acme/BlogBundle/Entity/Author.php
34+
namespace Acme\BlogBundle\Entity;
35+
3436
use Symfony\Component\Validator\Constraints as Assert;
3537
3638
class Author
@@ -53,6 +55,8 @@ Basic Usage
5355
.. code-block:: php
5456
5557
// src/Acme/BlogBundle/Entity/Author.php
58+
namespace Acme\BlogBundle\Entity;
59+
5660
use Symfony\Component\Validator\Mapping\ClassMetadata;
5761
use Symfony\Component\Validator\Constraints as Assert;
5862

reference/constraints/DateTime.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Basic Usage
5555
.. code-block:: php
5656
5757
// src/Acme/BlogBundle/Entity/Author.php
58+
namespace Acme\BlogBundle\Entity;
59+
5860
use Symfony\Component\Validator\Mapping\ClassMetadata;
5961
use Symfony\Component\Validator\Constraints as Assert;
6062

reference/constraints/False.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ method returns **false**:
6262
.. code-block:: php-annotations
6363
6464
// src/Acme/BlogBundle/Entity/Author.php
65+
namespace Acme\BlogBundle\Entity;
66+
6567
use Symfony\Component\Validator\Constraints as Assert;
6668
6769
class Author
@@ -78,6 +80,8 @@ method returns **false**:
7880
.. code-block:: php
7981
8082
// src/Acme/BlogBundle/Entity/Author.php
83+
namespace Acme\BlogBundle\Entity;
84+
8185
use Symfony\Component\Validator\Mapping\ClassMetadata;
8286
use Symfony\Component\Validator\Constraints as Assert;
8387

reference/constraints/File.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ below a certain file size and a valid PDF, add the following:
8383
.. code-block:: php-annotations
8484
8585
// src/Acme/BlogBundle/Entity/Author.php
86+
namespace Acme\BlogBundle\Entity;
87+
8688
use Symfony\Component\Validator\Constraints as Assert;
8789
8890
class Author
@@ -116,6 +118,8 @@ below a certain file size and a valid PDF, add the following:
116118
.. code-block:: php
117119
118120
// src/Acme/BlogBundle/Entity/Author.php
121+
namespace Acme\BlogBundle\Entity;
122+
119123
use Symfony\Component\Validator\Mapping\ClassMetadata;
120124
use Symfony\Component\Validator\Constraints\File;
121125

reference/constraints/Max.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ add the following:
3434
.. code-block:: php-annotations
3535
3636
// src/Acme/EventBundle/Entity/Participant.php
37+
namespace Acme\EventBundle\Entity;
38+
3739
use Symfony\Component\Validator\Constraints as Assert;
3840
3941
class Participant
@@ -59,6 +61,8 @@ add the following:
5961
.. code-block:: php
6062
6163
// src/Acme/EventBundle/Entity/Participant.php
64+
namespace Acme\EventBundle\Entity;
65+
6266
use Symfony\Component\Validator\Mapping\ClassMetadata;
6367
use Symfony\Component\Validator\Constraints as Assert;
6468

reference/constraints/MaxLength.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Basic Usage
3131
.. code-block:: php-annotations
3232
3333
// src/Acme/BlogBundle/Entity/Blog.php
34+
namespace Acme\BlogBundle\Entity;
35+
3436
use Symfony\Component\Validator\Constraints as Assert;
3537
3638
class Blog
@@ -52,6 +54,24 @@ Basic Usage
5254
</property>
5355
</class>
5456
57+
.. code-block:: php
58+
59+
// src/Acme/BlogBundle/Entity/Blog.php
60+
namespace Acme\BlogBundle\Entity;
61+
62+
use Symfony\Component\Validator\Mapping\ClassMetadata;
63+
use Symfony\Component\Validator\Constraints as Assert;
64+
65+
class Blog
66+
{
67+
public static function loadValidatorMetadata(ClassMetadata $metadata)
68+
{
69+
$metadata->addPropertyConstraint('summary', new Assert\MaxLength(array(
70+
'limit' => 100,
71+
)));
72+
}
73+
}
74+
5575
Options
5676
-------
5777

@@ -78,4 +98,4 @@ charset
7898

7999
If the PHP extension "mbstring" is installed, then the PHP function :phpfunction:`mb_strlen`
80100
will be used to calculate the length of the string. The value of the ``charset``
81-
option is passed as the second argument to that function.
101+
option is passed as the second argument to that function.

reference/constraints/Min.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ the following:
3434
.. code-block:: php-annotations
3535
3636
// src/Acme/EventBundle/Entity/Participant.php
37+
namespace Acme\EventBundle\Entity;
38+
3739
use Symfony\Component\Validator\Constraints as Assert;
3840
3941
class Participant
@@ -69,4 +71,4 @@ invalidMessage
6971
**type**: ``string`` **default**: ``This value should be a valid number``
7072

7173
The message that will be shown if the underlying value is not a number (per
72-
the :phpfunction:`is_numeric` PHP function).
74+
the :phpfunction:`is_numeric` PHP function).

reference/constraints/MinLength.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Basic Usage
3131
.. code-block:: php-annotations
3232
3333
// src/Acme/BlogBundle/Entity/Blog.php
34+
namespace Acme\BlogBundle\Entity;
35+
3436
use Symfony\Component\Validator\Constraints as Assert;
3537
3638
class Blog
@@ -59,6 +61,8 @@ Basic Usage
5961
.. code-block:: php
6062
6163
// src/Acme/BlogBundle/Entity/Blog.php
64+
namespace Acme\BlogBundle\Entity;
65+
6266
use Symfony\Component\Validator\Mapping\ClassMetadata;
6367
use Symfony\Component\Validator\Constraints as Assert;
6468

reference/constraints/NotBlank.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ were not blank, you could do the following:
2525

2626
.. code-block:: yaml
2727
28-
properties:
29-
firstName:
30-
- NotBlank: ~
28+
# src/BlogBundle/Resources/config/validation.yml
29+
Acme\BlogBundle\Entity\Author:
30+
properties:
31+
firstName:
32+
- NotBlank: ~
3133
3234
.. code-block:: php-annotations
3335
3436
// src/Acme/BlogBundle/Entity/Author.php
37+
namespace Acme\BlogBundle\Entity;
38+
3539
use Symfony\Component\Validator\Constraints as Assert;
3640
3741
class Author
@@ -54,6 +58,8 @@ were not blank, you could do the following:
5458
.. code-block:: php
5559
5660
// src/Acme/BlogBundle/Entity/Author.php
61+
namespace Acme\BlogBundle\Entity;
62+
5763
use Symfony\Component\Validator\Mapping\ClassMetadata;
5864
use Symfony\Component\Validator\Constraints as Assert;
5965

reference/constraints/NotNull.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ were not strictly equal to ``null``, you would:
2525

2626
.. code-block:: yaml
2727
28-
properties:
29-
firstName:
30-
- NotNull: ~
28+
# src/BlogBundle/Resources/config/validation.yml
29+
Acme\BlogBundle\Entity\Author:
30+
properties:
31+
firstName:
32+
- NotNull: ~
3133
3234
.. code-block:: php-annotations
3335
3436
// src/Acme/BlogBundle/Entity/Author.php
37+
namespace Acme\BlogBundle\Entity;
38+
3539
use Symfony\Component\Validator\Constraints as Assert;
3640
3741
class Author
@@ -54,6 +58,8 @@ were not strictly equal to ``null``, you would:
5458
.. code-block:: php
5559
5660
// src/Acme/BlogBundle/Entity/Author.php
61+
namespace Acme\BlogBundle\Entity;
62+
5763
use Symfony\Component\Validator\Mapping\ClassMetadata;
5864
use Symfony\Component\Validator\Constraints as Assert;
5965

0 commit comments

Comments
 (0)