Regenerated PHP petstore sample.

This commit is contained in:
Arne Jørgensen 2015-10-27 22:58:25 +01:00
parent d907822fa9
commit 47b2ae934b
5 changed files with 163 additions and 105 deletions

View File

@ -431,9 +431,6 @@ class PetApi
//TODO support oauth
// make the API Call
try
{
@ -509,10 +506,16 @@ class PetApi
}
// form params
if ($name !== null) {
$formParams['name'] = $this->apiClient->getSerializer()->toFormValue($name);
}// form params
if ($status !== null) {
$formParams['status'] = $this->apiClient->getSerializer()->toFormValue($status);
}
@ -665,10 +668,22 @@ class PetApi
}
// form params
if ($additional_metadata !== null) {
$formParams['additionalMetadata'] = $this->apiClient->getSerializer()->toFormValue($additional_metadata);
}// form params
if ($file !== null) {
$formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file);
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
// See: https://wiki.php.net/rfc/curl-file-upload
if (function_exists('curl_file_create')) {
$formParams['file'] = curl_file_create($this->apiClient->getSerializer()->toFormValue($file));
} else {
$formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file);
}
}

View File

@ -165,6 +165,12 @@ class ApiClient
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// disable SSL verification, if needed
if ($this->config->getSSLVerification() == false) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
}
if (! empty($queryParams)) {
$url = ($url . '?' . http_build_query($queryParams));
}
@ -233,9 +239,14 @@ class ApiClient
$data = $http_body;
}
} else {
$data = json_decode($http_body);
if (json_last_error() > 0) { // if response is a string
$data = $http_body;
}
throw new ApiException(
"[".$response_info['http_code']."] Error connecting to the API ($url)",
$response_info['http_code'], $http_header, $http_body
$response_info['http_code'], $http_header, $data
);
}
return array($data, $http_header);

View File

@ -47,8 +47,8 @@ class ApiException extends Exception
{
/**
* The HTTP body of the server response.
* @var string
* The HTTP body of the server response either as Json or string.
* @var mixed
*/
protected $responseBody;
@ -67,9 +67,9 @@ class ApiException extends Exception
/**
* Constructor
* @param string $message Error message
* @param string $code HTTP status code
* @param int $code HTTP status code
* @param string $responseHeaders HTTP response header
* @param string $responseBody Deseralized response object
* @param mixed $responseBody HTTP body of the server response either as Json or string
*/
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null)
{
@ -89,9 +89,9 @@ class ApiException extends Exception
}
/**
* Gets the HTTP response body
* Gets the HTTP body of the server response either as Json or string
*
* @return string HTTP response body
* @return mixed HTTP body of the server response either as Json or string
*/
public function getResponseBody()
{

View File

@ -126,6 +126,15 @@ class Configuration
*/
protected $tempFolderPath;
/**
* Indicates if SSL verification should be enabled or disabled.
*
* This is useful if the host uses a self-signed SSL certificate.
*
* @var boolean True if the certificate should be validated, false otherwise.
*/
protected $sslVerification = true;
/**
* Constructor
*/
@ -418,6 +427,29 @@ class Configuration
return $this->tempFolderPath;
}
/**
* Sets if SSL verification should be enabled or disabled
*
* @param boolean $sslVerification True if the certificate should be validated, false otherwise
*
* @return Configuration
*/
public function setSSLVerification($sslVerification)
{
$this->sslVerification = $sslVerification;
return $this;
}
/**
* Gets if SSL verification should be enabled or disabled
*
* @return boolean True if the certificate should be validated, false otherwise
*/
public function getSSLVerification()
{
return $this->sslVerification;
}
/**
* Gets the default configuration instance
*

View File

@ -193,7 +193,7 @@ class ObjectSerializer
$deserialized = $values;
} elseif ($class === '\DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
} elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) {
settype($data, $class);
$deserialized = $data;
} elseif ($class === '\SplFileObject') {