Completed
Push — master ( 14cbb2...16a771 )
by MoshiMoshi
02:26
created

LocaleListener::addConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015 Yahoo Japan Corporation
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 YahooJapan\ConfigCacheBundle\EventListener;
13
14
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
15
use YahooJapan\ConfigCacheBundle\ConfigCache\Locale\ConfigCacheInterface;
16
17
/**
18
 * Sets the locale which the Request holds to each ConfigCache service.
19
 */
20
class LocaleListener
21
{
22
    protected $configs = array();
23
24
    /**
25
     * Runs on kernel request.
26
     *
27
     * @param GetResponseEvent $event
28
     */
29 4
    public function onKernelRequest(GetResponseEvent $event)
30
    {
31 4
        if (!$event->isMasterRequest()) {
32 1
            return;
33
        }
34 3
        $locale = $event->getRequest()->getLocale();
35 3
        foreach ($this->configs as $config) {
36 2
            $config->setCurrentLocale($locale);
37 3
        }
38 3
    }
39
40
    /**
41
     * Adds a ConfigCache.
42
     *
43
     * @param ConfigCacheInterface $config
44
     *
45
     * @return LocaleListener
46
     */
47 3
    public function addConfig(ConfigCacheInterface $config)
48
    {
49 3
        $this->configs[] = $config;
50
51 3
        return $this;
52
    }
53
}
54