Skip to content

Instantly share code, notes, and snippets.

@atillay
Last active November 11, 2021 12:15
Show Gist options
  • Save atillay/abb154ca63b2e6752dd8a768346f9761 to your computer and use it in GitHub Desktop.
Save atillay/abb154ca63b2e6752dd8a768346f9761 to your computer and use it in GitHub Desktop.
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(
* collectionOperations={
* "get"={
* "denormalization_context"={"groups"={"my-entity:get_col"}},
* "normalization_context"={"groups"={"my-entity:get_col"}}
* },
* "post"={
* "denormalization_context"={"groups"={"my-entity:post", "my-entity:post:in"}},
* "normalization_context"={"groups"={"my-entity:post", "my-entity:post:out"}}
* }
* },
* itemOperations={
* "get"={
* "denormalization_context"={"groups"={"my-entity:get_item"}},
* "normalization_context"={"groups"={"my-entity:get_item"}}
* },
* "get_custom"={
* "method"="GET",
* "path"="/my-entity/{id}/custom",
* "denormalization_context"={"groups"={"my-entity:get_custom"}},
* "normalization_context"={"groups"={"my-entity:get_custom"}}
* },
* "put"={
* "denormalization_context"={"groups"={"my-entity:put", "my-entity:put:in"}},
* "normalization_context"={"groups"={"my-entity:put", "my-entity:put:out"}}
* },
* "put_custom"={
* "method"="PUT",
* "path"="/my-entity/{id}/custom",
* "denormalization_context"={"groups"={"my-entity:put_custom", "my-entity:put_custom:in"}},
* "normalization_context"={"groups"={"my-entity:put_custom", "my-entity:put_custom:out"}}
* }
* }
* )
*/
class MyEntity {
/**
* @Groups({"my-entity:get_col", "my-entity:post:out", "my-entity:get_item", "my-entity:put:out"})
*/
public $id;
/**
* @Groups({"my-entity:get_col", "my-entity:post", "my-entity:put"})
*/
public $name;
/**
* @Groups({"my-entity:get_custom", "my-entity:put_custom"})
*/
public $specialValue;
/**
* @Groups({"my-entity:get_col", "my-entity:post:out", "my-entity:put:out"})
*/
public $createdAt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment