NotFoundLocaleListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onSetLocale() 0 12 3
1
<?php
2
3
/*
4
 * This file is part of the I18n Routing Bundle.
5
 *
6
 * (c) Beñat Espiña <[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 BenatEspina\I18nRoutingBundle\EventListener;
13
14
use BenatEspina\I18nRoutingBundle\Resolver\NotFoundLocaleResolver;
15
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
16
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17
18
/**
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class NotFoundLocaleListener
22
{
23
    private $resolver;
24
25
    public function __construct(NotFoundLocaleResolver $resolver)
26
    {
27
        $this->resolver = $resolver;
28
    }
29
30
    public function onSetLocale(GetResponseForExceptionEvent $event)
31
    {
32
        if (!$event->isMasterRequest()) {
33
            return;
34
        }
35
36
        if ($event->getException() instanceof NotFoundHttpException) {
37
            $event->getRequest()->setLocale(
38
                $this->resolver->getLocale($event->getRequest())
39
            );
40
        }
41
    }
42
}
43