Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

src/Eccube/DataCollector/EccubeDataCollector.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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