1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Configuration\Jms\Configuration\Plugin |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Configuration\Jms\Configuration; |
22
|
|
|
|
23
|
|
|
use JMS\Serializer\Annotation\Type; |
24
|
|
|
use JMS\Serializer\Annotation\SerializedName; |
25
|
|
|
use JMS\Serializer\Annotation\PostDeserialize; |
26
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
27
|
|
|
use TechDivision\Import\ConfigurationInterface; |
28
|
|
|
use TechDivision\Import\Configuration\PluginConfigurationInterface; |
29
|
|
|
use TechDivision\Import\Configuration\OperationConfigurationInterface; |
30
|
|
|
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface; |
31
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter; |
32
|
|
|
use TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* A simple plugin configuration implementation. |
36
|
|
|
* |
37
|
|
|
* @author Tim Wagner <[email protected]> |
38
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
39
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
40
|
|
|
* @link https://github.com/techdivision/import-configuration-jms |
41
|
|
|
* @link http://www.techdivision.com |
42
|
|
|
*/ |
43
|
|
|
class Plugin implements PluginConfigurationInterface, ListenerAwareConfigurationInterface |
44
|
|
|
{ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The trait that provides parameter configuration functionality. |
48
|
|
|
* |
49
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait |
50
|
|
|
*/ |
51
|
|
|
use ParamsTrait; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Trait that provides CSV configuration functionality. |
55
|
|
|
* |
56
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait |
57
|
|
|
*/ |
58
|
|
|
use ListenersTrait; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The main configuration. |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $configuration; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The execution context. |
69
|
|
|
* |
70
|
|
|
* @var \TechDivision\Import\Configuration\OperationConfigurationInterface |
71
|
|
|
*/ |
72
|
|
|
protected $operationConfiguration; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The plugin's unique DI identifier. |
76
|
|
|
* |
77
|
|
|
* @var string |
78
|
|
|
* @Type("string") |
79
|
|
|
* @SerializedName("id") |
80
|
|
|
*/ |
81
|
|
|
protected $id; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The plugin's name. |
85
|
|
|
* |
86
|
|
|
* @var string |
87
|
|
|
* @Type("string") |
88
|
|
|
* @SerializedName("name") |
89
|
|
|
*/ |
90
|
|
|
protected $name; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* ArrayCollection with the information of the configured subjects. |
94
|
|
|
* |
95
|
|
|
* @var \Doctrine\Common\Collections\ArrayCollection |
96
|
|
|
* @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Subject>") |
97
|
|
|
*/ |
98
|
|
|
protected $subjects; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* The swift mailer configuration to use. |
102
|
|
|
* |
103
|
|
|
* @var \TechDivision\Import\Configuration\Jms\Configuration\SwiftMailer |
104
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\SwiftMailer") |
105
|
|
|
* @SerializedName("swift-mailer") |
106
|
|
|
*/ |
107
|
|
|
protected $swiftMailer; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* The import adapter configuration instance. |
111
|
|
|
* |
112
|
|
|
* @var \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface |
113
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ImportAdapter") |
114
|
|
|
* @SerializedName("import-adapter") |
115
|
|
|
*/ |
116
|
|
|
protected $importAdapter; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* The export adapter configuration instance. |
120
|
|
|
* |
121
|
|
|
* @var \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface |
122
|
|
|
* @Type("TechDivision\Import\Configuration\Jms\Configuration\Subject\ExportAdapter") |
123
|
|
|
* @SerializedName("export-adapter") |
124
|
|
|
*/ |
125
|
|
|
protected $exportAdapter; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Lifecycle callback that will be invoked after deserialization. |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
* @PostDeserialize |
132
|
|
|
*/ |
133
|
|
|
public function postDeserialize() |
134
|
|
|
{ |
135
|
|
|
|
136
|
|
|
// create an empty collection if no subjects has been specified |
137
|
|
|
if ($this->subjects === null) { |
138
|
|
|
$this->subjects = new ArrayCollection(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// set a default import adatper if none has been configured |
142
|
|
|
if ($this->importAdapter === null) { |
143
|
|
|
$this->importAdapter = new ImportAdapter(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// set a default export adatper if none has been configured |
147
|
|
|
if ($this->exportAdapter === null) { |
148
|
|
|
$this->exportAdapter = new ExportAdapter(); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set's the reference to the configuration instance. |
154
|
|
|
* |
155
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
156
|
|
|
* |
157
|
|
|
* @return void |
158
|
|
|
*/ |
159
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
160
|
|
|
{ |
161
|
|
|
$this->configuration = $configuration; |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Return's the reference to the configuration instance. |
166
|
|
|
* |
167
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
168
|
|
|
*/ |
169
|
|
|
public function getConfiguration() |
170
|
|
|
{ |
171
|
|
|
return $this->configuration; |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Return's the plugin's unique DI identifier. |
176
|
|
|
* |
177
|
|
|
* @return string The plugin's unique DI identifier |
178
|
|
|
*/ |
179
|
|
|
public function getId() |
180
|
|
|
{ |
181
|
|
|
return $this->id; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Return's the plugin's name or the ID, if the name is NOT set. |
186
|
|
|
* |
187
|
|
|
* @return string The plugin's name |
188
|
|
|
* @see \TechDivision\Import\Configuration\PluginConfigurationInterface::getId() |
189
|
|
|
*/ |
190
|
|
|
public function getName() |
191
|
|
|
{ |
192
|
|
|
return $this->name ? $this->name : $this->getId(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Return's the ArrayCollection with the operation's subjects. |
197
|
|
|
* |
198
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operation's subjects |
199
|
|
|
*/ |
200
|
|
|
public function getSubjects() |
201
|
|
|
{ |
202
|
|
|
|
203
|
|
|
// initialize the array with the subject configurations |
204
|
|
|
$subjects = array(); |
205
|
|
|
|
206
|
|
|
// iterate over the subject configurations |
207
|
|
|
foreach ($this->subjects as $subject) { |
208
|
|
|
// inject the parent plugin configuration |
209
|
|
|
$subject->setPluginConfiguration($this); |
210
|
|
|
// add the subject to the array |
211
|
|
|
$subjects[] = $subject; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
// return the array with subject configurations |
215
|
|
|
return $subjects; |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Return's the swift mailer configuration to use. |
220
|
|
|
* |
221
|
|
|
* @return \TechDivision\Import\Configuration\Jms\Configuration\SwiftMailer The swift mailer configuration to use |
222
|
|
|
*/ |
223
|
|
|
public function getSwiftMailer() |
224
|
|
|
{ |
225
|
|
|
return $this->swiftMailer; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Return's the import adapter configuration instance. |
230
|
|
|
* |
231
|
|
|
* @return \TechDivision\Import\Configuration\Subject\ImportAdapterConfigurationInterface The import adapter configuration instance |
232
|
|
|
*/ |
233
|
|
|
public function getImportAdapter() |
234
|
|
|
{ |
235
|
|
|
return $this->importAdapter; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Return's the export adapter configuration instance. |
240
|
|
|
* |
241
|
|
|
* @return \TechDivision\Import\Configuration\Subject\ExportAdapterConfigurationInterface The export adapter configuration instance |
242
|
|
|
*/ |
243
|
|
|
public function getExportAdapter() |
244
|
|
|
{ |
245
|
|
|
return $this->exportAdapter; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Set's the configuration of the operation the plugin has been configured for. |
250
|
|
|
* |
251
|
|
|
* @param \\TechDivision\Import\Configuration\OperationConfigurationInterface $operationConfiguration The operation configuration |
252
|
|
|
* |
253
|
|
|
* @return void |
254
|
|
|
*/ |
255
|
|
|
public function setOperationConfiguration(OperationConfigurationInterface $operationConfiguration) |
256
|
|
|
{ |
257
|
|
|
$this->operationConfiguration = $operationConfiguration; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Return's the configuration of the operation the plugin has been configured for. |
262
|
|
|
* |
263
|
|
|
* @return \TechDivision\Import\Configuration\OperationConfigurationInterface The operation configuration |
264
|
|
|
*/ |
265
|
|
|
public function getOperationConfiguration() |
266
|
|
|
{ |
267
|
|
|
return $this->operationConfiguration; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Return's the execution context configuration for the actualy plugin configuration. |
272
|
|
|
* |
273
|
|
|
* @return \TechDivision\Import\ExecutionContextInterface The execution context to use |
274
|
|
|
*/ |
275
|
|
|
public function getExecutionContext() |
276
|
|
|
{ |
277
|
|
|
return $this->getOperationConfiguration()->getExecutionContext(); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Return's the full opration name, which consists of the Magento edition, the entity type code and the operation name. |
282
|
|
|
* |
283
|
|
|
* @param string $separator The separator used to seperate the elements |
284
|
|
|
* |
285
|
|
|
* @return string The full operation name |
286
|
|
|
*/ |
287
|
|
|
public function getFullOperationName($separator = '/') |
|
|
|
|
288
|
|
|
{ |
289
|
|
|
return $this->getOperationConfiguration()->getFullName(); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
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..