Skip to content

Commit f914f26

Browse files
committed
Merge pull request #400 from FindTheBest/master
Fixing curl $postData for php bindings
2 parents c98a780 + 4a6e719 commit f914f26

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/resources/php/Swagger.mustache

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class APIClient {
2828
public static $PUT = "PUT";
2929
public static $DELETE = "DELETE";
3030
31+
private $curl_timout = 5;
32+
3133
/**
3234
* @param string $apiKey your API key
3335
* @param string $apiServer the address of the API server
@@ -37,6 +39,16 @@ class APIClient {
3739
$this->apiServer = $apiServer;
3840
}
3941

42+
/**
43+
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
44+
*/
45+
public function setTimeout($seconds) {
46+
if (!is_numeric($seconds)) {
47+
throw new Exception('Timeout variable must be numeric.');
48+
}
49+
$this->curl_timout = $seconds;
50+
}
51+
4052

4153
/**
4254
* @param string $resourcePath path to method endpoint
@@ -72,7 +84,9 @@ class APIClient {
7284
$url = $this->apiServer . $resourcePath;
7385

7486
$curl = curl_init();
75-
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
87+
if ($this->curl_timout) {
88+
curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout);
89+
}
7690
// return the result on success, rather than just TRUE
7791
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
7892
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

src/main/resources/php/api.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class {{classname}} {
7777
{{/formParams}}
7878
if (empty($body)) {
7979
$body = null;
80+
} else if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) {
81+
$body = http_build_query($body);
8082
}
8183

8284
// Make the API Call

0 commit comments

Comments
 (0)