Completed
Push — ezp26828-trigger_crowdin_in_co... ( fa2c05 )
by
unknown
19:34
created

CrowdinRequestLocaleSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 8 1
A setInContextAcceptLanguage() 0 8 2
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Bundle\EzPublishCoreBundle\EventSubscriber;
7
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10
use Symfony\Component\HttpKernel\KernelEvents;
11
12
/**
13
 * If the request has an `ez_in_context_translation` cookie, sets the request accept-language
14
 * to the pseudo-locale used to trigger Crowdin's in-context translation UI.
15
 */
16
class CrowdinRequestLocaleSubscriber implements EventSubscriberInterface
17
{
18
    public static function getSubscribedEvents()
19
    {
20
        return [
21
            KernelEvents::REQUEST => [
22
                ['setInContextAcceptLanguage', 100],
23
            ],
24
        ];
25
    }
26
27
    public function setInContextAcceptLanguage(GetResponseEvent $e)
28
    {
29
        if (!$e->getRequest()->cookies->has('ez_in_context_translation')) {
30
            return;
31
        }
32
33
        $e->getRequest()->headers->set('accept-language', 'ach-UG');
34
    }
35
}
36