-
Notifications
You must be signed in to change notification settings - Fork 661
/
Copy pathEccubeDataCollector.php
159 lines (139 loc) · 3.79 KB
/
EccubeDataCollector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\DataCollector;
use Eccube\Common\Constant;
use Eccube\Entity\Plugin;
use Eccube\Repository\PluginRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
/**
* EccubeDataCollector.
*
* @see https://github.com/Sylius/SyliusCoreBundle/blob/master/Collector/SyliusCollector.php
*/
class EccubeDataCollector extends DataCollector
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var PluginRepository
*/
protected $pluginRepository;
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container, PluginRepository $pluginRepository)
{
$this->data = [
'version' => Constant::VERSION,
'base_currency_code' => null,
'currency_code' => null,
'default_locale_code' => null,
'locale_code' => null,
'plugins' => [],
];
$this->container = $container;
$this->pluginRepository = $pluginRepository;
}
/**
* @return string
*/
public function getVersion()
{
return $this->data['version'];
}
/**
* @return array
*/
public function getPlugins()
{
return $this->data['plugins'];
}
/**
* @return string
*/
public function getCurrencyCode()
{
return $this->data['currency_code'];
}
/**
* @return string
*/
public function getLocaleCode()
{
return $this->data['locale_code'];
}
/**
* @return string
*/
public function getDefaultCurrencyCode()
{
return $this->data['base_currency_code'];
}
/**
* @return string
*/
public function getDefaultLocaleCode()
{
return $this->data['default_locale_code'];
}
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data['base_currency_code'] = $this->container->getParameter('currency');
$this->data['currency_code'] = $this->container->getParameter('currency');
try {
$this->data['locale_code'] = $this->container->getParameter('locale');
} catch (LocaleNotFoundException $exception) {
}
try {
$enabled = $this->container->getParameter('eccube.plugins.enabled');
$disabled = $this->container->getParameter('eccube.plugins.disabled');
$Plugins = $this->pluginRepository->findAll();
foreach (array_merge($enabled, $disabled) as $code) {
$Plugin = null;
/* @var Plugin $Plugin */
foreach ($Plugins as $p) {
if ($code == $p->getCode()) {
$Plugin = $p;
break;
}
}
if (!$Plugin) {
$Plugin = new Plugin();
$Plugin->setCode($code);
$Plugin->setName($code);
$Plugin->setEnabled(false);
}
$this->data['plugins'][$code] = $Plugin->toArray();
}
} catch (\Exception $exception) {
}
}
public function reset()
{
$this->data = [];
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'eccube_core';
}
}