|
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\Handler\Request; |
|
9
|
|
|
|
|
10
|
|
|
use Exception; |
|
11
|
|
|
use FACTFinder\Util\Parameters; |
|
12
|
|
|
use Generated\Shared\Transfer\FactFinderSdkTrackingRequestTransfer; |
|
|
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\FactFinderSdkTrackingResponseTransfer; |
|
|
|
|
|
|
14
|
|
|
use SprykerEco\Client\FactFinderSdk\Business\Api\ApiConstants; |
|
15
|
|
|
use SprykerEco\Client\FactFinderSdk\Business\Api\Converter\ConverterFactory; |
|
16
|
|
|
use SprykerEco\Client\FactFinderSdk\Business\Api\FactFinderConnectorInterface; |
|
17
|
|
|
use SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig; |
|
18
|
|
|
|
|
19
|
|
|
class TrackingRequest extends AbstractRequest implements TrackingRequestInterface |
|
20
|
|
|
{ |
|
21
|
|
|
public const TRANSACTION_TYPE = ApiConstants::TRANSACTION_TYPE_SEARCH; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var \SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $config; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param \SprykerEco\Client\FactFinderSdk\Business\Api\FactFinderConnectorInterface $factFinderConnector |
|
30
|
|
|
* @param \SprykerEco\Client\FactFinderSdk\Business\Api\Converter\ConverterFactory $converterFactory |
|
31
|
|
|
* @param \SprykerEco\Client\FactFinderSdk\FactFinderSdkConfig $config |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(FactFinderConnectorInterface $factFinderConnector, ConverterFactory $converterFactory, FactFinderSdkConfig $config) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct($factFinderConnector, $converterFactory); |
|
36
|
|
|
$this->config = $config; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param \Generated\Shared\Transfer\FactFinderSdkTrackingRequestTransfer $factFinderTrackingRequestTransfer |
|
41
|
|
|
* |
|
42
|
|
|
* @return \Generated\Shared\Transfer\FactFinderSdkTrackingResponseTransfer |
|
43
|
|
|
*/ |
|
44
|
|
|
public function request(FactFinderSdkTrackingRequestTransfer $factFinderTrackingRequestTransfer) |
|
45
|
|
|
{ |
|
46
|
|
|
$parameters = new Parameters(); |
|
47
|
|
|
$parameters->setAll($this->getRequestData($factFinderTrackingRequestTransfer)); |
|
48
|
|
|
|
|
49
|
|
|
$parameters = $this->fillDefaultValues($parameters); |
|
50
|
|
|
$parameters = $this->removeEmptyParameters($parameters); |
|
51
|
|
|
$this->factFinderConnector->setRequestParameters($parameters); |
|
52
|
|
|
|
|
53
|
|
|
$trackingAdapter = $this->factFinderConnector->createTrackingAdapter(); |
|
54
|
|
|
|
|
55
|
|
|
try { |
|
56
|
|
|
$result = $trackingAdapter->applyTracking(); |
|
57
|
|
|
} catch (Exception $exception) { |
|
58
|
|
|
$result = false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$responseTransfer = new FactFinderSdkTrackingResponseTransfer(); |
|
62
|
|
|
$responseTransfer->setResult($result); |
|
63
|
|
|
|
|
64
|
|
|
return $responseTransfer; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param \Generated\Shared\Transfer\FactFinderSdkTrackingRequestTransfer $factFinderTrackingRequestTransfer |
|
69
|
|
|
* |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getRequestData(FactFinderSdkTrackingRequestTransfer $factFinderTrackingRequestTransfer) |
|
73
|
|
|
{ |
|
74
|
|
|
$data = $factFinderTrackingRequestTransfer->toArray(); |
|
75
|
|
|
|
|
76
|
|
|
foreach ($data as $key => $value) { |
|
77
|
|
|
$newKey = str_replace('_', '', ucwords($key, '_')); |
|
78
|
|
|
$newKey = lcfirst($newKey); |
|
79
|
|
|
|
|
80
|
|
|
if ($newKey !== $key) { |
|
81
|
|
|
$data[$newKey] = $value; |
|
82
|
|
|
unset($data[$key]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $data; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param \FACTFinder\Util\Parameters $parameters |
|
91
|
|
|
* |
|
92
|
|
|
* @return \FACTFinder\Util\Parameters |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function fillDefaultValues($parameters) |
|
95
|
|
|
{ |
|
96
|
|
|
$defaultValues = [ |
|
97
|
|
|
'channel' => $this->config->getFactFinderConfiguration()['channel'], |
|
98
|
|
|
]; |
|
99
|
|
|
|
|
100
|
|
|
foreach ($defaultValues as $key => $value) { |
|
101
|
|
|
if (empty($parameters[$key])) { |
|
102
|
|
|
$parameters[$key] = $value; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $parameters; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param \FACTFinder\Util\Parameters $parameters |
|
111
|
|
|
* |
|
112
|
|
|
* @return \FACTFinder\Util\Parameters |
|
113
|
|
|
*/ |
|
114
|
|
|
protected function removeEmptyParameters($parameters) |
|
115
|
|
|
{ |
|
116
|
|
|
foreach ($parameters->getArray() as $key => $value) { |
|
117
|
|
|
if ($value === '' || $value === null) { |
|
118
|
|
|
unset($parameters[$key]); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return $parameters; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
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