|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Client\FactFinderSdk\Business\Api; |
|
9
|
|
|
|
|
10
|
|
|
use Exception; |
|
11
|
|
|
use FACTFinder\Loader as FactFinderLoader; |
|
12
|
|
|
use FACTFinder\Util\Parameters; |
|
13
|
|
|
use Generated\Shared\Transfer\FactFinderSdkProductCampaignRequestTransfer; |
|
|
|
|
|
|
14
|
|
|
use Generated\Shared\Transfer\FactFinderSdkSearchRequestTransfer; |
|
|
|
|
|
|
15
|
|
|
use SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig; |
|
16
|
|
|
|
|
17
|
|
|
class FactFinderConnector implements FactFinderConnectorInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var \FACTFinder\Util\Pimple |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $dic; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \FACTFinder\Util\Parameters|null |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $requestParameters; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var \SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $factFinderConfig; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var \FACTFinder\Adapter\Search |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $searchAdapter; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var \FACTFinder\Adapter\TagCloud |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $tagCloudAdapter; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var \FACTFinder\Adapter\Recommendation |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $recommendationAdapter; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var \FACTFinder\Adapter\Suggest |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $suggestAdapter; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var \FACTFinder\Adapter\Tracking |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $trackingAdapter; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var \FACTFinder\Adapter\SimilarRecords |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $similarRecordsAdapter; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var \FACTFinder\Adapter\ProductCampaign |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $productCampaignAdapter; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var \FACTFinder\Adapter\Import |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $importAdapter; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var \FACTFinder\Adapter\Compare |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $compareAdapter; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param \SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig $factFinderConfig |
|
81
|
|
|
*/ |
|
82
|
|
|
public function __construct(FactFinderSdkConfig $factFinderConfig) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->factFinderConfig = $factFinderConfig; |
|
85
|
|
|
$this->dic = FactFinderLoader::getInstance('Util\Pimple'); |
|
86
|
|
|
|
|
87
|
|
|
$this->init(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return \FACTFinder\Adapter\Search |
|
92
|
|
|
*/ |
|
93
|
|
|
public function createSearchAdapter() |
|
94
|
|
|
{ |
|
95
|
|
|
$this->searchAdapter = FactFinderLoader::getInstance( |
|
96
|
|
|
'Adapter\Search', |
|
97
|
|
|
$this->dic['loggerClass'], |
|
98
|
|
|
$this->dic['configuration'], |
|
99
|
|
|
$this->dic['request'], |
|
100
|
|
|
$this->dic['clientUrlBuilder'] |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
return $this->searchAdapter; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return \FACTFinder\Adapter\TagCloud |
|
108
|
|
|
*/ |
|
109
|
|
|
public function createTagCloudAdapter() |
|
110
|
|
|
{ |
|
111
|
|
|
$this->tagCloudAdapter = FactFinderLoader::getInstance( |
|
112
|
|
|
'Adapter\TagCloud', |
|
113
|
|
|
$this->dic['loggerClass'], |
|
114
|
|
|
$this->dic['configuration'], |
|
115
|
|
|
$this->dic['request'], |
|
116
|
|
|
$this->dic['clientUrlBuilder'] |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
return $this->tagCloudAdapter; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return \FACTFinder\Adapter\Recommendation |
|
124
|
|
|
*/ |
|
125
|
|
|
public function createRecommendationAdapter() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->recommendationAdapter = FactFinderLoader::getInstance( |
|
128
|
|
|
'Adapter\Recommendation', |
|
129
|
|
|
$this->dic['loggerClass'], |
|
130
|
|
|
$this->dic['configuration'], |
|
131
|
|
|
$this->dic['request'], |
|
132
|
|
|
$this->dic['clientUrlBuilder'] |
|
133
|
|
|
); |
|
134
|
|
|
|
|
135
|
|
|
return $this->recommendationAdapter; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return \FACTFinder\Adapter\Suggest |
|
140
|
|
|
*/ |
|
141
|
|
|
public function createSuggestAdapter() |
|
142
|
|
|
{ |
|
143
|
|
|
$this->suggestAdapter = FactFinderLoader::getInstance( |
|
144
|
|
|
'Adapter\Suggest', |
|
145
|
|
|
$this->dic['loggerClass'], |
|
146
|
|
|
$this->dic['configuration'], |
|
147
|
|
|
$this->dic['request'], |
|
148
|
|
|
$this->dic['clientUrlBuilder'] |
|
149
|
|
|
); |
|
150
|
|
|
|
|
151
|
|
|
return $this->suggestAdapter; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return \FACTFinder\Adapter\Tracking |
|
156
|
|
|
*/ |
|
157
|
|
|
public function createTrackingAdapter() |
|
158
|
|
|
{ |
|
159
|
|
|
$this->trackingAdapter = FactFinderLoader::getInstance( |
|
160
|
|
|
'Adapter\Tracking', |
|
161
|
|
|
$this->dic['loggerClass'], |
|
162
|
|
|
$this->dic['configuration'], |
|
163
|
|
|
$this->dic['request'], |
|
164
|
|
|
$this->dic['clientUrlBuilder'] |
|
165
|
|
|
); |
|
166
|
|
|
|
|
167
|
|
|
return $this->trackingAdapter; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return \FACTFinder\Adapter\SimilarRecords |
|
172
|
|
|
*/ |
|
173
|
|
|
public function createSimilarRecordsAdapter() |
|
174
|
|
|
{ |
|
175
|
|
|
$this->similarRecordsAdapter = FactFinderLoader::getInstance( |
|
176
|
|
|
'Adapter\SimilarRecords', |
|
177
|
|
|
$this->dic['loggerClass'], |
|
178
|
|
|
$this->dic['configuration'], |
|
179
|
|
|
$this->dic['request'], |
|
180
|
|
|
$this->dic['clientUrlBuilder'] |
|
181
|
|
|
); |
|
182
|
|
|
|
|
183
|
|
|
return $this->similarRecordsAdapter; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return \FACTFinder\Adapter\ProductCampaign |
|
188
|
|
|
*/ |
|
189
|
|
|
public function createProductCampaignAdapter() |
|
190
|
|
|
{ |
|
191
|
|
|
$this->productCampaignAdapter = FactFinderLoader::getInstance( |
|
192
|
|
|
'Adapter\ProductCampaign', |
|
193
|
|
|
$this->dic['loggerClass'], |
|
194
|
|
|
$this->dic['configuration'], |
|
195
|
|
|
$this->dic['request'], |
|
196
|
|
|
$this->dic['clientUrlBuilder'] |
|
197
|
|
|
); |
|
198
|
|
|
|
|
199
|
|
|
return $this->productCampaignAdapter; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @return \FACTFinder\Adapter\Import |
|
204
|
|
|
*/ |
|
205
|
|
|
public function createImportAdapter() |
|
206
|
|
|
{ |
|
207
|
|
|
$this->importAdapter = FactFinderLoader::getInstance( |
|
208
|
|
|
'Adapter\Import', |
|
209
|
|
|
$this->dic['loggerClass'], |
|
210
|
|
|
$this->dic['configuration'], |
|
211
|
|
|
$this->dic['request'], |
|
212
|
|
|
$this->dic['clientUrlBuilder'] |
|
213
|
|
|
); |
|
214
|
|
|
|
|
215
|
|
|
return $this->importAdapter; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return \FACTFinder\Adapter\Compare |
|
220
|
|
|
*/ |
|
221
|
|
|
public function createCompareAdapter() |
|
222
|
|
|
{ |
|
223
|
|
|
$this->compareAdapter = FactFinderLoader::getInstance( |
|
224
|
|
|
'Adapter\Compare', |
|
225
|
|
|
$this->dic['loggerClass'], |
|
226
|
|
|
$this->dic['configuration'], |
|
227
|
|
|
$this->dic['request'], |
|
228
|
|
|
$this->dic['clientUrlBuilder'] |
|
229
|
|
|
); |
|
230
|
|
|
|
|
231
|
|
|
return $this->compareAdapter; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @return string |
|
236
|
|
|
*/ |
|
237
|
|
|
public function getPageContentEncoding() |
|
238
|
|
|
{ |
|
239
|
|
|
return $this->dic['configuration']->getPageContentEncoding(); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @return \FACTFinder\Util\Parameters |
|
244
|
|
|
*/ |
|
245
|
|
|
public function getRequestParameters() |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->requestParameters; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @param \FACTFinder\Util\Parameters $requestParameters |
|
252
|
|
|
* |
|
253
|
|
|
* @return void |
|
254
|
|
|
*/ |
|
255
|
|
|
public function setRequestParameters($requestParameters) |
|
256
|
|
|
{ |
|
257
|
|
|
$this->requestParameters = $requestParameters; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param \Generated\Shared\Transfer\FactFinderSdkSearchRequestTransfer $searchRequestTransfer |
|
262
|
|
|
* |
|
263
|
|
|
* @return \FACTFinder\Util\Parameters |
|
264
|
|
|
*/ |
|
265
|
|
|
public function createRequestParametersFromSearchRequestTransfer(FactFinderSdkSearchRequestTransfer $searchRequestTransfer) |
|
266
|
|
|
{ |
|
267
|
|
|
$config = $this->factFinderConfig->getFactFinderConfiguration(); |
|
268
|
|
|
$parameters = $searchRequestTransfer->getRequest(); |
|
269
|
|
|
|
|
270
|
|
|
if (empty($parameters['channel'])) { |
|
271
|
|
|
$parameters['channel'] = $config['channel']; |
|
272
|
|
|
} |
|
273
|
|
|
if (empty($parameters['query']) || $parameters['query'] == '*') { |
|
274
|
|
|
$parameters['navigation'] = true; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
return FactFinderLoader::getInstance( |
|
278
|
|
|
'Util\Parameters', |
|
279
|
|
|
$parameters |
|
280
|
|
|
); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @param \Generated\Shared\Transfer\FactFinderSdkProductCampaignRequestTransfer $factFinderProductCampaignRequestTransfer |
|
285
|
|
|
* |
|
286
|
|
|
* @return \FACTFinder\Util\Parameters |
|
287
|
|
|
*/ |
|
288
|
|
|
public function createRequestParametersFromProductCampaignRequestTransfer( |
|
289
|
|
|
FactFinderSdkProductCampaignRequestTransfer $factFinderProductCampaignRequestTransfer |
|
290
|
|
|
) { |
|
291
|
|
|
$parameters = []; |
|
292
|
|
|
$parameters['productNumber'] = $factFinderProductCampaignRequestTransfer->getProductNumber(); |
|
293
|
|
|
$parameters['sid'] = $factFinderProductCampaignRequestTransfer->getSid(); |
|
294
|
|
|
|
|
295
|
|
|
return FactFinderLoader::getInstance( |
|
296
|
|
|
'Util\Parameters', |
|
297
|
|
|
$parameters |
|
298
|
|
|
); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @return \FACTFinder\Util\Parameters |
|
303
|
|
|
*/ |
|
304
|
|
|
public function createRequestParametersFromRequestParser() |
|
305
|
|
|
{ |
|
306
|
|
|
/** @var \FACTFinder\Util\Parameters $requestParameters */ |
|
307
|
|
|
$requestParameters = $this->dic['requestParser']->getRequestParameters(); |
|
308
|
|
|
if (!$requestParameters->offsetExists('query')) { |
|
309
|
|
|
$requestParameters->offsetSet('query', '*'); |
|
310
|
|
|
} |
|
311
|
|
|
$query = trim($requestParameters->offsetGet('query')); |
|
312
|
|
|
if (!strlen($query)) { |
|
313
|
|
|
$requestParameters->offsetSet('query', '*'); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
return $requestParameters; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* @param \FACTFinder\Util\Parameters $parameters |
|
321
|
|
|
* |
|
322
|
|
|
* @return \FACTFinder\Data\SearchParameters |
|
323
|
|
|
*/ |
|
324
|
|
|
public function createSearchParameters(Parameters $parameters) |
|
325
|
|
|
{ |
|
326
|
|
|
return FactFinderLoader::getInstance( |
|
327
|
|
|
'Data\SearchParameters', |
|
328
|
|
|
$parameters |
|
329
|
|
|
); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* @return \FACTFinder\Data\SearchParameters |
|
334
|
|
|
*/ |
|
335
|
|
|
public function createSearchParametersFromRequestParser() |
|
336
|
|
|
{ |
|
337
|
|
|
return FactFinderLoader::getInstance( |
|
338
|
|
|
'Data\SearchParameters', |
|
339
|
|
|
$this->dic['requestParser']->getRequestParameters() |
|
340
|
|
|
); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @return string |
|
345
|
|
|
*/ |
|
346
|
|
|
public function getRequestTarget() |
|
347
|
|
|
{ |
|
348
|
|
|
return $this->dic['requestParser']->getRequestTarget(); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @return string |
|
353
|
|
|
*/ |
|
354
|
|
|
public function getSessionId() |
|
355
|
|
|
{ |
|
356
|
|
|
$sid = session_id(); |
|
357
|
|
|
if ($sid === '') { |
|
358
|
|
|
session_start(); |
|
359
|
|
|
$sid = session_id(); |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
return $sid; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @return string |
|
367
|
|
|
*/ |
|
368
|
|
|
public function getSearchStatusEnum() |
|
369
|
|
|
{ |
|
370
|
|
|
return FactFinderLoader::getClassName('Data\SearchStatus'); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* @return string |
|
375
|
|
|
*/ |
|
376
|
|
|
public function getArticleNumberSearchStatusEnum() |
|
377
|
|
|
{ |
|
378
|
|
|
return FactFinderLoader::getClassName('Data\ArticleNumberSearchStatus'); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @return void |
|
383
|
|
|
*/ |
|
384
|
|
|
protected function init() |
|
385
|
|
|
{ |
|
386
|
|
|
$this->dic['loggerClass'] = function ($c) { |
|
|
|
|
|
|
387
|
|
|
$loggerClass = FactFinderLoader::getClassName('Util\Log4PhpLogger'); |
|
388
|
|
|
$loggerClass::configure($this->getLog4phpConfigXml()); |
|
389
|
|
|
|
|
390
|
|
|
return $loggerClass; |
|
391
|
|
|
}; |
|
392
|
|
|
|
|
393
|
|
|
$this->dic['configuration'] = function ($c) { |
|
|
|
|
|
|
394
|
|
|
return FactFinderLoader::getInstance( |
|
395
|
|
|
'Core\ManualConfiguration', |
|
396
|
|
|
$this->factFinderConfig->getFactFinderConfiguration() |
|
397
|
|
|
); |
|
398
|
|
|
}; |
|
399
|
|
|
|
|
400
|
|
|
$this->dic['request'] = $this->dic->factory(function ($c) { |
|
401
|
|
|
return $c['requestFactory']->getRequest(); |
|
402
|
|
|
}); |
|
403
|
|
|
|
|
404
|
|
|
$this->dic['requestFactory'] = function ($c) { |
|
405
|
|
|
return FactFinderLoader::getInstance( |
|
406
|
|
|
'Core\Server\MultiCurlRequestFactory', |
|
407
|
|
|
$c['loggerClass'], |
|
408
|
|
|
$c['configuration'], |
|
409
|
|
|
$this->getRequestParameters() |
|
410
|
|
|
); |
|
411
|
|
|
}; |
|
412
|
|
|
|
|
413
|
|
|
$this->dic['clientUrlBuilder'] = function ($c) { |
|
414
|
|
|
return FactFinderLoader::getInstance( |
|
415
|
|
|
'Core\Client\UrlBuilder', |
|
416
|
|
|
$c['loggerClass'], |
|
417
|
|
|
$c['configuration'], |
|
418
|
|
|
$c['requestParser'], |
|
419
|
|
|
$c['encodingConverter'] |
|
420
|
|
|
); |
|
421
|
|
|
}; |
|
422
|
|
|
|
|
423
|
|
|
$this->dic['requestParser'] = function ($c) { |
|
424
|
|
|
return FactFinderLoader::getInstance( |
|
425
|
|
|
'Core\Client\RequestParser', |
|
426
|
|
|
$c['loggerClass'], |
|
427
|
|
|
$c['configuration'], |
|
428
|
|
|
$c['encodingConverter'] |
|
429
|
|
|
); |
|
430
|
|
|
}; |
|
431
|
|
|
|
|
432
|
|
|
$this->dic['encodingConverter'] = function ($c) { |
|
433
|
|
|
if (extension_loaded('iconv')) { |
|
434
|
|
|
$type = 'Core\IConvEncodingConverter'; |
|
435
|
|
|
} elseif ( |
|
436
|
|
|
function_exists('utf8_encode') |
|
437
|
|
|
&& function_exists('utf8_decode') |
|
438
|
|
|
) { |
|
439
|
|
|
$type = 'Core\Utf8EncodingConverter'; |
|
440
|
|
|
} else { |
|
441
|
|
|
throw new Exception('No encoding conversion available.'); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
return FactFinderLoader::getInstance( |
|
445
|
|
|
$type, |
|
446
|
|
|
$c['loggerClass'], |
|
447
|
|
|
$c['configuration'] |
|
448
|
|
|
); |
|
449
|
|
|
}; |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
/** |
|
453
|
|
|
* @return string |
|
454
|
|
|
*/ |
|
455
|
|
|
protected function getLog4phpConfigXml() |
|
456
|
|
|
{ |
|
457
|
|
|
return $this->factFinderConfig |
|
458
|
|
|
->getLog4PhpConfigPath(); |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths