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