RequestListener::onKernelRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xgc\CarbonBundle\EventListener;
5
6
use Carbon\Carbon;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpKernel\KernelEvents;
10
11
/**
12
 * Class RequestListener
13
 * @package Xgc\CarbonBundle\EventListener
14
 */
15
class RequestListener implements EventSubscriberInterface
16
{
17
    /**
18
     * @var ContainerInterface
19
     */
20
    protected $container;
21
22
    /**
23
     * RequestListener constructor.
24
     *
25
     * @param ContainerInterface $container
26
     */
27 1
    public function __construct(ContainerInterface $container)
28
    {
29 1
        $this->container = $container;
30 1
    }
31
32 1
    public function onKernelRequest()
33
    {
34 1
        $locale = $this->container->getParameter('locale');
35 1
        $encoding = $this->container->getParameter('encoding');
36
37 1
        \setlocale(\LC_TIME, "$locale.$encoding");
38 1
        Carbon::setLocale("$locale.$encoding");
39 1
    }
40
41
    /**
42
     * @return array
43
     */
44 1
    public static function getSubscribedEvents(): array
45
    {
46
        return [
47 1
            KernelEvents::CONTROLLER => [['onKernelRequest', 17]]
48
        ];
49
    }
50
}
51