src/Infrastructure/RequestDto/LoginDto.php line 8

Open in your IDE?
  1. <?php
  2. namespace App\Infrastructure\RequestDto;
  3. use App\Infrastructure\Traits\CurrencyTrait;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. class LoginDto implements UserInterface
  6. {
  7.     use CurrencyTrait;
  8.     public const JWT_TOKEN_COOKIE 'JWT_TOKEN';
  9.     public const JWT_REFRESH_TOKEN_COOKIE 'JWT_REFRESH_TOKEN';
  10.     public const ROLE_AGENT 'ROLE_AGENT';
  11.     public const ROLE_MANAGER 'ROLE_MANAGER';
  12.     private $id;
  13.     private ?string $firstName;
  14.     private ?string $lastName;
  15.     private $username;
  16.     private $password;
  17.     private $token;
  18.     private $qualification;
  19.     private $avatar;
  20.     private $manager;
  21.     private $termsAccepted;
  22.     private ?string $refreshToken null;
  23.     /**
  24.      * @var array
  25.      */
  26.     private array $roles = [];
  27.     /**
  28.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  29.      */
  30.     public function getUsername()
  31.     {
  32.         return (string) $this->username;
  33.     }
  34.     public function setUsername(string $username): self
  35.     {
  36.         $this->username $username;
  37.         return $this;
  38.     }
  39.     /**
  40.      * @return mixed
  41.      */
  42.     public function getId()
  43.     {
  44.         return $this->id;
  45.     }
  46.     /**
  47.      * @param mixed $id
  48.      */
  49.     public function setId($id): void
  50.     {
  51.         $this->id $id;
  52.     }
  53.     /**
  54.      * A visual identifier that represents this user.
  55.      *
  56.      * @see UserInterface
  57.      */
  58.     public function getUserIdentifier(): ?string
  59.     {
  60.         return (string) $this->username;
  61.     }
  62.     /**
  63.      * @see UserInterface
  64.      */
  65.     public function getRoles(): array
  66.     {
  67.         $roles $this->roles;
  68.         return array_unique($roles);
  69.     }
  70.     public function setRoles(array $roles): self
  71.     {
  72.         $this->roles $roles;
  73.         return $this;
  74.     }
  75.     /**
  76.      * This method can be removed in Symfony 6.0 - is not needed for apps that do not check user passwords.
  77.      *
  78.      * @see PasswordAuthenticatedUserInterface
  79.      */
  80.     public function getPassword(): ?string
  81.     {
  82.         return $this->password;
  83.     }
  84.     public function setPassword(string $password): self
  85.     {
  86.         $this->password $password;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function eraseCredentials()
  93.     {
  94.         // If you store any temporary, sensitive data on the user, clear it here
  95.         // $this->plainPassword = null;
  96.     }
  97.     /**
  98.      * @return string|null
  99.      */
  100.     public function getFirstName(): ?string
  101.     {
  102.         return $this->firstName;
  103.     }
  104.     /**
  105.      * @param string|null $firstName
  106.      */
  107.     public function setFirstName(?string $firstName): void
  108.     {
  109.         $this->firstName $firstName;
  110.     }
  111.     /**
  112.      * @return string|null
  113.      */
  114.     public function getLastName(): ?string
  115.     {
  116.         return $this->lastName;
  117.     }
  118.     /**
  119.      * @param string|null $lastName
  120.      */
  121.     public function setLastName(?string $lastName): void
  122.     {
  123.         $this->lastName $lastName;
  124.     }
  125.     /**
  126.      * @return string|null
  127.      */
  128.     public function getToken(): ?string
  129.     {
  130.         return $this->token;
  131.     }
  132.     /**
  133.      * @param string|null $token
  134.      */
  135.     public function setToken(?string $token): void
  136.     {
  137.         $this->token $token;
  138.     }
  139.     public function getSalt(): ?string
  140.     {
  141.         return null;
  142.     }
  143.     /**
  144.      * @return mixed
  145.      */
  146.     public function getQualification()
  147.     {
  148.         return $this->qualification;
  149.     }
  150.     /**
  151.      * @param mixed $qualification
  152.      */
  153.     public function setQualification($qualification): void
  154.     {
  155.         $this->qualification $qualification;
  156.     }
  157.     /**
  158.      * @return mixed
  159.      */
  160.     public function getAvatar()
  161.     {
  162.         return $this->avatar;
  163.     }
  164.     /**
  165.      * @param mixed $avatar
  166.      */
  167.     public function setAvatar($avatar): void
  168.     {
  169.         $this->avatar $avatar;
  170.     }
  171.     /**
  172.      * @return mixed
  173.      */
  174.     public function getManager()
  175.     {
  176.         return $this->manager;
  177.     }
  178.     /**
  179.      * @param mixed $manager
  180.      */
  181.     public function setManager($manager): self
  182.     {
  183.         $this->manager $manager;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return mixed
  188.      */
  189.     public function getTermsAccepted()
  190.     {
  191.         return $this->termsAccepted;
  192.     }
  193.     /**
  194.      * @param mixed $termsAccepted
  195.      */
  196.     public function setTermsAccepted($termsAccepted): self
  197.     {
  198.         $this->termsAccepted $termsAccepted;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return string|null
  203.      */
  204.     public function getRefreshToken(): ?string
  205.     {
  206.         return $this->refreshToken;
  207.     }
  208.     /**
  209.      * @param string|null $refreshToken
  210.      *
  211.      * @return $this
  212.      */
  213.     public function setRefreshToken(?string $refreshToken): self
  214.     {
  215.         $this->refreshToken $refreshToken;
  216.         return $this;
  217.     }
  218.     public function toArray(): array
  219.     {
  220.         return [
  221.             'token' => $this->getToken(),
  222.             'refresh_token' => $this->getRefreshToken(),
  223.             'user' => [
  224.                 'roles' => $this->getRoles(),
  225.                 'firstName' => $this->getFirstName(),
  226.                 'lastName' => $this->getLastName(),
  227.                 'qualification' => $this->getQualification(),
  228.                 'avatar' => $this->getAvatar(),
  229.                 'id' => $this->getId(),
  230.                 'manager' => $this->getManager(),
  231.                 'currency' => $this->getCurrency(),
  232.                 'termsAccepted' => $this->getTermsAccepted(),
  233.             ]
  234.         ];
  235.     }
  236.     public static function createFromArray(array $data): self
  237.     {
  238.         $user = new self();
  239.         $user->setToken($data['token']);
  240.         $user->setRefreshToken($data['refresh_token']);
  241.         $user->setRoles($data['user']['roles']);
  242.         $user->setFirstName($data['user']['firstName']);
  243.         $user->setLastName($data['user']['lastName']);
  244.         $user->setQualification($data['user']['qualification']);
  245.         $user->setAvatar($data['user']['avatar']);
  246.         $user->setId($data['user']['id']);
  247.         $user->setManager($data['user']['manager'] ?? []);
  248.         $user->setCurrency($data['user']['currency']);
  249.         $user->setTermsAccepted($data['user']['termsAccepted']);
  250.         return $user;
  251.     }
  252.     public static function map(self $originself $destination)
  253.     {
  254.         $origin->setId($destination->getId());
  255.         $origin->setRoles($destination->getRoles());
  256.         $origin->setToken($destination->getToken());
  257.         $origin->setRefreshToken($destination->getRefreshToken());
  258.         $origin->setFirstName($destination->getFirstName());
  259.         $origin->setLastName($destination->getLastName());
  260.         $origin->setQualification($destination->getQualification());
  261.         $origin->setAvatar($destination->getAvatar());
  262.         $origin->setManager($destination->getManager());
  263.         $origin->setCurrency($destination->getCurrency());
  264.         $origin->setTermsAccepted($destination->getTermsAccepted());
  265.     }
  266.     /**
  267.      * @return string|null
  268.      */
  269.     public function getFullName(): ?string
  270.     {
  271.         return ucfirst($this->firstName ?? '') . ' ' strtoupper($this->lastName ?? '');
  272.     }
  273. }