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

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.     /** @var StorageInterface */
  18.     private $storage;
  19.     public function __construct(StorageInterface $storage)
  20.     {
  21.         $this->storage $storage;
  22.     }
  23.     public function set(ChannelInterface $channelstring $localeCode): void
  24.     {
  25.         $this->storage->set($this->provideKey($channel), $localeCode);
  26.     }
  27.     public function get(ChannelInterface $channel): string
  28.     {
  29.         $localeCode $this->storage->get($this->provideKey($channel));
  30.         if (null === $localeCode) {
  31.             throw new LocaleNotFoundException('No locale is set for current channel!');
  32.         }
  33.         return $localeCode;
  34.     }
  35.     private function provideKey(ChannelInterface $channel): string
  36.     {
  37.         return '_locale_' $channel->getCode();
  38.     }
  39. }