Completed
Push — master ( 7af792...02ca7a )
by Rafał
05:00
created

ActiveThemeListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onKernelRequest() 0 12 2
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Web Renderer Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\WebRendererBundle\EventListener;
15
16
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
17
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
18
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
19
use Symfony\Component\HttpKernel\HttpKernelInterface;
20
21
class ActiveThemeListener
22
{
23
    /**
24
     * @var ThemeRepositoryInterface
25
     */
26
    private $themeRepository;
27
28
    /**
29
     * @var ThemeContextInterface
30
     */
31
    private $themeContext;
32
33
    /**
34
     * @param ThemeRepositoryInterface $themeRepository
35
     * @param ThemeContextInterface $themeContext
36
     */
37
    public function __construct(ThemeRepositoryInterface $themeRepository, ThemeContextInterface $themeContext)
38
    {
39
        $this->themeRepository = $themeRepository;
40
        $this->themeContext = $themeContext;
41
    }
42
43
    /**
44
     * @param GetResponseEvent $event
45
     */
46
    public function onKernelRequest(GetResponseEvent $event)
47
    {
48
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
49
            // don't do anything if it's not the master request
50
            return;
51
        }
52
53
        $this->themeContext->setTheme(
54
            // for now just hardcode default theme
55
            $this->themeRepository->findOneByName('swp/default-theme')
56
        );
57
    }
58
}
59