Completed
Push — locale-in-url ( 151bbf...6507a9 )
by Kamil
20:45
created

StorageBasedLocaleSwitcher::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ShopBundle\Locale;
13
14
use Sylius\Component\Channel\Context\ChannelContextInterface;
15
use Sylius\Component\Core\Locale\LocaleStorageInterface;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Request;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
final class StorageBasedLocaleSwitcher implements LocaleSwitcherInterface
23
{
24
    /**
25
     * @var LocaleStorageInterface
26
     */
27
    private $localeStorage;
28
29
    /**
30
     * @var ChannelContextInterface
31
     */
32
    private $channelContext;
33
34
    /**
35
     * @param LocaleStorageInterface $localeStorage
36
     * @param ChannelContextInterface $channelContext
37
     */
38
    public function __construct(LocaleStorageInterface $localeStorage, ChannelContextInterface $channelContext)
39
    {
40
        $this->localeStorage = $localeStorage;
41
        $this->channelContext = $channelContext;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function handle(Request $request, $localeCode)
48
    {
49
        $this->localeStorage->set($this->channelContext->getChannel(), $localeCode);
50
51
        return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost()));
52
    }
53
}
54