@@ -10,7 +10,7 @@ for this task, but you can replace it with your preferred validation library suc
10
10
11
11
Validating submitted data is as simple as adding [ Symfony's built-in constraints] ( http://symfony.com/doc/current/reference/constraints.html )
12
12
or [ custom constraints] ( http://symfony.com/doc/current/validation/custom_constraint.html ) directly in classes marked with
13
- the ` #[ApiResource] ` annotation :
13
+ the ` #[ApiResource] ` attribute :
14
14
15
15
``` php
16
16
<?php
@@ -39,9 +39,8 @@ class Product
39
39
40
40
/**
41
41
* @var string[] Describe the product
42
- *
43
- * @MinimalProperties
44
42
*/
43
+ #[MinimalProperties]
45
44
#[ORM\Column(type: 'json')]
46
45
public $properties;
47
46
@@ -59,9 +58,7 @@ namespace App\Validator\Constraints;
59
58
60
59
use Symfony\Component\Validator\Constraint;
61
60
62
- /**
63
- * @Annotation
64
- */
61
+ #[\Attribute]
65
62
class MinimalProperties extends Constraint
66
63
{
67
64
public $message = 'The product must have the minimal properties required ("description", "price")';
@@ -77,9 +74,6 @@ namespace App\Validator\Constraints;
77
74
use Symfony\Component\Validator\Constraint;
78
75
use Symfony\Component\Validator\ConstraintValidator;
79
76
80
- /**
81
- * @Annotation
82
- */
83
77
final class MinimalPropertiesValidator extends ConstraintValidator
84
78
{
85
79
public function validate($value, Constraint $constraint): void
@@ -118,7 +112,7 @@ errors to HTTP errors.
118
112
Without specific configuration, the default validation group is always used, but this behavior is customizable: the framework
119
113
is able to leverage Symfony's [ validation groups] ( https://symfony.com/doc/current/validation/groups.html ) .
120
114
121
- You can configure the groups you want to use when the validation occurs directly through the ` ApiResource ` annotation :
115
+ You can configure the groups you want to use when the validation occurs directly through the ` ApiResource ` attribute :
122
116
123
117
``` php
124
118
<?php
@@ -145,7 +139,7 @@ With the previous configuration, the validation groups `a` and `b` will be used
145
139
Like for [ serialization groups] ( serialization.md#using-different-serialization-groups-per-operation ) ,
146
140
you can specify validation groups globally or on a per-operation basis.
147
141
148
- Of course, you can use XML or YAML configuration format instead of annotations if you prefer.
142
+ Of course, you can use XML or YAML configuration format instead of attributes if you prefer.
149
143
150
144
You may also pass in a [ group sequence] ( http://symfony.com/doc/current/validation/sequence_provider.html ) in place of
151
145
the array of group names.
0 commit comments