src/Domain/Entity/PressKit.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Application\ApiResources\State\Processor\PressKit\PostProcessor;
  10. use App\Application\ApiResources\State\Processor\PressKit\PutProcessor;
  11. use App\Domain\Entity\Behavior\Identifiable;
  12. use DateTime;
  13. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  14. use Gedmo\Timestampable\Traits\Timestampable;
  15. /**
  16.  * Class PressKit
  17.  *
  18.  * @package App\Domain\Entity
  19.  */
  20. #[ApiResource(
  21.     operations            : [
  22.         new Delete(security"is_granted('ROLE_ADMIN')"),
  23.         new Get(),
  24.         new GetCollection(filters: ['press.search_filter''press_kit.query_filter''soft_delete_filter']),
  25.         new Post(security"is_granted('ROLE_ADMIN')"processorPostProcessor::class),
  26.         new Put(security"is_granted('ROLE_ADMIN')"processorPutProcessor::class),
  27.     ],
  28.     normalizationContext  : ['groups' => ['press_kit_read']],
  29.     denormalizationContext: ['groups' => ['press_kit_write']]
  30. )]
  31. class PressKit
  32. {
  33.     use Identifiable;
  34.     use SoftDeleteable;
  35.     use Timestampable;
  36.     /**
  37.      * @param Locale      $locale
  38.      * @param bool|null   $isOnline
  39.      * @param Media|null  $file
  40.      * @param string|null $name
  41.      */
  42.     public function __construct(
  43.         public Locale $locale,
  44.         public ?bool $isOnline false,
  45.         public ?Media $file null,
  46.         public ?string $name null,
  47.     ) {}
  48.     public function getPublicationDate(): DateTime
  49.     {
  50.         return $this->updatedAt;
  51.     }
  52.     public function getFormattedPublicationDate(): string
  53.     {
  54.         return $this->updatedAt->format('F Y');
  55.     }
  56. }