vendor/sylius/sylius/src/Sylius/Component/Order/Context/CompositeCartContext.php line 42

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\Component\Order\Context;
  12. use Laminas\Stdlib\PriorityQueue;
  13. use Sylius\Component\Order\Model\OrderInterface;
  14. final class CompositeCartContext implements CartContextInterface
  15. {
  16.     /**
  17.      * @var PriorityQueue|CartContextInterface[]
  18.      *
  19.      * @psalm-var PriorityQueue<CartContextInterface>
  20.      */
  21.     private PriorityQueue $cartContexts;
  22.     public function __construct()
  23.     {
  24.         $this->cartContexts = new PriorityQueue();
  25.     }
  26.     public function addContext(CartContextInterface $cartContextint $priority 0): void
  27.     {
  28.         $this->cartContexts->insert($cartContext$priority);
  29.     }
  30.     public function getCart(): OrderInterface
  31.     {
  32.         foreach ($this->cartContexts as $cartContext) {
  33.             try {
  34.                 return $cartContext->getCart();
  35.             } catch (CartNotFoundException) {
  36.                 continue;
  37.             }
  38.         }
  39.         throw new CartNotFoundException();
  40.     }
  41. }