src/Domain/Merchant/Model/Merchant.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Merchant\Model;
  4. use App\Domain\Shared\Model\Aggregate;
  5. use App\Domain\Shared\Model\TimestampTrait;
  6. use App\Domain\Site\Model\Site;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Uid\Uuid;
  12. class Merchant extends Aggregate implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     use TimestampTrait;
  15.     /**
  16.      * @var Collection<array-key, Site>
  17.      */
  18.     private Collection $sites;
  19.     /**
  20.      * @var Collection<array-key, MerchantResetPasswordToken>
  21.      */
  22.     private Collection $resetPasswordTokens;
  23.     public function __construct(
  24.         private Uuid $id,
  25.         private string $firstName,
  26.         private string $lastName,
  27.         private string $email,
  28.         private string $password,
  29.         private MerchantRole $role,
  30.         private bool $active,
  31.         private ?string $paymentProvider null
  32.     ) {
  33.         $this->paymentProvider $paymentProvider;
  34.         $this->sites = new ArrayCollection();
  35.         $this->resetPasswordTokens = new ArrayCollection();
  36.         $this->createdAt = new \DateTimeImmutable();
  37.         $this->updatedAt null;
  38.     }
  39.     public function getId(): Uuid
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getFirstName(): string
  44.     {
  45.         return $this->firstName;
  46.     }
  47.     public function getLastName(): string
  48.     {
  49.         return $this->lastName;
  50.     }
  51.     public function getEmail(): string
  52.     {
  53.         return $this->email;
  54.     }
  55.     public function getRole(): MerchantRole
  56.     {
  57.         return $this->role;
  58.     }
  59.     public function getPaymentProvider(): ?string
  60.     {
  61.         return $this->paymentProvider;
  62.     }
  63.     public function isActive(): bool
  64.     {
  65.         return $this->active;
  66.     }
  67.     public function getRoles(): array
  68.     {
  69.         return [$this->role->value];
  70.     }
  71.     public function eraseCredentials()
  72.     {
  73.         // TODO: Implement eraseCredentials() method.
  74.     }
  75.     public function getUserIdentifier(): string
  76.     {
  77.         return $this->email;
  78.     }
  79.     public function getPassword(): ?string
  80.     {
  81.         return $this->password;
  82.     }
  83.     public function setCreatedAt(\DateTimeImmutable $createdAt): void
  84.     {
  85.         $this->createdAt $createdAt;
  86.     }
  87.     public function setUpdatedAt($updatedAt): void
  88.     {
  89.         $this->updatedAt $updatedAt;
  90.     }
  91.     public function setId(Uuid $id): void
  92.     {
  93.         $this->id $id;
  94.     }
  95.     public function setFirstName(string $firstName): void
  96.     {
  97.         $this->firstName $firstName;
  98.     }
  99.     public function setLastName(string $lastName): void
  100.     {
  101.         $this->lastName $lastName;
  102.     }
  103.     public function setEmail(string $email): void
  104.     {
  105.         $this->email $email;
  106.     }
  107.     public function setPassword(string $password): void
  108.     {
  109.         $this->password $password;
  110.     }
  111.     public function setRole(MerchantRole $role): void
  112.     {
  113.         $this->role $role;
  114.     }
  115.     public function setPaymentProvider(?string $paymentProvider): void
  116.     {
  117.         $this->paymentProvider $paymentProvider;
  118.     }
  119.     public function setActive(bool $active): void
  120.     {
  121.         $this->active $active;
  122.     }
  123.     public function addSite(Site $site): void
  124.     {
  125.         if (!$this->sites->contains($site)) {
  126.             $this->sites->add($site);
  127.         }
  128.     }
  129.     public function removeSite(Site $site): void
  130.     {
  131.         if ($this->sites->contains($site)) {
  132.             $this->sites->removeElement($site);
  133.         }
  134.     }
  135. }