Completed
Push — master ( 4207f0...333332 )
by Kamil
23:19 queued 01:42
created

ThemeDataCollector::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 2
b 0
f 1
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\ThemeBundle\Collector;
13
14
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
15
use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface;
16
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
17
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
21
22
/**
23
 * @author Kamil Kokot <[email protected]>
24
 */
25
class ThemeDataCollector implements DataCollectorInterface, \Serializable
26
{
27
    /**
28
     * @var ThemeInterface
29
     */
30
    private $usedTheme;
31
32
    /**
33
     * @var ThemeInterface[]
34
     */
35
    private $themeHierarchy;
36
37
    /**
38
     * @var ThemeInterface[]
39
     */
40
    private $allThemes;
41
42
    /**
43
     * @var ThemeRepositoryInterface
44
     */
45
    private $themeRepository;
46
47
    /**
48
     * @var ThemeContextInterface
49
     */
50
    private $themeContext;
51
52
    /**
53
     * @param ThemeRepositoryInterface $themeRepository
54
     * @param ThemeContextInterface $themeContext
55
     */
56
    public function __construct(
57
        ThemeRepositoryInterface $themeRepository,
58
        ThemeContextInterface $themeContext
59
    ) {
60
        $this->themeRepository = $themeRepository;
61
        $this->themeContext = $themeContext;
62
    }
63
64
    /**
65
     * @return ThemeInterface
66
     */
67
    public function getUsedTheme()
68
    {
69
        return $this->usedTheme;
70
    }
71
72
    /**
73
     * @return ThemeInterface[]
74
     */
75
    public function getThemeHierarchy()
76
    {
77
        return $this->themeHierarchy;
78
    }
79
80
    /**
81
     * @return ThemeInterface[]
82
     */
83
    public function getAllThemes()
84
    {
85
        return $this->allThemes;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function collect(Request $request, Response $response, \Exception $exception = null)
92
    {
93
        $this->usedTheme = $this->themeContext->getTheme();
94
        $this->themeHierarchy = $this->themeContext->getThemeHierarchy();
95
        $this->allThemes = $this->themeRepository->findAll();
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function serialize()
102
    {
103
        return serialize([$this->usedTheme, $this->themeHierarchy, $this->allThemes]);
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function unserialize($serialized)
110
    {
111
        list($this->usedTheme, $this->themeHierarchy, $this->allThemes) = unserialize($serialized);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function getName()
118
    {
119
        return 'sylius_theme';
120
    }
121
}
122