1 | <?php |
||
46 | class ShopwareClient |
||
47 | { |
||
48 | const VERSION = '0.0.1'; |
||
49 | |||
50 | /** |
||
51 | * @var string|null |
||
52 | */ |
||
53 | protected $baseUrl; |
||
54 | |||
55 | /** |
||
56 | * @var string|null |
||
57 | */ |
||
58 | protected $username; |
||
59 | |||
60 | /** |
||
61 | * @var string|null |
||
62 | */ |
||
63 | protected $apiKey; |
||
64 | |||
65 | /** |
||
66 | * @var Client |
||
67 | */ |
||
68 | protected $client; |
||
69 | |||
70 | /** |
||
71 | * ShopwareClient constructor. |
||
72 | * |
||
73 | * @param $baseUrl |
||
74 | * @param null $username |
||
75 | * @param null $apiKey |
||
76 | */ |
||
77 | 10 | public function __construct($baseUrl, $username = null, $apiKey = null) |
|
86 | |||
87 | /** |
||
88 | * Does a request. |
||
89 | * |
||
90 | * @param $uri |
||
91 | * @param string $method |
||
92 | * @param null $body |
||
93 | * @param array $headers |
||
94 | * |
||
95 | * @return mixed|\Psr\Http\Message\ResponseInterface |
||
96 | */ |
||
97 | 8 | public function request($uri, $method = 'GET', $body = null, $headers = []) |
|
98 | { |
||
99 | 8 | if (empty($headers['Accept'])) { |
|
100 | 8 | $headers['Accept'] = 'application/json'; |
|
101 | 8 | } |
|
102 | |||
103 | 8 | if (empty($headers['Content-Type'])) { |
|
104 | 8 | $headers['Content-Type'] = 'application/json'; |
|
105 | 8 | } |
|
106 | |||
107 | 8 | return $this->client->request($method, $uri, [ |
|
108 | 8 | 'form_params' => $body, |
|
109 | 8 | 'headers' => $headers, |
|
110 | 'auth' => [ |
||
111 | 8 | $this->username, |
|
112 | 8 | $this->apiKey, |
|
113 | 8 | 'digest', |
|
114 | 8 | ], |
|
115 | 8 | ]); |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Magically get the query classes. |
||
120 | * |
||
121 | * @param $name |
||
122 | * @param array $arguments |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | 2 | public function __call($name, $arguments = []) |
|
140 | |||
141 | /** |
||
142 | * @return Client |
||
143 | */ |
||
144 | 1 | public function getClient() |
|
148 | |||
149 | /** |
||
150 | * @param Client $client |
||
151 | * |
||
152 | * @return ShopwareClient |
||
153 | */ |
||
154 | 10 | public function setClient($client) |
|
160 | } |
||
161 |