1 | <?php |
||
24 | class Api |
||
25 | { |
||
26 | /** |
||
27 | * Example: http://www.example.com |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $host; |
||
32 | |||
33 | /** |
||
34 | * The API key from your Dandomain admin |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $apiKey; |
||
39 | |||
40 | /** |
||
41 | * This is the HTTP client |
||
42 | * |
||
43 | * @var ClientInterface |
||
44 | */ |
||
45 | protected $client; |
||
46 | |||
47 | /** |
||
48 | * This is the last response |
||
49 | * |
||
50 | * @var Response |
||
51 | */ |
||
52 | protected $response; |
||
53 | |||
54 | /** |
||
55 | * These are the options used for the next request |
||
56 | * After that request, these options are reset |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $options; |
||
61 | |||
62 | /** |
||
63 | * These are default options used for every request |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $defaultOptions; |
||
68 | |||
69 | /** |
||
70 | * These are the resolved options used in the last request |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $lastOptions; |
||
75 | |||
76 | /* |
||
77 | * These are endpoints in the Dandomain API |
||
78 | */ |
||
79 | /** |
||
80 | * @var Endpoint\Customer |
||
81 | */ |
||
82 | protected $customer; |
||
83 | |||
84 | /** |
||
85 | * @var Endpoint\Discount |
||
86 | */ |
||
87 | protected $discount; |
||
88 | |||
89 | /** |
||
90 | * @var Endpoint\Order; |
||
91 | */ |
||
92 | protected $order; |
||
93 | |||
94 | /** |
||
95 | * @var Endpoint\Product; |
||
96 | */ |
||
97 | protected $product; |
||
98 | |||
99 | /** |
||
100 | * @var Endpoint\ProductData; |
||
101 | */ |
||
102 | protected $productData; |
||
103 | |||
104 | /** |
||
105 | * @var Endpoint\ProductTag; |
||
106 | */ |
||
107 | protected $productTag; |
||
108 | |||
109 | /** |
||
110 | * @var Endpoint\RelatedData; |
||
111 | */ |
||
112 | protected $relatedData; |
||
113 | |||
114 | /** |
||
115 | * @var Endpoint\Settings; |
||
116 | */ |
||
117 | protected $settings; |
||
118 | |||
119 | /** |
||
120 | * @var Endpoint\Plugin; |
||
121 | */ |
||
122 | protected $plugin; |
||
123 | |||
124 | 4 | public function __construct(string $host, string $apiKey, array $defaultOptions = []) |
|
136 | |||
137 | /** |
||
138 | * This ensures lazy loading of the endpoint classes |
||
139 | * |
||
140 | * @param string $name |
||
141 | * @return Endpoint\Endpoint |
||
142 | */ |
||
143 | 4 | public function __get($name) |
|
161 | |||
162 | /** |
||
163 | * Will always return a JSON result contrary to Dandomains API |
||
164 | * Errors are formatted as described here: http://jsonapi.org/format/#errors |
||
165 | * |
||
166 | * @param string $method |
||
167 | * @param string $uri |
||
168 | * @param array|\stdClass $body The body is sent as JSON |
||
169 | * @param array $options |
||
170 | * @return mixed |
||
171 | */ |
||
172 | 2 | public function doRequest(string $method, string $uri, $body = null, array $options = []) |
|
236 | |||
237 | /** |
||
238 | * @return ClientInterface |
||
239 | */ |
||
240 | 2 | public function getClient() : ClientInterface |
|
248 | |||
249 | /** |
||
250 | * @param ClientInterface $client |
||
251 | * @return Api |
||
252 | */ |
||
253 | 2 | public function setClient(ClientInterface $client) : Api |
|
258 | |||
259 | /** |
||
260 | * Returns the latest response |
||
261 | * |
||
262 | * @return ResponseInterface |
||
263 | */ |
||
264 | public function getResponse() : ResponseInterface |
||
268 | |||
269 | /** |
||
270 | * Sets request options for the next request |
||
271 | * |
||
272 | * @param array $options |
||
273 | * @return Api |
||
274 | */ |
||
275 | public function setOptions(array $options) : Api |
||
280 | |||
281 | /** |
||
282 | * Sets default request options |
||
283 | * |
||
284 | * @param array $defaultOptions |
||
285 | * @return Api |
||
286 | */ |
||
287 | 1 | public function setDefaultOptions(array $defaultOptions) : Api |
|
292 | |||
293 | /** |
||
294 | * @return array |
||
295 | */ |
||
296 | 1 | public function getLastOptions(): array |
|
300 | |||
301 | /** |
||
302 | * Helper method to convert a \stdClass into an array |
||
303 | * |
||
304 | * @param $obj |
||
305 | * @return array |
||
306 | */ |
||
307 | protected function objectToArray($obj) : array |
||
315 | |||
316 | 2 | protected function configureOptions(OptionsResolver $resolver) |
|
331 | |||
332 | 2 | protected function resolveOptions(array ...$options) : array |
|
346 | } |
||
347 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: