vendor/sylius/sylius/src/Sylius/Component/Channel/Context/CompositeChannelContext.php line 41

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\Channel\Context;
  12. use Sylius\Component\Channel\Model\ChannelInterface;
  13. use Zend\Stdlib\PriorityQueue;
  14. final class CompositeChannelContext implements ChannelContextInterface
  15. {
  16.     /** @var PriorityQueue|ChannelContextInterface[] */
  17.     private $channelContexts;
  18.     public function __construct()
  19.     {
  20.         $this->channelContexts = new PriorityQueue();
  21.     }
  22.     public function addContext(ChannelContextInterface $channelContextint $priority 0): void
  23.     {
  24.         $this->channelContexts->insert($channelContext$priority);
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function getChannel(): ChannelInterface
  30.     {
  31.         foreach ($this->channelContexts as $channelContext) {
  32.             try {
  33.                 return $channelContext->getChannel();
  34.             } catch (ChannelNotFoundException $exception) {
  35.                 continue;
  36.             }
  37.         }
  38.         throw new ChannelNotFoundException();
  39.     }
  40. }