src/Offer/EventSubscriber/SetOfferEmailMetaSubscriber.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\OfferEmail\CreateEvent;
  20. use DateTimeImmutable;
  21. use JetBrains\PhpStorm\ArrayShape;
  22. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  23. final class SetOfferEmailMetaSubscriber 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.         $createdBy $this->context->getBase();
  40.         $createdAt = new DateTimeImmutable();
  41.         $email $event->getEmail();
  42.         $email->setCreatedBy($createdBy);
  43.         $email->setCreatedAt($createdAt);
  44.         foreach ($email->getAttachments() as $attachment) {
  45.             $attachment->setCreatedBy($createdBy);
  46.             $attachment->setCreatedAt($createdAt);
  47.         }
  48.     }
  49. }