vendor/lnb/shopware6-lnb-partner-auth/src/TherapistsApi/BearerTokenAuthProvider.php line 49

Open in your IDE?
  1. <?php
  2. namespace Lnb\Shopware6\LnbPartnerAuth\TherapistsApi;
  3. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  4. class BearerTokenAuthProvider
  5. {
  6.     public const TOKEN_KEY 'lnb_partner_auth_token';
  7.     public const PARTNER_ID_KEY 'lnb_partner_id';
  8.     private ?string $token null;
  9.     private ?string $partnerId null;
  10.     public function __construct(
  11.         private readonly SessionInterface $session
  12.     ) {
  13.     }
  14.     public function save(): void
  15.     {
  16.         $this->session->set(self::TOKEN_KEY$this->token);
  17.         $this->session->set(self::PARTNER_ID_KEY$this->partnerId);
  18.     }
  19.     public function restore(): void
  20.     {
  21.         if ($this->hasSessionToken()) {
  22.             $this->token $this->session->get(self::TOKEN_KEY);
  23.         }
  24.         if ($this->hasPartnerId()) {
  25.             $this->partnerId $this->session->get(self::PARTNER_ID_KEY);
  26.         }
  27.     }
  28.     public function reset(): void
  29.     {
  30.         $this->token null;
  31.         $this->partnerId null;
  32.         $this->session->remove(self::TOKEN_KEY);
  33.         $this->session->remove(self::PARTNER_ID_KEY);
  34.     }
  35.     public function hasSessionToken(): bool
  36.     {
  37.         return $this->session->has(self::TOKEN_KEY);
  38.     }
  39.     public function hasPartnerId(): bool
  40.     {
  41.         return $this->session->has(self::PARTNER_ID_KEY);
  42.     }
  43.     public function getBearerToken(): ?string
  44.     {
  45.         return $this->token;
  46.     }
  47.     public function getPartnerId(): ?string
  48.     {
  49.         return $this->partnerId;
  50.     }
  51.     public function set(string $tokenstring $partnerId): void
  52.     {
  53.         $this->token $token;
  54.         $this->partnerId $partnerId;
  55.         $this->save();
  56.     }
  57. }