src/Sylius/Bundle/UiBundle/Storage/FilterStorage.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\UiBundle\Storage;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  14. final class FilterStorage implements FilterStorageInterface
  15. {
  16.     public function __construct(private SessionInterface|RequestStack $requestStackOrSession)
  17.     {
  18.         if ($this->requestStackOrSession instanceof SessionInterface) {
  19.             trigger_deprecation('sylius/admin-bundle''1.12'sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius 1.12 and will be removed in 2.0. Pass an instance of %s instead.'SessionInterface::class, self::class, RequestStack::class));
  20.         }
  21.     }
  22.     public function set(array $filters): void
  23.     {
  24.         $this->getSession()->set('filters'$filters);
  25.     }
  26.     public function all(): array
  27.     {
  28.         return $this->getSession()->get('filters', []);
  29.     }
  30.     public function hasFilters(): bool
  31.     {
  32.         return [] !== $this->getSession()->get('filters', []);
  33.     }
  34.     private function getSession(): SessionInterface
  35.     {
  36.         if ($this->requestStackOrSession instanceof RequestStack) {
  37.             return $this->requestStackOrSession->getSession();
  38.         }
  39.         return $this->requestStackOrSession;
  40.     }
  41. }