vendor/shopware/core/Checkout/Cart/LineItem/Group/LineItemGroupServiceRegistry.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart\LineItem\Group;
  3. use Shopware\Core\Checkout\Cart\LineItem\Group\Exception\LineItemGroupPackagerNotFoundException;
  4. use Shopware\Core\Checkout\Cart\LineItem\Group\Exception\LineItemGroupSorterNotFoundException;
  5. class LineItemGroupServiceRegistry
  6. {
  7.     /**
  8.      * @var iterable
  9.      */
  10.     private $packagers;
  11.     /**
  12.      * @var iterable
  13.      */
  14.     private $sorters;
  15.     public function __construct(iterable $packagersiterable $sorters)
  16.     {
  17.         $this->packagers $packagers;
  18.         $this->sorters $sorters;
  19.     }
  20.     /**
  21.      * Gets a list of all registered packagers.
  22.      */
  23.     public function getPackagers(): \Generator
  24.     {
  25.         foreach ($this->packagers as $packager) {
  26.             yield $packager;
  27.         }
  28.     }
  29.     /**
  30.      * Gets the packager for the provided key, if registered.
  31.      *
  32.      * @throws LineItemGroupPackagerNotFoundException
  33.      */
  34.     public function getPackager(string $key): LineItemGroupPackagerInterface
  35.     {
  36.         /** @var LineItemGroupPackagerInterface $packager */
  37.         foreach ($this->packagers as $packager) {
  38.             if (mb_strtolower($packager->getKey()) === mb_strtolower($key)) {
  39.                 return $packager;
  40.             }
  41.         }
  42.         throw new LineItemGroupPackagerNotFoundException($key);
  43.     }
  44.     /**
  45.      * Gets a list of all registered sorters.
  46.      */
  47.     public function getSorters(): \Generator
  48.     {
  49.         foreach ($this->sorters as $sorter) {
  50.             yield $sorter;
  51.         }
  52.     }
  53.     /**
  54.      * Gets the sorter for the provided key, if registered.
  55.      *
  56.      * @throws LineItemGroupSorterNotFoundException
  57.      */
  58.     public function getSorter(string $key): LineItemGroupSorterInterface
  59.     {
  60.         /** @var LineItemGroupSorterInterface $sorter */
  61.         foreach ($this->sorters as $sorter) {
  62.             if (mb_strtolower($sorter->getKey()) === mb_strtolower($key)) {
  63.                 return $sorter;
  64.             }
  65.         }
  66.         throw new LineItemGroupSorterNotFoundException($key);
  67.     }
  68. }