function it_throws_an_exception_if_locale_taken_from_storage_is_not_available(ChannelContextInterface $channelContext, LocaleStorageInterface $localeStorage, LocaleProviderInterface $localeProvider, ChannelInterface $channel)
 {
     $channelContext->getChannel()->willReturn($channel);
     $localeStorage->get($channel)->willReturn('pl_PL');
     $localeProvider->getAvailableLocalesCodes()->willReturn(['en_US', 'en_UK']);
     $this->shouldThrow(LocaleNotFoundException::class)->during('getLocaleCode');
 }
 function it_throws_handle_exception_if_channel_was_not_found(LocaleStorageInterface $localeStorage, ChannelContextInterface $channelContext, EventDispatcherInterface $eventDispatcher)
 {
     $channelContext->getChannel()->willThrow(ChannelNotFoundException::class);
     $localeStorage->set(Argument::any(), Argument::any())->shouldNotBeCalled();
     $eventDispatcher->dispatch(SyliusLocaleEvents::CODE_CHANGED, new GenericEvent('en_GB'))->shouldNotBeCalled();
     $this->shouldThrow(HandleException::class)->during('handle', ['en_GB']);
 }
 /**
  * {@inheritdoc}
  */
 public function handle($code)
 {
     try {
         $this->localeStorage->set($this->channelContext->getChannel(), $code);
     } catch (ChannelNotFoundException $exception) {
         throw new HandleException(self::class, 'Sylius cannot found the channel', $exception);
     }
     $this->eventDispatcher->dispatch(SyliusLocaleEvents::CODE_CHANGED, new GenericEvent($code));
 }
 /**
  * {@inheritdoc}
  */
 public function getLocaleCode()
 {
     $availableLocalesCodes = $this->localeProvider->getAvailableLocalesCodes();
     try {
         $localeCode = $this->localeStorage->get($this->channelContext->getChannel());
     } catch (ChannelNotFoundException $exception) {
         throw new LocaleNotFoundException(null, $exception);
     }
     if (!in_array($localeCode, $availableLocalesCodes, true)) {
         throw LocaleNotFoundException::notAvailable($localeCode, $availableLocalesCodes);
     }
     return $localeCode;
 }
Example #5
0
 /**
  * @param Request $request
  * @param string $code
  *
  * @return Response
  */
 public function switchLocaleAction(Request $request, $code)
 {
     $this->localeStorage->set($this->channelContext->getChannel(), $code);
     return new RedirectResponse($request->headers->get('referer'));
 }