vendor/shopware/core/Content/Product/SalesChannel/Listing/FilterCollection.php line 12

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\SalesChannel\Listing;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Shopware\Core\Framework\Struct\Collection;
  5. /**
  6.  * @extends Collection<Filter>
  7.  */
  8. #[Package('inventory')]
  9. class FilterCollection extends Collection
  10. {
  11.     /**
  12.      * @param string|int  $key
  13.      * @param Filter|null $element
  14.      */
  15.     public function set($key$element): void
  16.     {
  17.         if ($element === null) {
  18.             return;
  19.         }
  20.         parent::set($key$element);
  21.     }
  22.     /**
  23.      * @param Filter $element
  24.      */
  25.     public function add($element): void
  26.     {
  27.         $this->validateType($element);
  28.         $this->elements[$element->getName()] = $element;
  29.     }
  30.     public function blacklist(string $exclude): FilterCollection
  31.     {
  32.         $filtered = new self();
  33.         foreach ($this->elements as $key => $value) {
  34.             if ($exclude === $key) {
  35.                 continue;
  36.             }
  37.             $filtered->set($key$value);
  38.         }
  39.         return $filtered;
  40.     }
  41.     public function filtered(): FilterCollection
  42.     {
  43.         return $this->filter(function (Filter $filter) {
  44.             return $filter->isFiltered() ? $filter null;
  45.         });
  46.     }
  47.     public function getFilters(): array
  48.     {
  49.         return $this->fmap(function (Filter $filter) {
  50.             return $filter->getFilter();
  51.         });
  52.     }
  53.     protected function getExpectedClass(): ?string
  54.     {
  55.         return Filter::class;
  56.     }
  57. }