src/Domain/Entity/PointOfInterest/OpeningHour.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity\PointOfInterest;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Link;
  7. use ApiPlatform\Metadata\Post;
  8. use App\Domain\Entity\Behavior\Identifiable;
  9. use Gedmo\Timestampable\Traits\Timestampable;
  10. /**
  11.  * Class OpeningHour
  12.  * @package App\Domain\Entity\PointOfInterest
  13.  */
  14. #[ApiResource(
  15.     operations            : [
  16.         new Get(),
  17.         new GetCollection(),
  18.         new Post()
  19.     ],
  20.     normalizationContext  : ['groups' => ['opening_hour_read']],
  21.     denormalizationContext: ['groups' => ['opening_hour_write']]
  22. )]
  23. #[ApiResource(
  24.     uriTemplate '/revisions/{uuid}/opening_hours',
  25.     operations  : [
  26.         new GetCollection()
  27.     ],
  28.     uriVariables: [
  29.         'uuid' => new Link(fromProperty'openingHours'fromClassRevision::class)
  30.     ]
  31. )]
  32. class OpeningHour
  33. {
  34.     use Identifiable;
  35.     use Timestampable;
  36.     public function __construct(
  37.         public \DateTime $end,
  38.         public Revision $revision,
  39.         public \DateTime $start,
  40.     ) {
  41.     }
  42.     public function getFormattedEnd(): string
  43.     {
  44.         return $this->end->format('H:i');
  45.     }
  46.     public function getFormattedStart(): string
  47.     {
  48.         return $this->start->format('H:i');
  49.     }
  50. }