Skip to content

Commit b93eb7c

Browse files
authored
Use Php8 attributes in validation.md (#1302)
1 parent e37294a commit b93eb7c

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

core/validation.md

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use Symfony\Component\Validator\Constraints as Assert; // Symfony's built-in con
2626
/**
2727
* A product.
2828
*
29-
* @ApiResource
3029
* @ORM\Entity
3130
*/
31+
#[ApiResource]
3232
class Product
3333
{
3434
/**
@@ -138,10 +138,7 @@ You can configure the groups you want to use when the validation occurs directly
138138
use ApiPlatform\Core\Annotation\ApiResource;
139139
use Symfony\Component\Validator\Constraints as Assert;
140140

141-
/**
142-
* @ApiResource(attributes={"validation_groups"={"a", "b"}})
143-
* ...
144-
*/
141+
#[ApiResource(attributes: ['validation_groups' => ['a', 'b']])]
145142
class Book
146143
{
147144
/**
@@ -179,20 +176,17 @@ You can have different validation for each [operation](operations.md) related to
179176
use ApiPlatform\Core\Annotation\ApiResource;
180177
use Symfony\Component\Validator\Constraints as Assert;
181178

182-
/**
183-
* @ApiResource(
184-
* collectionOperations={
185-
* "get",
186-
* "post"={"validation_groups"={"Default", "postValidation"}}
187-
* },
188-
* itemOperations={
189-
* "delete",
190-
* "get",
191-
* "put"={"validation_groups"={"Default", "putValidation"}}
192-
* }
193-
* )
194-
* ...
195-
*/
179+
#[ApiResource(
180+
collectionOperations: [
181+
'get',
182+
'post' => ['validation_groups' => ['Default', 'postValidation']]
183+
],
184+
itemOperations: [
185+
'delete',
186+
'get',
187+
'put' => ['validation_groups' => ['Default', 'putValidation']]
188+
]
189+
)]
196190
class Book
197191
{
198192
/**
@@ -247,11 +241,9 @@ In the following example, we use a static method to return the validation groups
247241
use ApiPlatform\Core\Annotation\ApiResource;
248242
use Symfony\Component\Validator\Constraints as Assert;
249243

250-
/**
251-
* @ApiResource(
252-
* attributes={"validation_groups"={Book::class, "validationGroups"}}
253-
* )
254-
*/
244+
#[ApiResource(
245+
attributes: ['validation_groups' => [Book::class, 'validationGroups']]
246+
)]
255247
class Book
256248
{
257249
/**
@@ -329,9 +321,7 @@ use ApiPlatform\Core\Annotation\ApiResource;
329321
use App\Validator\AdminGroupsGenerator;
330322
use Symfony\Component\Validator\Constraints as Assert;
331323

332-
/**
333-
* @ApiResource(attributes={"validation_groups"=AdminGroupsGenerator::class})
334-
*/
324+
#[ApiResource(attributes: ['validation_groups' => AdminGroupsGenerator::class])
335325
class Book
336326
{
337327
/**
@@ -394,15 +384,15 @@ use App\Validator\MySequencedGroup; // the sequence group to use
394384
use Doctrine\ORM\Mapping as ORM;
395385

396386
/**
397-
* @ApiResource(
398-
* collectionOperations={
399-
* "post" = {
400-
* "validation_groups" = MySequencedGroup::class
401-
* }
402-
* }
403-
* )
404387
* @ORM\Entity
405388
*/
389+
#[ApiResource(
390+
collectionOperations: [
391+
'post' => [
392+
'validation_groups' => MySequencedGroup::class
393+
]
394+
]
395+
)]
406396
class Greeting
407397
{
408398
/**

0 commit comments

Comments
 (0)