src/Messenger/Messages/User/CustomerNumberUpdated.php line 64

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. use Ramsey\Uuid\Uuid;
  6. use Ramsey\Uuid\UuidInterface;
  7. class CustomerNumberUpdated  implements DistributedMessageInterface
  8. {
  9.     public const SUBJECT '86645d90-cfae-415e-86a4-cd4f49dba4b8';
  10.     private UuidInterface $userId;
  11.     private string $webshopCustomerId;
  12.     private string $customerNumber;
  13.     private \DateTimeImmutable $when;
  14.     public function __construct(
  15.         UuidInterface $userId,
  16.         string $webshopCustomerId,
  17.         string $customerNumber,
  18.         ?\DateTimeImmutable $when null
  19.     ) {
  20.         $this->userId $userId;
  21.         $this->webshopCustomerId $webshopCustomerId;
  22.         $this->customerNumber $customerNumber;
  23.         $this->when $when ?? new \DateTimeImmutable();
  24.     }
  25.     public static function getSubject(): string
  26.     {
  27.         return self::SUBJECT;
  28.     }
  29.     public function toPayload(): array
  30.     {
  31.         return [
  32.             'userId' => $this->userId->toString(),
  33.             'webshopCustomerId' => $this->webshopCustomerId,
  34.             'customerNumber' => $this->customerNumber,
  35.             'when' => $this->when,
  36.         ];
  37.     }
  38.     public static function fromPayload(array $data): CustomerNumberUpdated
  39.     {
  40.         $static = new static(Uuid::fromString($data['userId']), (string) $data['webshopCustomerId'], (string) $data['customerNumber']);
  41.         $when = new \DateTimeImmutable(
  42.             $data['when']['date'],
  43.             new \DateTimeZone($data['when']['timezone'])
  44.         );
  45.         $static->when $when;
  46.         return $static;
  47.     }
  48.     public function jsonSerialize()
  49.     {
  50.         return $this->toPayload();
  51.     }
  52.     public function getUserId(): UuidInterface
  53.     {
  54.         return $this->userId;
  55.     }
  56.     public function getWebshopCustomerId(): string
  57.     {
  58.         return $this->webshopCustomerId;
  59.     }
  60.     public function getCustomerNumber(): string
  61.     {
  62.         return $this->customerNumber;
  63.     }
  64.     public function getWhen(): \DateTimeImmutable
  65.     {
  66.         return $this->when;
  67.     }
  68. }