src/Offer/EventSubscriber/SetOfferMetaSubscriber.php line 44

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2021 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2021 TECLA Consulting Group oü
  16.  */
  17. namespace App\Offer\EventSubscriber;
  18. use App\Contact\Security\ContactContextInterface;
  19. use App\Offer\Event\Offer\CreateEvent;
  20. use DateTimeImmutable;
  21. use JetBrains\PhpStorm\ArrayShape;
  22. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  23. final class SetOfferMetaSubscriber implements EventSubscriberInterface
  24. {
  25.     private ContactContextInterface $context;
  26.     public function __construct(ContactContextInterface $context)
  27.     {
  28.         $this->context $context;
  29.     }
  30.     #[ArrayShape([CreateEvent::class => 'array'])]
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             CreateEvent::class => ['onCreate', -1024],
  35.         ];
  36.     }
  37.     public function onCreate(CreateEvent $event): void
  38.     {
  39.         $offer $event->getOffer();
  40.         $offer->setCreatedBy($this->context->getBase());
  41.         $offer->setCreatedAt(new DateTimeImmutable());
  42.     }
  43. }