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\CoreBundle\DataCollector; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\CoreBundle\Application\Kernel; |
15
|
|
|
use Sylius\Component\Core\Context\ShopperContextInterface; |
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
19
|
|
|
|
20
|
|
|
class SyliusDataCollector extends DataCollector |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ShopperContextInterface |
24
|
|
|
*/ |
25
|
|
|
private $shopperContext; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $version; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $channelCode; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $currencyCode; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $localeCode; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private $customerEmail; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ShopperContextInterface $shopperContext |
54
|
|
|
*/ |
55
|
|
|
public function __construct(ShopperContextInterface $shopperContext) |
56
|
|
|
{ |
57
|
|
|
$this->shopperContext = $shopperContext; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getVersion() |
64
|
|
|
{ |
65
|
|
|
return $this->version; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getChannelCode() |
72
|
|
|
{ |
73
|
|
|
return $this->channelCode; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getCurrencyCode() |
80
|
|
|
{ |
81
|
|
|
return $this->currencyCode; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getCustomerEmail() |
88
|
|
|
{ |
89
|
|
|
return $this->customerEmail; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getLocaleCode() |
96
|
|
|
{ |
97
|
|
|
return $this->localeCode; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
104
|
|
|
{ |
105
|
|
|
$this->version = Kernel::VERSION; |
106
|
|
|
|
107
|
|
|
$this->channelCode = $this->shopperContext->getChannel()->getCode(); |
108
|
|
|
$this->currencyCode = $this->shopperContext->getCurrencyCode(); |
109
|
|
|
$this->localeCode = $this->shopperContext->getLocaleCode(); |
110
|
|
|
|
111
|
|
|
$customer = $this->shopperContext->getCustomer(); |
112
|
|
|
|
113
|
|
|
if (null !== $customer) { |
114
|
|
|
$this->customerEmail = $customer->getEmail(); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function serialize() |
122
|
|
|
{ |
123
|
|
|
return serialize([$this->version, $this->channelCode, $this->currencyCode, $this->localeCode, $this->customerEmail]); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
public function unserialize($serialized) |
130
|
|
|
{ |
131
|
|
|
list($this->version, $this->channelCode, $this->currencyCode, $this->localeCode, $this->customerEmail) = unserialize($serialized); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* {@inheritdoc} |
136
|
|
|
*/ |
137
|
|
|
public function getName() |
138
|
|
|
{ |
139
|
|
|
return 'sylius_core'; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|