vendor/shopware/platform/src/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.     /**
  21.      * @return string
  22.      */
  23.     public function getAliasName()
  24.     {
  25.         return 'loginRequired';
  26.     }
  27.     /**
  28.      * @return bool
  29.      */
  30.     public function allowArray()
  31.     {
  32.         return false;
  33.     }
  34.     public function isLoggedIn(SalesChannelContext $context): bool
  35.     {
  36.         if ($context->getCustomer() === null) {
  37.             return false;
  38.         }
  39.         if ($context->getCustomer()->getGuest() && $this->isAllowGuest() === false) {
  40.             return false;
  41.         }
  42.         return true;
  43.     }
  44.     public function isAllowGuest(): bool
  45.     {
  46.         return $this->allowGuest;
  47.     }
  48.     public function setAllowGuest(bool $allowGuest): void
  49.     {
  50.         $this->allowGuest $allowGuest;
  51.     }
  52. }