vendor/store.shopware.com/netinexteasycoupon/src/Service/ConditionService/ConditionErrorService.php line 38

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon\Service\ConditionService;
  4. use NetInventors\NetiNextEasyCoupon\Service\VoucherRedemption\Validator\Error\ConditionsError;
  5. use Symfony\Component\HttpFoundation\Session\Session;
  6. class ConditionErrorService
  7. {
  8.     private const SESSION_KEY 'EasyCouponConditionsError';
  9.     private Session $session;
  10.     public function __construct(Session $session)
  11.     {
  12.         $this->session $session;
  13.     }
  14.     public function set(?ConditionsError $error): void
  15.     {
  16.         if (!$error) {
  17.             return;
  18.         }
  19.         $this->session->set(self::SESSION_KEY, [
  20.             'code'     => $error->getCode(),
  21.             'messages' => $error->getMessages(),
  22.         ]);
  23.     }
  24.     public function get(): ?ConditionsError
  25.     {
  26.         /** @var array|null $error */
  27.         $error $this->session->get(self::SESSION_KEY);
  28.         $this->session->remove(self::SESSION_KEY);
  29.         if (\is_array($error) && \is_string($error['code']) && \is_array($error['messages'])) {
  30.             return new ConditionsError($error['code'], $error['messages']);
  31.         }
  32.         return null;
  33.     }
  34. }