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

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. use Shopware\Core\Framework\Log\Package;
  6. #[Package('checkout')]
  7. class LineItemGroupServiceRegistry
  8. {
  9.     /**
  10.      * @var iterable
  11.      */
  12.     private $packagers;
  13.     /**
  14.      * @var iterable
  15.      */
  16.     private $sorters;
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(iterable $packagersiterable $sorters)
  21.     {
  22.         $this->packagers $packagers;
  23.         $this->sorters $sorters;
  24.     }
  25.     /**
  26.      * Gets a list of all registered packagers.
  27.      */
  28.     public function getPackagers(): \Generator
  29.     {
  30.         foreach ($this->packagers as $packager) {
  31.             yield $packager;
  32.         }
  33.     }
  34.     /**
  35.      * Gets the packager for the provided key, if registered.
  36.      *
  37.      * @throws LineItemGroupPackagerNotFoundException
  38.      */
  39.     public function getPackager(string $key): LineItemGroupPackagerInterface
  40.     {
  41.         /** @var LineItemGroupPackagerInterface $packager */
  42.         foreach ($this->packagers as $packager) {
  43.             if (mb_strtolower($packager->getKey()) === mb_strtolower($key)) {
  44.                 return $packager;
  45.             }
  46.         }
  47.         throw new LineItemGroupPackagerNotFoundException($key);
  48.     }
  49.     /**
  50.      * Gets a list of all registered sorters.
  51.      */
  52.     public function getSorters(): \Generator
  53.     {
  54.         foreach ($this->sorters as $sorter) {
  55.             yield $sorter;
  56.         }
  57.     }
  58.     /**
  59.      * Gets the sorter for the provided key, if registered.
  60.      *
  61.      * @throws LineItemGroupSorterNotFoundException
  62.      */
  63.     public function getSorter(string $key): LineItemGroupSorterInterface
  64.     {
  65.         /** @var LineItemGroupSorterInterface $sorter */
  66.         foreach ($this->sorters as $sorter) {
  67.             if (mb_strtolower($sorter->getKey()) === mb_strtolower($key)) {
  68.                 return $sorter;
  69.             }
  70.         }
  71.         throw new LineItemGroupSorterNotFoundException($key);
  72.     }
  73. }