Skip to content

Commit f0cf120

Browse files
committed
🔥
1 parent d86fa25 commit f0cf120

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/MagicAPI/ApiClientTrait.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,33 @@ public function __call(string $name, array $arguments):ResponseInterface{
108108
$body = Psr7\clean_query_params($body);
109109
}
110110

111+
112+
if((is_array($body) || is_object($body)) && !empty($body)){
113+
114+
if(!isset($headers['Content-type'])){
115+
$headers['Content-type'] = 'application/x-www-form-urlencoded';
116+
}
117+
118+
if($headers['Content-type'] === 'application/x-www-form-urlencoded'){
119+
$body = http_build_query($body, '', '&', PHP_QUERY_RFC1738);
120+
}
121+
elseif($headers['Content-type'] === 'application/json'){
122+
$body = json_encode($body);
123+
}
124+
else{
125+
$body = null; // @todo
126+
}
127+
128+
}
129+
130+
111131
}
112132

113133
$params = Psr7\clean_query_params($params);
114134

115135
if($this->logger instanceof LoggerInterface){
116136

117-
$this->logger->debug(get_called_class().'::__call() -> '.(new ReflectionClass($this))->getShortName().'::'.$name.'()', [
137+
$this->logger->debug('ApiClientTrait::__call() -> '.(new ReflectionClass($this))->getShortName().'::'.$name.'()', [
118138
'$endpoint' => $endpoint, '$method' => $method, '$params' => $params, '$body' => $body, '$headers' => $headers,
119139
]);
120140

0 commit comments

Comments
 (0)