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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\ThemeBundle\Collector; |
15
|
|
|
|
16
|
|
|
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
19
|
|
|
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
23
|
|
|
|
24
|
|
|
final class ThemeCollector extends DataCollector |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ThemeRepositoryInterface |
28
|
|
|
*/ |
29
|
|
|
private $themeRepository; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ThemeContextInterface |
33
|
|
|
*/ |
34
|
|
|
private $themeContext; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ThemeHierarchyProviderInterface |
38
|
|
|
*/ |
39
|
|
|
private $themeHierarchyProvider; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param ThemeRepositoryInterface $themeRepository |
43
|
|
|
* @param ThemeContextInterface $themeContext |
44
|
|
|
* @param ThemeHierarchyProviderInterface $themeHierarchyProvider |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
ThemeRepositoryInterface $themeRepository, |
48
|
|
|
ThemeContextInterface $themeContext, |
49
|
|
|
ThemeHierarchyProviderInterface $themeHierarchyProvider |
50
|
|
|
) { |
51
|
|
|
$this->themeRepository = $themeRepository; |
52
|
|
|
$this->themeContext = $themeContext; |
53
|
|
|
$this->themeHierarchyProvider = $themeHierarchyProvider; |
54
|
|
|
|
55
|
|
|
$this->data = [ |
56
|
|
|
'used_theme' => null, |
57
|
|
|
'used_themes' => [], |
58
|
|
|
'themes' => [], |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return ThemeInterface|null |
64
|
|
|
*/ |
65
|
|
|
public function getUsedTheme(): ?ThemeInterface |
66
|
|
|
{ |
67
|
|
|
return $this->data['used_theme']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array|ThemeInterface[] |
72
|
|
|
*/ |
73
|
|
|
public function getUsedThemes(): array |
74
|
|
|
{ |
75
|
|
|
return $this->data['used_themes']; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return ThemeInterface[] |
80
|
|
|
*/ |
81
|
|
|
public function getThemes(): array |
82
|
|
|
{ |
83
|
|
|
return $this->data['themes']; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function collect(Request $request, Response $response, ?\Exception $exception = null): void |
90
|
|
|
{ |
91
|
|
|
$usedTheme = $this->themeContext->getTheme(); |
92
|
|
|
|
93
|
|
|
$this->data['used_theme'] = $usedTheme; |
94
|
|
|
$this->data['used_themes'] = null !== $usedTheme ? $this->themeHierarchyProvider->getThemeHierarchy($usedTheme) : []; |
95
|
|
|
$this->data['themes'] = $this->themeRepository->findAll(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function reset(): void |
102
|
|
|
{ |
103
|
|
|
$this->data['used_theme'] = null; |
104
|
|
|
$this->data['used_themes'] = []; |
105
|
|
|
$this->data['themes'] = []; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
|
|
public function getName(): string |
112
|
|
|
{ |
113
|
|
|
return 'sylius_theme'; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|