Completed
Push — master ( 61c1b2...61092d )
by Javier
08:21
created

RequestListener::onKernelRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
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
    public function __construct(ContainerInterface $container)
28
    {
29
        $this->container = $container;
30
    }
31
32
    public function onKernelRequest()
33
    {
34
        $locale = $this->container->getParameter('locale');
35
        $encoding = $this->container->getParameter('encoding');
36
37
        \setlocale(\LC_TIME, "$locale.$encoding");
38
        Carbon::setLocale("$locale.$encoding");
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public static function getSubscribedEvents(): array
45
    {
46
        return [
47
            KernelEvents::CONTROLLER => [['onKernelRequest', 17]]
48
        ];
49
    }
50
}
51