|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) shopware AG <[email protected]> |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ShopwarePlugins\Connect\Components; |
|
9
|
|
|
|
|
10
|
|
|
use Firebase\JWT\JWT; |
|
11
|
|
|
use Shopware\Components\HttpClient\HttpClientInterface; |
|
12
|
|
|
use Shopware\Connect\Gateway; |
|
13
|
|
|
|
|
14
|
|
|
class SnHttpClient |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var \Shopware\Components\HttpClient\HttpClientInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $httpClient; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var \Shopware\Connect\Gateway |
|
23
|
|
|
*/ |
|
24
|
|
|
private $gateway; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var \ShopwarePlugins\Connect\Components\Config |
|
28
|
|
|
*/ |
|
29
|
|
|
private $configComponent; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
HttpClientInterface $httpClient, |
|
33
|
|
|
Gateway $gateway, |
|
34
|
|
|
Config $config |
|
35
|
|
|
) { |
|
36
|
|
|
$this->httpClient = $httpClient; |
|
37
|
|
|
$this->gateway = $gateway; |
|
38
|
|
|
$this->configComponent = $config; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Call SocialNetwork REST API |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $path |
|
45
|
|
|
* @param array $data |
|
46
|
|
|
* @return \Shopware\Components\HttpClient\Response |
|
47
|
|
|
*/ |
|
48
|
|
|
public function sendRequestToConnect($path, array $data = []) |
|
49
|
|
|
{ |
|
50
|
|
|
$host = $this->configComponent->getConfig('connectDebugHost'); |
|
|
|
|
|
|
51
|
|
|
if (!$host || $host == '') { |
|
52
|
|
|
$host = $this->configComponent->getMarketplaceUrl(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$shopId = $this->gateway->getShopId(); |
|
56
|
|
|
$key = $this->configComponent->getConfig('apiKey'); |
|
57
|
|
|
$token = [ |
|
58
|
|
|
'iss' => $shopId, |
|
59
|
|
|
'aud' => 'SocialNetwork', |
|
60
|
|
|
'iat' => time(), |
|
61
|
|
|
'nbf' => time(), |
|
62
|
|
|
'exp' => time() + (60), |
|
63
|
|
|
'content' => $data |
|
64
|
|
|
]; |
|
65
|
|
|
$connectAuthKey = JWT::encode($token, $key); |
|
66
|
|
|
$url = $host . '/rest/' . $path; |
|
67
|
|
|
|
|
68
|
|
|
$response = $this->httpClient->post( |
|
69
|
|
|
$url, |
|
70
|
|
|
[ |
|
71
|
|
|
'content-type' => 'application/json', |
|
72
|
|
|
'X-Shopware-Connect-Shop' => $shopId, |
|
73
|
|
|
'X-Shopware-Connect-Key' => $connectAuthKey |
|
74
|
|
|
] |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
return $response; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.