LocaleListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Translation\EventListener;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
7
use Symfony\Component\HttpKernel\KernelEvents;
8
9
class LocaleListener implements EventSubscriberInterface
10
{
11 92
    public function onKernelRequest(GetResponseEvent $event)
12
    {
13 92
        $request = $event->getRequest();
14
15 92
        if ($request->query->has('language') === false) {
16 89
            return;
17
        }
18
19 7
        $locale = $request->query->get('language');
20
21 7
        if (empty($locale) || !$locale) {
22
            return;
23
        }
24
25 7
        $request->setLocale($locale);
26 7
    }
27
28
    public static function getSubscribedEvents()
29
    {
30
        return [
31
            // must be registered before the default Locale listener
32
            KernelEvents::REQUEST => [['onKernelRequest', 17]],
33
        ];
34
    }
35
}
36