File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -520,6 +520,21 @@ $config['ShopifyApiFeatures'] = ['include-presentment-prices'];
520
520
$shopify = new PHPShopify\ShopifySDK($config);
521
521
```
522
522
523
+ ### ShopifySDK Request callback
524
+
525
+ Sometimes you will want to log all of your requests, you can setup a global logging callback, that will be triggered after the curl request has been made.
526
+
527
+ ```
528
+ // set the logging callback
529
+ \PHPShopify\CurlRequest::setCurlCallback(function(CurlResponse $response){
530
+
531
+ Log::info('Shopify API Request', [
532
+ 'body' => $response->getBody(),
533
+ 'headers' => $response->getHeaders(),
534
+ ]);
535
+
536
+ });
537
+
523
538
524
539
## Reference
525
540
- [Shopify API Reference](https://help.shopify.com/api/reference/)
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ class CurlRequest
42
42
*/
43
43
protected static $ config = array ();
44
44
45
+ /**
46
+ * User callback to get the response
47
+ * @closure
48
+ */
49
+ protected static $ curlCallback ;
50
+
45
51
/**
46
52
* Initialize the curl resource
47
53
*
@@ -208,7 +214,33 @@ protected static function processRequest($ch)
208
214
209
215
self ::$ lastHttpResponseHeaders = $ response ->getHeaders ();
210
216
217
+ // call the user callback with the response
218
+ self ::callCurlCallback ($ response );
219
+
211
220
return $ response ->getBody ();
212
221
}
213
222
223
+ /**
224
+ * set the user callback to be called after the curl request
225
+ *
226
+ * @param closure $userCallback
227
+ * @return void
228
+ */
229
+ public static function setCurlCallback ($ curlCallback )
230
+ {
231
+ self ::$ curlCallback = $ curlCallback ;
232
+ }
233
+
234
+ /**
235
+ * call the user callback and pass the response
236
+ *
237
+ * @param CurlResponse $response
238
+ * @return CurlResponse
239
+ */
240
+ protected static function callCurlCallback ($ response )
241
+ {
242
+ if (self ::$ curlCallback ) {
243
+ return call_user_func (self ::$ curlCallback , $ response );
244
+ }
245
+ }
214
246
}
You can’t perform that action at this time.
0 commit comments