src/Messenger/Messages/User/CreateWebshopCustomerFromBusinessPartner.php line 53

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bodymed\Webshop\Messenger\Messages\User;
  4. use Bodymed\Webshop\Messenger\DistributedMessageInterface;
  5. /**
  6.  * Sent, when a BusinessPartner was created and should get a webshop-login
  7.  */
  8. class CreateWebshopCustomerFromBusinessPartner implements DistributedMessageInterface
  9. {
  10.     public const SUBJECT 'f9636140-464e-46a1-be03-856e73e78bd1';
  11.     private string $email;
  12.     private array $payload;
  13.     private \DateTimeImmutable $when;
  14.     public function __construct(array $payload\DateTimeImmutable $when null)
  15.     {
  16.         $this->email = (string) $payload['email'];
  17.         $this->payload $payload;
  18.         $this->when $when ?? new \DateTimeImmutable();
  19.     }
  20.     public static function getSubject(): string
  21.     {
  22.         return self::SUBJECT;
  23.     }
  24.     public function toPayload(): array
  25.     {
  26.         return \array_merge($this->payload, [
  27.             'when' => $this->when,
  28.         ]);
  29.     }
  30.     public static function fromPayload(array $data): CreateWebshopCustomerFromBusinessPartner
  31.     {
  32.         $static = new CreateWebshopCustomerFromBusinessPartner($data);
  33.         $static->when = new \DateTimeImmutable(
  34.             $data['when']['date'],
  35.             new \DateTimeZone($data['when']['timezone'])
  36.         );
  37.         return $static;
  38.     }
  39.     public function jsonSerialize()
  40.     {
  41.         return $this->toPayload();
  42.     }
  43.     public function getEmail(): string
  44.     {
  45.         return $this->email;
  46.     }
  47.     public function getPayload(): array
  48.     {
  49.         return $this->payload;
  50.     }
  51.     public function getWhen(): \DateTimeImmutable
  52.     {
  53.         return $this->when;
  54.     }
  55. }