vendor/shopware/core/Framework/Api/Context/AdminApiSource.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\Context;
  3. use Shopware\Core\Framework\Log\Package;
  4. #[Package('core')]
  5. class AdminApiSource implements ContextSource
  6. {
  7.     /**
  8.      * @var string|null
  9.      */
  10.     private $userId;
  11.     /**
  12.      * @var string|null
  13.      */
  14.     private $integrationId;
  15.     /**
  16.      * @var bool
  17.      */
  18.     private $isAdmin;
  19.     /**
  20.      * @var array
  21.      */
  22.     private $permissions = [];
  23.     public function __construct(?string $userId, ?string $integrationId null)
  24.     {
  25.         $this->userId $userId;
  26.         $this->integrationId $integrationId;
  27.         $this->isAdmin false;
  28.     }
  29.     public function getUserId(): ?string
  30.     {
  31.         return $this->userId;
  32.     }
  33.     public function getIntegrationId(): ?string
  34.     {
  35.         return $this->integrationId;
  36.     }
  37.     public function setIsAdmin(bool $isAdmin): void
  38.     {
  39.         $this->isAdmin $isAdmin;
  40.     }
  41.     public function setPermissions(array $permissions): void
  42.     {
  43.         $this->permissions $permissions;
  44.     }
  45.     public function isAllowed(string $privilege): bool
  46.     {
  47.         if ($this->isAdmin) {
  48.             return true;
  49.         }
  50.         return \in_array($privilege$this->permissionstrue);
  51.     }
  52.     public function isAdmin(): bool
  53.     {
  54.         return $this->isAdmin;
  55.     }
  56. }