@@ -490,13 +490,14 @@ public function reset(): Matomo
490490 /**
491491 * Make API request
492492 *
493- * @param string $method
494- * @param array $params
495- * @param array $optional
493+ * @param string $method HTTP method
494+ * @param array $params Query parameters
495+ * @param array $optional Optional arguments for this api call
496+ * @param int|null $format Override the response format
496497 * @return bool|object
497498 * @throws InvalidRequestException
498499 */
499- private function _request (string $ method , array $ params = [], array $ optional = [])
500+ private function _request (string $ method , array $ params = [], array $ optional = [], $ format = null )
500501 {
501502 $ url = $ this ->_parseUrl ($ method , $ params + $ optional );
502503 if ($ url === false ) {
@@ -520,7 +521,7 @@ private function _request(string $method, array $params = [], array $optional =
520521
521522 if (!empty ($ buffer )) {
522523 try {
523- return $ this ->_finishResponse ($ this ->_parseResponse ($ buffer ), $ method , $ params + $ optional );
524+ return $ this ->_finishResponse ($ this ->_parseResponse ($ buffer, $ format ), $ method , $ params + $ optional );
524525 } catch (InvalidResponseException $ e ) {
525526 throw new InvalidRequestException ($ e ->getMessage (), $ e ->getCode (), $ e );
526527 }
@@ -639,11 +640,17 @@ private function _isValidResponse($response)
639640 * Parse request result
640641 *
641642 * @param Response $response
643+ * @param int|null $overrideFormat Override the default format
642644 * @return mixed
643645 */
644- private function _parseResponse (Response $ response )
646+ private function _parseResponse (Response $ response, $ overrideFormat = null )
645647 {
646- switch ($ this ->_format ) {
648+ $ format = $ this ->_format ;
649+ if ($ overrideFormat !== null ) {
650+ $ format = $ overrideFormat ;
651+ }
652+
653+ switch ($ format ) {
647654 case self ::FORMAT_JSON :
648655 return json_decode ($ response , $ this ->_isJsonDecodeAssoc );
649656 default :
@@ -2483,7 +2490,7 @@ public function getImageGraph(
24832490 'aliasedGraph ' => $ aliasedGraph ,
24842491 'idGoal ' => $ idGoal ,
24852492 'colors ' => $ colors ,
2486- ], $ optional );
2493+ ], $ optional, self :: FORMAT_PHP );
24872494 }
24882495
24892496 /**
0 commit comments