mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-10 22:52:46 +00:00
Merge pull request #604 from wing328/php_fix_warning
Fixed PHP5.3 warning
This commit is contained in:
@@ -25,6 +25,16 @@ class APIClient {
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
/*
|
||||
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||
*/
|
||||
protected $curl_timeout = 0;
|
||||
|
||||
/*
|
||||
* @var string user agent of the HTTP request, set to "PHP-Swagger" by default
|
||||
*/
|
||||
protected $user_agent = "PHP-Swagger";
|
||||
|
||||
/**
|
||||
* @param string $host the address of the API server
|
||||
* @param string $headerName a header to pass on requests
|
||||
@@ -54,7 +64,7 @@ class APIClient {
|
||||
if (!is_numeric($seconds)) {
|
||||
throw new Exception('Timeout variable must be numeric.');
|
||||
}
|
||||
$this->curl_timout = $seconds;
|
||||
$this->curl_timeout = $seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,15 +94,16 @@ class APIClient {
|
||||
$headers[] = $this->headerName . ": " . $this->headerValue;
|
||||
}
|
||||
|
||||
if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) {
|
||||
if ((isset($headers['Content-Type']) and strpos($headers['Content-Type'], "multipart/form-data") < 0) and (is_object($postData) or is_array($postData))) {
|
||||
$postData = json_encode($this->sanitizeForSerialization($postData));
|
||||
}
|
||||
|
||||
$url = $this->host . $resourcePath;
|
||||
|
||||
$curl = curl_init();
|
||||
if ($this->curl_timout) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout);
|
||||
// set timeout, if needed
|
||||
if ($this->curl_timeout != 0) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout);
|
||||
}
|
||||
// return the result on success, rather than just TRUE
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
@@ -120,11 +131,7 @@ class APIClient {
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
// Set user agent
|
||||
if ($this->user_agent) {
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
|
||||
} else { // use PHP-Swagger as the default user agent
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, 'PHP-Swagger');
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
|
||||
|
||||
// Make the request
|
||||
$response = curl_exec($curl);
|
||||
|
||||
@@ -44,6 +44,7 @@ class {{classname}} {
|
||||
$resourcePath = "{{path}}";
|
||||
$resourcePath = str_replace("{format}", "json", $resourcePath);
|
||||
$method = "{{httpMethod}}";
|
||||
$httpBody = '';
|
||||
$queryParams = array();
|
||||
$headerParams = array();
|
||||
$formParams = array();
|
||||
@@ -77,16 +78,19 @@ class {{classname}} {
|
||||
$body = ${{paramName}};
|
||||
}{{/bodyParams}}
|
||||
|
||||
// for model (json/xml)
|
||||
if (isset($body)) {
|
||||
$httpBody = $body; // $body is the method argument, if present
|
||||
}
|
||||
|
||||
// for HTTP post (form)
|
||||
$body = $body ?: $formParams;
|
||||
|
||||
if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) {
|
||||
$body = http_build_query($body);
|
||||
$httpBody = http_build_query($formParams);
|
||||
}
|
||||
|
||||
// make the API Call
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
$queryParams, $body,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
|
||||
{{#returnType}}if(! $response) {
|
||||
|
||||
Reference in New Issue
Block a user