vendor/sylius/sylius/src/Sylius/Component/Locale/Context/CompositeLocaleContext.php line 43

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\Locale\Context;
  12. use Laminas\Stdlib\PriorityQueue;
  13. final class CompositeLocaleContext implements LocaleContextInterface
  14. {
  15.     /**
  16.      * @var PriorityQueue|LocaleContextInterface[]
  17.      *
  18.      * @psalm-var PriorityQueue<LocaleContextInterface>
  19.      */
  20.     private PriorityQueue $localeContexts;
  21.     public function __construct()
  22.     {
  23.         $this->localeContexts = new PriorityQueue();
  24.     }
  25.     public function addContext(LocaleContextInterface $localeContextint $priority 0): void
  26.     {
  27.         $this->localeContexts->insert($localeContext$priority);
  28.     }
  29.     public function getLocaleCode(): string
  30.     {
  31.         $lastException null;
  32.         foreach ($this->localeContexts as $localeContext) {
  33.             try {
  34.                 return $localeContext->getLocaleCode();
  35.             } catch (LocaleNotFoundException $exception) {
  36.                 $lastException $exception;
  37.                 continue;
  38.             }
  39.         }
  40.         throw new LocaleNotFoundException(null$lastException);
  41.     }
  42. }