vendor/sylius/sylius/src/Sylius/Component/Core/Locale/LocaleStorage.php line 33

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\Core\Locale;
  12. use Sylius\Component\Channel\Model\ChannelInterface;
  13. use Sylius\Component\Locale\Context\LocaleNotFoundException;
  14. use Sylius\Component\Resource\Storage\StorageInterface;
  15. final class LocaleStorage implements LocaleStorageInterface
  16. {
  17.     public function __construct(private StorageInterface $storage)
  18.     {
  19.     }
  20.     public function set(ChannelInterface $channelstring $localeCode): void
  21.     {
  22.         $this->storage->set($this->provideKey($channel), $localeCode);
  23.     }
  24.     public function get(ChannelInterface $channel): string
  25.     {
  26.         $localeCode $this->storage->get($this->provideKey($channel));
  27.         if (null === $localeCode) {
  28.             throw new LocaleNotFoundException('No locale is set for current channel!');
  29.         }
  30.         return $localeCode;
  31.     }
  32.     private function provideKey(ChannelInterface $channel): string
  33.     {
  34.         return '_locale_' $channel->getCode();
  35.     }
  36. }