Completed
Pull Request — 2.x (#251)
by
unknown
02:57
created

SwitchLocaleAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
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 Sonata\TranslationBundle\Action;
13
14
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
18
/**
19
 * Locale action.
20
 *
21
 * @author Jonathan Vautrin <[email protected]>
22
 */
23
final class SwitchLocaleAction
24
{
25
    /**
26
     * Switch current locale.
27
     *
28
     * @return RedirectResponse
29
     */
30
    public function __invoke(Request $request, $locale)
31
    {
32
        $request->getSession()->set('_locale', $locale);
33
        return new RedirectResponse($request->headers->get('referer', '/'));
34
    }
35
}
36