/**
  * {@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));
 }
 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']);
 }
Example #3
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'));
 }