Skip to content

Use Php8 attributes in validation.md #1302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 24 additions & 34 deletions core/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use Symfony\Component\Validator\Constraints as Assert; // Symfony's built-in con
/**
* A product.
*
* @ApiResource
* @ORM\Entity
*/
#[ApiResource]
class Product
{
/**
Expand Down Expand Up @@ -138,10 +138,7 @@ You can configure the groups you want to use when the validation occurs directly
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;

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

/**
* @ApiResource(
* collectionOperations={
* "get",
* "post"={"validation_groups"={"Default", "postValidation"}}
* },
* itemOperations={
* "delete",
* "get",
* "put"={"validation_groups"={"Default", "putValidation"}}
* }
* )
* ...
*/
#[ApiResource(
collectionOperations: [
'get',
'post' => ['validation_groups' => ['Default', 'postValidation']]
],
itemOperations: [
'delete',
'get',
'put' => ['validation_groups' => ['Default', 'putValidation']]
]
)]
class Book
{
/**
Expand Down Expand Up @@ -247,11 +241,9 @@ In the following example, we use a static method to return the validation groups
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ApiResource(
* attributes={"validation_groups"={Book::class, "validationGroups"}}
* )
*/
#[ApiResource(
attributes: ['validation_groups' => [Book::class, 'validationGroups']]
)]
class Book
{
/**
Expand Down Expand Up @@ -329,9 +321,7 @@ use ApiPlatform\Core\Annotation\ApiResource;
use App\Validator\AdminGroupsGenerator;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ApiResource(attributes={"validation_groups"=AdminGroupsGenerator::class})
*/
#[ApiResource(attributes: ['validation_groups' => AdminGroupsGenerator::class])
class Book
{
/**
Expand Down Expand Up @@ -394,15 +384,15 @@ use App\Validator\MySequencedGroup; // the sequence group to use
use Doctrine\ORM\Mapping as ORM;

/**
* @ApiResource(
* collectionOperations={
* "post" = {
* "validation_groups" = MySequencedGroup::class
* }
* }
* )
* @ORM\Entity
*/
#[ApiResource(
collectionOperations: [
'post' => [
'validation_groups' => MySequencedGroup::class
]
]
)]
class Greeting
{
/**
Expand Down