vendor/shopware/core/Framework/Routing/Annotation/LoginRequired.php line 13

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Routing\Annotation;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
  4. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  5. /**
  6.  * Annotation for store-api/storefront
  7.  *
  8.  * @Annotation
  9.  */
  10. class LoginRequired implements ConfigurationInterface
  11. {
  12.     /**
  13.      * @var bool
  14.      */
  15.     private $allowGuest;
  16.     public function __construct(array $values)
  17.     {
  18.         $this->allowGuest = isset($values['allowGuest']) ? $values['allowGuest'] : false;
  19.     }
  20.     public function getAliasName()
  21.     {
  22.         return 'loginRequired';
  23.     }
  24.     public function allowArray()
  25.     {
  26.         return false;
  27.     }
  28.     public function isLoggedIn(SalesChannelContext $context): bool
  29.     {
  30.         if ($context->getCustomer() === null) {
  31.             return false;
  32.         }
  33.         if ($context->getCustomer()->getGuest() && $this->isAllowGuest() === false) {
  34.             return false;
  35.         }
  36.         return true;
  37.     }
  38.     public function isAllowGuest(): bool
  39.     {
  40.         return $this->allowGuest;
  41.     }
  42.     public function setAllowGuest(bool $allowGuest): void
  43.     {
  44.         $this->allowGuest $allowGuest;
  45.     }
  46. }