1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by the developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusShippingExportPlugin\Entity; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
16
|
|
|
use Doctrine\Common\Collections\Collection; |
17
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
18
|
|
|
use Webmozart\Assert\Assert; |
19
|
|
|
|
20
|
|
|
class ShippingGateway implements ShippingGatewayInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
*/ |
25
|
|
|
protected $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $code; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $label; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $config; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Collection|ShippingMethodInterface[] |
44
|
|
|
*/ |
45
|
|
|
protected $shippingMethods; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Collection|ShippingExportInterface[] |
49
|
|
|
*/ |
50
|
|
|
protected $shippingExports; |
51
|
|
|
|
52
|
|
|
public function __construct() |
53
|
|
|
{ |
54
|
|
|
$this->shippingExports = new ArrayCollection(); |
|
|
|
|
55
|
|
|
$this->shippingMethods = new ArrayCollection(); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function getId(): ?int |
62
|
|
|
{ |
63
|
|
|
return $this->id; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function setCode(?string $code): void |
70
|
|
|
{ |
71
|
|
|
$this->code = $code; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function getCode(): ?string |
78
|
|
|
{ |
79
|
|
|
return $this->code; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function setLabel(?string $label): void |
86
|
|
|
{ |
87
|
|
|
$this->label = $label; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function getLabel(): ?string |
94
|
|
|
{ |
95
|
|
|
return $this->label; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function setConfig(?array $config): void |
102
|
|
|
{ |
103
|
|
|
$this->config = $config; |
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function getConfig(): ?array |
110
|
|
|
{ |
111
|
|
|
return $this->config; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function getConfigValue(string $key): ?string |
118
|
|
|
{ |
119
|
|
|
Assert::keyExists($this->config, $key, sprintf( |
120
|
|
|
'Shipping gateway config named %s does not exist.', |
121
|
|
|
$key |
122
|
|
|
)); |
123
|
|
|
|
124
|
|
|
return $this->config[$key]; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* {@inheritdoc} |
129
|
|
|
*/ |
130
|
|
|
public function getShippingMethods(): ?Collection |
131
|
|
|
{ |
132
|
|
|
return $this->shippingMethods; |
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* {@inheritdoc} |
137
|
|
|
*/ |
138
|
|
|
public function addShippingMethod(ShippingMethodInterface $shippingMethod): void |
139
|
|
|
{ |
140
|
|
|
if (!$this->hasShippingMethod($shippingMethod)) { |
141
|
|
|
$this->shippingMethods->add($shippingMethod); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function removeShippingMethod(ShippingMethodInterface $shippingMethod): void |
149
|
|
|
{ |
150
|
|
|
if ($this->hasShippingMethod($shippingMethod)) { |
151
|
|
|
$this->shippingMethods->removeElement($shippingMethod); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* {@inheritdoc} |
157
|
|
|
*/ |
158
|
|
|
public function hasShippingMethod(ShippingMethodInterface $shippingMethod): bool |
159
|
|
|
{ |
160
|
|
|
return $this->shippingMethods->contains($shippingMethod); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* {@inheritdoc} |
165
|
|
|
*/ |
166
|
|
|
public function getShippingExports(): ?Collection |
167
|
|
|
{ |
168
|
|
|
return $this->shippingExports; |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* {@inheritdoc} |
173
|
|
|
*/ |
174
|
|
|
public function addShippingExport(ShippingExportInterface $shippingExport): void |
175
|
|
|
{ |
176
|
|
|
if (!$this->hasShippingExport($shippingExport)) { |
177
|
|
|
$this->shippingExports->add($shippingExport); |
178
|
|
|
$shippingExport->setShippingGateway($this); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* {@inheritdoc} |
184
|
|
|
*/ |
185
|
|
|
public function removeShippingExport(ShippingExportInterface $shippingExport): void |
186
|
|
|
{ |
187
|
|
|
if ($this->hasShippingExport($shippingExport)) { |
188
|
|
|
$this->shippingExports->removeElement($shippingExport); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* {@inheritdoc} |
194
|
|
|
*/ |
195
|
|
|
public function hasShippingExport(ShippingExportInterface $shippingExport): bool |
196
|
|
|
{ |
197
|
|
|
return $this->shippingExports->contains($shippingExport); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..