temporary folder setting

This commit is contained in:
wing328 2015-06-26 23:55:51 +08:00
parent 7f31da734d
commit 259b31ccd4
22 changed files with 3697 additions and 3671 deletions

View File

@ -19,206 +19,206 @@ namespace {{invokerPackage}};
class ApiClient {
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
public static $PUT = "PUT";
public static $DELETE = "DELETE";
/** @var Configuration */
protected $config;
/** @var ObjectSerializer */
protected $serializer;
/**
* @param Configuration $config config for this ApiClient
*/
function __construct(Configuration $config = null) {
if ($config == null) {
$config = Configuration::getDefaultConfiguration();
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
public static $PUT = "PUT";
public static $DELETE = "DELETE";
/** @var Configuration */
protected $config;
/** @var ObjectSerializer */
protected $serializer;
/**
* @param Configuration $config config for this ApiClient
*/
function __construct(Configuration $config = null) {
if ($config == null) {
$config = Configuration::getDefaultConfiguration();
}
$this->config = $config;
$this->serializer = new ObjectSerializer();
}
/**
* get the config
* @return Configuration
*/
public function getConfig() {
return $this->config;
}
/**
* get the serializer
* @return ObjectSerializer
*/
public function getSerializer() {
return $this->serializer;
}
/**
* Get API key (with prefix if set)
* @param string $apiKey name of apikey
* @return string API key with the prefix
*/
public function getApiKeyWithPrefix($apiKeyIdentifier) {
$prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier);
$apiKey = $this->config->getApiKey($apiKeyIdentifier);
if (!isset($apiKey)) {
return null;
}
if (isset($prefix)) {
$keyWithPrefix = $prefix." ".$apiKey;
} else {
$keyWithPrefix = $apiKey;
}
return $keyWithPrefix;
}
$this->config = $config;
$this->serializer = new ObjectSerializer();
}
/**
* get the config
* @return Configuration
*/
public function getConfig() {
return $this->config;
}
/**
* get the serializer
* @return ObjectSerializer
*/
public function getSerializer() {
return $this->serializer;
}
/**
* Get API key (with prefix if set)
* @param string $apiKey name of apikey
* @return string API key with the prefix
*/
public function getApiKeyWithPrefix($apiKey) {
$prefix = $this->config->getApiKeyPrefix($apiKey);
$apiKey = $this->config->getApiKey($apiKey);
if (!isset($apiKey)) {
return null;
}
if (isset($prefix)) {
$keyWithPrefix = $prefix." ".$apiKey;
} else {
$keyWithPrefix = $apiKey;
}
return $keyWithPrefix;
}
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
* @param array $queryParams parameters to be place in query URL
* @param array $postData parameters to be placed in POST body
* @param array $headerParams parameters to be place in request header
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
* @return mixed
*/
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
* @param array $queryParams parameters to be place in query URL
* @param array $postData parameters to be placed in POST body
* @param array $headerParams parameters to be place in request header
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
* @return mixed
*/
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
$headers = array();
# construct the http header
$headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
$headers = array();
# construct the http header
$headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
// form data
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
$postData = http_build_query($postData);
}
else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
}
$url = $this->config->getHost() . $resourcePath;
$curl = curl_init();
// set timeout, if needed
if ($this->config->getCurlTimeout() != 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
}
// return the result on success, rather than just TRUE
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (! empty($queryParams)) {
$url = ($url . '?' . http_build_query($queryParams));
}
if ($method == self::$POST) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PATCH) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PUT) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$DELETE) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
// Set user agent
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
// debugging for curl
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
} else {
curl_setopt($curl, CURLOPT_VERBOSE, 0);
}
// obtain the HTTP response headers
curl_setopt($curl, CURLOPT_HEADER, 1);
// Make the request
$response = curl_exec($curl);
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = substr($response, 0, $http_header_size);
$http_body = substr($response, $http_header_size);
$response_info = curl_getinfo($curl);
// debug HTTP response body
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
}
// Handle the response
if ($response_info['http_code'] == 0) {
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
// return raw body if response is a file
if ($responseType == '\SplFileObject') {
return array($http_body, $http_header);
}
$data = json_decode($http_body);
if (json_last_error() > 0) { // if response is a string
$data = $http_body;
}
} else {
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
$response_info['http_code'], $http_header, $http_body);
}
return array($data, $http_header);
}
// form data
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
$postData = http_build_query($postData);
/*
* return the header 'Accept' based on an array of Accept provided
*
* @param string[] $accept Array of header
* @return string Accept (e.g. application/json)
*/
public static function selectHeaderAccept($accept) {
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
return NULL;
} elseif (preg_grep("/application\/json/i", $accept)) {
return 'application/json';
} else {
return implode(',', $accept);
}
}
else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
/*
* return the content type based on an array of content-type provided
*
* @param string[] content_type_array Array fo content-type
* @return string Content-Type (e.g. application/json)
*/
public static function selectHeaderContentType($content_type) {
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
return 'application/json';
} elseif (preg_grep("/application\/json/i", $content_type)) {
return 'application/json';
} else {
return implode(',', $content_type);
}
}
$url = $this->config->getHost() . $resourcePath;
$curl = curl_init();
// set timeout, if needed
if ($this->config->getCurlTimeout() != 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
}
// return the result on success, rather than just TRUE
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (! empty($queryParams)) {
$url = ($url . '?' . http_build_query($queryParams));
}
if ($method == self::$POST) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PATCH) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PUT) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$DELETE) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
// Set user agent
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
// debugging for curl
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
} else {
curl_setopt($curl, CURLOPT_VERBOSE, 0);
}
// obtain the HTTP response headers
curl_setopt($curl, CURLOPT_HEADER, 1);
// Make the request
$response = curl_exec($curl);
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = substr($response, 0, $http_header_size);
$http_body = substr($response, $http_header_size);
$response_info = curl_getinfo($curl);
// debug HTTP response body
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
}
// Handle the response
if ($response_info['http_code'] == 0) {
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
// return raw body if response is a file
if ($responseType == '\SplFileObject') {
return array($http_body, $http_header);
}
$data = json_decode($http_body);
if (json_last_error() > 0) { // if response is a string
$data = $http_body;
}
} else {
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
$response_info['http_code'], $http_header, $http_body);
}
return array($data, $http_header);
}
/*
* return the header 'Accept' based on an array of Accept provided
*
* @param string[] $accept Array of header
* @return string Accept (e.g. application/json)
*/
public static function selectHeaderAccept($accept) {
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
return NULL;
} elseif (preg_grep("/application\/json/i", $accept)) {
return 'application/json';
} else {
return implode(',', $accept);
}
}
/*
* return the content type based on an array of content-type provided
*
* @param string[] content_type_array Array fo content-type
* @return string Content-Type (e.g. application/json)
*/
public static function selectHeaderContentType($content_type) {
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
return 'application/json';
} elseif (preg_grep("/application\/json/i", $content_type)) {
return 'application/json';
} else {
return implode(',', $content_type);
}
}
}

View File

@ -21,50 +21,50 @@ use \Exception;
class ApiException extends Exception {
/** @var string The HTTP body of the server response. */
protected $responseBody;
/** @var string[] The HTTP header of the server response. */
protected $responseHeaders;
/**
* The deserialized response object
*/
protected $responseObject;
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Get the HTTP response header
*
* @return string HTTP response header
*/
public function getResponseHeaders() {
return $this->responseHeaders;
}
/**
* Get the HTTP response body
*
* @return string HTTP response body
*/
public function getResponseBody() {
return $this->responseBody;
}
/**
* sets the deseralized response object (during deserialization)
* @param mixed $obj
*/
public function setResponseObject($obj) {
$this->responseObject = $obj;
}
public function getResponseObject() {
return $this->responseObject;
}
/** @var string The HTTP body of the server response. */
protected $responseBody;
/** @var string[] The HTTP header of the server response. */
protected $responseHeaders;
/**
* The deserialized response object
*/
protected $responseObject;
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Get the HTTP response header
*
* @return string HTTP response header
*/
public function getResponseHeaders() {
return $this->responseHeaders;
}
/**
* Get the HTTP response body
*
* @return string HTTP response body
*/
public function getResponseBody() {
return $this->responseBody;
}
/**
* sets the deseralized response object (during deserialization)
* @param mixed $obj
*/
public function setResponseObject($obj) {
$this->responseObject = $obj;
}
public function getResponseObject() {
return $this->responseObject;
}
}

View File

@ -9,29 +9,29 @@ class ObjectSerializer {
* @return string serialized form of $data
*/
public function sanitizeForSerialization($data) {
if (is_scalar($data) || null === $data) {
$sanitized = $data;
} else if ($data instanceof \DateTime) {
$sanitized = $data->format(\DateTime::ISO8601);
} else if (is_array($data)) {
foreach ($data as $property => $value) {
$data[$property] = $this->sanitizeForSerialization($value);
if (is_scalar($data) || null === $data) {
$sanitized = $data;
} else if ($data instanceof \DateTime) {
$sanitized = $data->format(\DateTime::ISO8601);
} else if (is_array($data)) {
foreach ($data as $property => $value) {
$data[$property] = $this->sanitizeForSerialization($value);
}
$sanitized = $data;
} else if (is_object($data)) {
$values = array();
foreach (array_keys($data::$swaggerTypes) as $property) {
$getter = $data::$getters[$property];
if ($data->$getter() !== null) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter());
}
}
$sanitized = $values;
} else {
$sanitized = (string)$data;
}
$sanitized = $data;
} else if (is_object($data)) {
$values = array();
foreach (array_keys($data::$swaggerTypes) as $property) {
$getter = $data::$getters[$property];
if ($data->$getter() !== null) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter());
}
}
$sanitized = $values;
} else {
$sanitized = (string)$data;
}
return $sanitized;
return $sanitized;
}
/**
@ -41,7 +41,7 @@ class ObjectSerializer {
* @return string the serialized object
*/
public function toPathValue($value) {
return rawurlencode($this->toString($value));
return rawurlencode($this->toString($value));
}
/**
@ -53,11 +53,11 @@ class ObjectSerializer {
* @return string the serialized object
*/
public function toQueryValue($object) {
if (is_array($object)) {
return implode(',', $object);
} else {
return $this->toString($object);
}
if (is_array($object)) {
return implode(',', $object);
} else {
return $this->toString($object);
}
}
/**
@ -68,7 +68,7 @@ class ObjectSerializer {
* @return string the header string
*/
public function toHeaderValue($value) {
return $this->toString($value);
return $this->toString($value);
}
/**
@ -79,11 +79,11 @@ class ObjectSerializer {
* @return string the form string
*/
public function toFormValue($value) {
if ($value instanceof SplFileObject) {
return $value->getRealPath();
} else {
return $this->toString($value);
}
if ($value instanceof SplFileObject) {
return $value->getRealPath();
} else {
return $this->toString($value);
}
}
/**
@ -94,11 +94,11 @@ class ObjectSerializer {
* @return string the header string
*/
public function toString($value) {
if ($value instanceof \DateTime) { // datetime in ISO8601 format
return $value->format(\DateTime::ISO8601);
} else {
return $value;
}
if ($value instanceof \DateTime) { // datetime in ISO8601 format
return $value->format(\DateTime::ISO8601);
} else {
return $value;
}
}
/**
@ -109,65 +109,65 @@ class ObjectSerializer {
* @return object an instance of $class
*/
public function deserialize($data, $class, $httpHeader=null) {
if (null === $data) {
$deserialized = null;
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
$inner = substr($class, 4, -1);
$deserialized = array();
if(strrpos($inner, ",") !== false) {
$subClass_array = explode(',', $inner, 2);
$subClass = $subClass_array[1];
foreach ($data as $key => $value) {
$deserialized[$key] = $this->deserialize($value, $subClass);
}
if (null === $data) {
$deserialized = null;
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
$inner = substr($class, 4, -1);
$deserialized = array();
if(strrpos($inner, ",") !== false) {
$subClass_array = explode(',', $inner, 2);
$subClass = $subClass_array[1];
foreach ($data as $key => $value) {
$deserialized[$key] = $this->deserialize($value, $subClass);
}
}
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
$subClass = substr($class, 0, -2);
$values = array();
foreach ($data as $key => $value) {
$values[] = $this->deserialize($value, $subClass);
}
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} elseif ($class === '\SplFileObject') {
# determine temp folder path
if (!isset(Configuration::getDefaultConfig->$tempFolderPath) || '' === Configuration::$tempFolderPath) {
$tmpFolderPath = sys_get_temp_dir();
} else {
$tmpFolderPath = Configuration::tempFolderPath;
}
# determine file name
if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) {
$filename = $tmpFolderPath.$match[1];
} else {
$filename = tempnam($tmpFolderPath, '');
}
$deserialized = new \SplFileObject($filename, "w");
$byte_written = $deserialized->fwrite($data);
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile());
} else {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
$propertySetter = $instance::$setters[$property];
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
continue;
}
$propertyValue = $data->{$instance::$attributeMap[$property]};
if (isset($propertyValue)) {
$instance->$propertySetter($this->deserialize($propertyValue, $type));
}
}
$deserialized = $instance;
}
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
$subClass = substr($class, 0, -2);
$values = array();
foreach ($data as $key => $value) {
$values[] = $this->deserialize($value, $subClass);
}
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} elseif ($class === '\SplFileObject') {
# determine temp folder path
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
$tmpFolderPath = sys_get_temp_dir();
} else {
$tmpFolderPath = Configuration::tempFolderPath;
}
# determine file name
if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) {
$filename = $tmpFolderPath.$match[1];
} else {
$filename = tempnam($tmpFolderPath, '');
}
$deserialized = new \SplFileObject($filename, "w");
$byte_written = $deserialized->fwrite($data);
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile());
} else {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
$propertySetter = $instance::$setters[$property];
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
continue;
}
$propertyValue = $data->{$instance::$attributeMap[$property]};
if (isset($propertyValue)) {
$instance->$propertySetter($this->deserialize($propertyValue, $type));
}
}
$deserialized = $instance;
}
return $deserialized;
return $deserialized;
}
}

View File

@ -30,132 +30,132 @@ use \{{invokerPackage}}\ObjectSerializer;
{{#operations}}
class {{classname}} {
/** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */
private $apiClient;
/**
* @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use
*/
function __construct($apiClient = null) {
if ($apiClient == null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('{{basePath}}');
}
$this->apiClient = $apiClient;
}
/**
* @return \{{invokerPackage}}\ApiClient get the API client
*/
public function getApiClient() {
return $this->apiClient;
}
/**
* @param \{{invokerPackage}}\ApiClient $apiClient set the API client
* @return {{classname}}
*/
public function setApiClient(ApiClient $apiClient) {
$this->apiClient = $apiClient;
return $this;
}
{{#operation}}
/**
* {{{nickname}}}
*
* {{{summary}}}
*
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
* @throws \{{invokerPackage}}\ApiException on non-2xx response
*/
public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) {
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
}
{{/required}}{{/allParams}}
// parse inputs
$resourcePath = "{{path}}";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "{{httpMethod}}";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
{{#queryParams}}// query params
if(${{paramName}} !== null) {
$queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
}{{/queryParams}}
{{#headerParams}}// header params
if(${{paramName}} !== null) {
$headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
}{{/headerParams}}
{{#pathParams}}// path params
if(${{paramName}} !== null) {
$resourcePath = str_replace("{" . "{{baseName}}" . "}",
$this->apiClient->getSerializer()->toPathValue(${{paramName}}),
$resourcePath);
}{{/pathParams}}
{{#formParams}}// form params
if (${{paramName}} !== null) {
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}});
}{{/formParams}}
{{#bodyParams}}// body params
$_tempBody = null;
if (isset(${{paramName}})) {
$_tempBody = ${{paramName}};
}{{/bodyParams}}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
{{#authMethods}}{{#isApiKey}}
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
if (isset($apiKey)) {
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
}{{/isApiKey}}
{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
{{/authMethods}}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
} catch (ApiException $e) {
switch ($e->getCode()) { {{#responses}}{{#dataType}}
case {{code}}:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader);
$e->setResponseObject($data);
break;{{/dataType}}{{/responses}}
/** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */
private $apiClient;
/**
* @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use
*/
function __construct($apiClient = null) {
if ($apiClient == null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('{{basePath}}');
}
throw $e;
}
{{#returnType}}
if (!$response) {
return null;
}
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'{{returnType}}');
return $responseObject;
{{/returnType}}
}
{{/operation}}
$this->apiClient = $apiClient;
}
/**
* @return \{{invokerPackage}}\ApiClient get the API client
*/
public function getApiClient() {
return $this->apiClient;
}
/**
* @param \{{invokerPackage}}\ApiClient $apiClient set the API client
* @return {{classname}}
*/
public function setApiClient(ApiClient $apiClient) {
$this->apiClient = $apiClient;
return $this;
}
{{#operation}}
/**
* {{{nickname}}}
*
* {{{summary}}}
*
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
* @throws \{{invokerPackage}}\ApiException on non-2xx response
*/
public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) {
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
>>>>>>> temporary folder setting
}
{{/required}}{{/allParams}}
// parse inputs
$resourcePath = "{{path}}";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "{{httpMethod}}";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
{{#queryParams}}// query params
if(${{paramName}} !== null) {
$queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
}{{/queryParams}}
{{#headerParams}}// header params
if(${{paramName}} !== null) {
$headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
}{{/headerParams}}
{{#pathParams}}// path params
if(${{paramName}} !== null) {
$resourcePath = str_replace("{" . "{{baseName}}" . "}",
$this->apiClient->getSerializer()->toPathValue(${{paramName}}),
$resourcePath);
}{{/pathParams}}
{{#formParams}}// form params
if (${{paramName}} !== null) {
$formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}});
}{{/formParams}}
{{#bodyParams}}// body params
$_tempBody = null;
if (isset(${{paramName}})) {
$_tempBody = ${{paramName}};
}{{/bodyParams}}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
{{#authMethods}}{{#isApiKey}}
$apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
if (isset($apiKey)) {
{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
}{{/isApiKey}}
{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
{{/authMethods}}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
} catch (ApiException $e) {
switch ($e->getCode()) { {{#responses}}{{#dataType}}
case {{code}}:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader);
$e->setResponseObject($data);
break;{{/dataType}}{{/responses}}
}
throw $e;
}
{{#returnType}}
if (!$response) {
return null;
}
return $this->apiClient->getSerializer()->deserialize($response,'{{returnType}}');
{{/returnType}}
}
{{/operation}}
}
{{/operations}}

View File

@ -1,33 +1,33 @@
{
"name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}}
"version": "{{artifactVersion}}",{{/artifactVersion}}
"description": "{{description}}",
"keywords": [
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
"name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}}
"version": "{{artifactVersion}}",{{/artifactVersion}}
"description": "{{description}}",
"keywords": [
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }
}
}

View File

@ -19,262 +19,265 @@ namespace {{invokerPackage}};
class Configuration {
private static $defaultConfiguration = null;
/** @var string[] Associate array to store API key(s) */
protected $apiKeys = array();
/** string[] Associate array to store API prefix (e.g. Bearer) */
protected $apiKeyPrefixes = array();
/** @var string Username for HTTP basic authentication */
protected $username = '';
/** @var string Password for HTTP basic authentication */
protected $password = '';
/** @var \{{invokerPackage}}\ApiClient The default instance of ApiClient */
protected $defaultHeaders = array();
/** @var string The host */
protected $host = 'http://localhost';
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
protected $curlTimeout = 0;
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
protected $userAgent = "PHP-Swagger";
/** @var bool Debug switch (default set to false) */
protected $debug = false;
/** @var string Debug file location (log to STDOUT by default) */
protected $debugFile = 'php://output';
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKey($key, $value) {
$this->apiKeys[$key] = $value;
return $this;
}
/**
* @param $key
* @return string
*/
public function getApiKey($key) {
return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null;
}
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKeyPrefix($key, $value) {
$this->apiKeyPrefixes[$key] = $value;
return $this;
}
/**
* @param $key
* @return string
*/
public function getApiKeyPrefix($key) {
return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null;
}
/**
* @param string $username
* @return Configuration
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* @param string $password
* @return Configuration
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* add default header
*
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
* @return ApiClient
*/
public function addDefaultHeader($headerName, $headerValue) {
if (!is_string($headerName)) {
throw new \InvalidArgumentException('Header name must be a string.');
private static $defaultConfiguration = null;
/** @var string[] Associate array to store API key(s) */
protected $apiKeys = array();
/** string[] Associate array to store API prefix (e.g. Bearer) */
protected $apiKeyPrefixes = array();
/** @var string Username for HTTP basic authentication */
protected $username = '';
/** @var string Password for HTTP basic authentication */
protected $password = '';
/** @var \{{invokerPackage}}\ApiClient The default instance of ApiClient */
protected $defaultHeaders = array();
/** @var string The host */
protected $host = 'http://localhost';
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
protected $curlTimeout = 0;
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
protected $userAgent = "PHP-Swagger";
/** @var bool Debug switch (default set to false) */
protected $debug = false;
/** @var string Debug file location (log to STDOUT by default) */
protected $debugFile = 'php://output';
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKey($key, $value) {
$this->apiKeys[$key] = $value;
return $this;
}
$this->defaultHeaders[$headerName] = $headerValue;
return $this;
}
/**
* get the default header
*
* @return array default header
*/
public function getDefaultHeaders() {
return $this->defaultHeaders;
}
/**
* delete a default header
* @param string $headerName the header to delete
* @return Configuration
*/
public function deleteDefaultHeader($headerName) {
unset($this->defaultHeaders[$headerName]);
}
/**
* @param string $host
* @return Configuration
*/
public function setHost($host) {
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/**
* set the user agent of the api client
*
* @param string $userAgent the user agent of the api client
* @return ApiClient
*/
public function setUserAgent($userAgent) {
if (!is_string($userAgent)) {
throw new \InvalidArgumentException('User-agent must be a string.');
/**
* @param $key
* @return string
*/
public function getApiKey($key) {
return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null;
}
$this->userAgent = $userAgent;
return $this;
}
/**
* get the user agent of the api client
*
* @return string user agent
*/
public function getUserAgent() {
return $this->userAgent;
}
/**
* set the HTTP timeout value
*
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
* @return ApiClient
*/
public function setCurlTimeout($seconds) {
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKeyPrefix($key, $value) {
$this->apiKeyPrefixes[$key] = $value;
return $this;
}
$this->curlTimeout = $seconds;
return $this;
}
/**
* get the HTTP timeout value
*
* @return string HTTP timeout value
*/
public function getCurlTimeout() {
return $this->curlTimeout;
}
/**
* @param bool $debug
* @return Configuration
*/
public function setDebug($debug) {
$this->debug = $debug;
return $this;
}
/**
* @return bool
*/
public function getDebug() {
return $this->debug;
}
/**
* @param string $debugFile
* @return Configuration
*/
public function setDebugFile($debugFile) {
$this->debugFile = $debugFile;
return $this;
}
/**
* @return string
*/
public function getDebugFile() {
return $this->debugFile;
}
/**
* @return Configuration
*/
public static function getDefaultConfiguration() {
if (self::$defaultConfiguration == null) {
return new Configuration();
/**
* @param $key
* @return string
*/
public function getApiKeyPrefix($key) {
return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null;
}
return self::$defaultConfiguration;
}
public static function setDefaultConfiguration(Configuration $config) {
self::$defaultConfiguration = $config;
}
/*
* return the report for debuggin
*/
public static function toDebugReport() {
$report = "PHP SDK ({{invokerPackage}}) Debug Report:\n";
$report .= " OS: ".php_uname()."\n";
$report .= " PHP Version: ".phpversion()."\n";
$report .= " Swagger Spec Version: {{version}}\n";
$report .= " SDK Package Version: {{version}}\n";
return $report;
}
/**
* @param string $username
* @return Configuration
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* @param string $password
* @return Configuration
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* add default header
*
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
* @return ApiClient
*/
public function addDefaultHeader($headerName, $headerValue) {
if (!is_string($headerName)) {
throw new \InvalidArgumentException('Header name must be a string.');
}
$this->defaultHeaders[$headerName] = $headerValue;
return $this;
}
/**
* get the default header
*
* @return array default header
*/
public function getDefaultHeaders() {
return $this->defaultHeaders;
}
/**
* delete a default header
* @param string $headerName the header to delete
* @return Configuration
*/
public function deleteDefaultHeader($headerName) {
unset($this->defaultHeaders[$headerName]);
}
/**
* @param string $host
* @return Configuration
*/
public function setHost($host) {
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/**
* set the user agent of the api client
*
* @param string $userAgent the user agent of the api client
* @return ApiClient
*/
public function setUserAgent($userAgent) {
if (!is_string($userAgent)) {
throw new \InvalidArgumentException('User-agent must be a string.');
}
$this->userAgent = $userAgent;
return $this;
}
/**
* get the user agent of the api client
*
* @return string user agent
*/
public function getUserAgent() {
return $this->userAgent;
}
/**
* set the HTTP timeout value
*
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
* @return ApiClient
*/
public function setCurlTimeout($seconds) {
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
}
$this->curlTimeout = $seconds;
return $this;
}
/**
* get the HTTP timeout value
*
* @return string HTTP timeout value
*/
public function getCurlTimeout() {
return $this->curlTimeout;
}
/**
* @param bool $debug
* @return Configuration
*/
public function setDebug($debug) {
$this->debug = $debug;
return $this;
}
/**
* @return bool
*/
public function getDebug() {
return $this->debug;
}
/**
* @param string $debugFile
* @return Configuration
*/
public function setDebugFile($debugFile) {
$this->debugFile = $debugFile;
return $this;
}
/**
* @return string
*/
public function getDebugFile() {
return $this->debugFile;
}
/**
* @return Configuration
*/
public static function getDefaultConfiguration() {
if (self::$defaultConfiguration == null) {
return new Configuration();
}
return self::$defaultConfiguration;
}
/**
* @param Configuration $config
*/
public static function setDefaultConfiguration(Configuration $config) {
self::$defaultConfiguration = $config;
}
/*
* return the report for debugging
*/
public static function toDebugReport() {
$report = "PHP SDK ({{invokerPackage}}) Debug Report:\n";
$report .= " OS: ".php_uname()."\n";
$report .= " PHP Version: ".phpversion()."\n";
$report .= " Swagger Spec Version: {{version}}\n";
$report .= " SDK Package Version: {{version}}\n";
return $report;
}
}

View File

@ -29,82 +29,82 @@ namespace {{modelPackage}};
use \ArrayAccess;
class {{classname}} implements ArrayAccess {
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
{{#vars}}
/** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/
protected ${{name}};
{{/vars}}
public function __construct(array $data = null) {
if ($data != null) {
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
{{/hasMore}}{{/vars}}
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
{{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}},
{{/hasMore}}{{/vars}}
);
{{#vars}}
/** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/
protected ${{name}};
{{/vars}}
public function __construct(array $data = null) {
if ($data != null) {
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
{{/hasMore}}{{/vars}}
}
}
}
{{#vars}}
/**
* get {{name}}
* @return {{datatype}}
*/
public function {{getter}}() {
return $this->{{name}};
}
/**
* set {{name}}
* @param {{datatype}} ${{name}}
* @return $this
*/
public function {{setter}}(${{name}}) {
$this->{{name}} = ${{name}};
return $this;
}
{{/vars}}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
{{#vars}}
/**
* get {{name}}
* @return {{datatype}}
*/
public function {{getter}}() {
return $this->{{name}};
}
/**
* set {{name}}
* @param {{datatype}} ${{name}}
* @return $this
*/
public function {{setter}}(${{name}}) {
$this->{{name}} = ${{name}};
return $this;
}
{{/vars}}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
}
}
}
}
{{/model}}
{{/models}}

View File

@ -235,7 +235,7 @@
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Pet"
"type": "file"
}
},
"400": {

View File

@ -1,32 +1,32 @@
{
"name": "swagger/swagger-client",
"description": "",
"keywords": [
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
"name": "swagger/swagger-client",
"description": "",
"keywords": [
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "Swagger\\Client\\" : "lib/" }
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "Swagger\\Client\\" : "lib/" }
}
}

View File

@ -29,315 +29,312 @@ use \Swagger\Client\ObjectSerializer;
class StoreApi {
/** @var \Swagger\Client\ApiClient instance of the ApiClient */
private $apiClient;
/**
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use
*/
function __construct($apiClient = null) {
if ($apiClient == null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
/** @var \Swagger\Client\ApiClient instance of the ApiClient */
private $apiClient;
/**
* @param \Swagger\Client\ApiClient|null $apiClient The api client to use
*/
function __construct($apiClient = null) {
if ($apiClient == null) {
$apiClient = new ApiClient();
$apiClient->getConfig()->setHost('http://petstore.swagger.io/v2');
}
$this->apiClient = $apiClient;
}
$this->apiClient = $apiClient;
}
/**
* @return \Swagger\Client\ApiClient get the API client
*/
public function getApiClient() {
return $this->apiClient;
}
/**
* @param \Swagger\Client\ApiClient $apiClient set the API client
* @return StoreApi
*/
public function setApiClient(ApiClient $apiClient) {
$this->apiClient = $apiClient;
return $this;
}
/**
* getInventory
*
* Returns pet inventories by status
*
* @return map[string,int]
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getInventory() {
// parse inputs
$resourcePath = "/store/inventory";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "GET";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) {
$headerParams['api_key'] = $apiKey;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams, 'map[string,int]');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader);
$e->setResponseObject($data);
break;
/**
* @return \Swagger\Client\ApiClient get the API client
*/
public function getApiClient() {
return $this->apiClient;
}
/**
* @param \Swagger\Client\ApiClient $apiClient set the API client
* @return StoreApi
*/
public function setApiClient(ApiClient $apiClient) {
$this->apiClient = $apiClient;
return $this;
}
/**
* getInventory
*
* Returns pet inventories by status
*
* @return map[string,int]
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getInventory() {
// parse inputs
$resourcePath = "/store/inventory";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "GET";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
throw $e;
}
if (!$response) {
return null;
}
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'map[string,int]');
return $responseObject;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
/**
* placeOrder
*
* Place an order for a pet
*
* @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required)
* @return \Swagger\Client\Model\Order
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function placeOrder($body) {
// parse inputs
$resourcePath = "/store/order";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "POST";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = $body;
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Order');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
$e->setResponseObject($data);
break;
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
throw $e;
}
if (!$response) {
return null;
}
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order');
return $responseObject;
}
/**
* getOrderById
*
* Find purchase order by ID
*
* @param string $order_id ID of pet that needs to be fetched (required)
* @return \Swagger\Client\Model\Order
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getOrderById($order_id) {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
}
// parse inputs
$resourcePath = "/store/order/{orderId}";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "GET";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// path params
if($order_id !== null) {
$resourcePath = str_replace("{" . "orderId" . "}",
$this->apiClient->getSerializer()->toPathValue($order_id),
$resourcePath);
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Order');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
$e->setResponseObject($data);
break;
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) {
$headerParams['api_key'] = $apiKey;
}
throw $e;
}
if (!$response) {
return null;
}
$responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order');
return $responseObject;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams, 'map[string,int]');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader);
$e->setResponseObject($data);
break;
}
/**
* deleteOrder
*
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @return void
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function deleteOrder($order_id) {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
}
// parse inputs
$resourcePath = "/store/order/{orderId}";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "DELETE";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// path params
if($order_id !== null) {
$resourcePath = str_replace("{" . "orderId" . "}",
$this->apiClient->getSerializer()->toPathValue($order_id),
$resourcePath);
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
switch ($e->getCode()) {
throw $e;
}
if (!$response) {
return null;
}
throw $e;
}
}
return $this->apiClient->getSerializer()->deserialize($response,'map[string,int]');
}
/**
* placeOrder
*
* Place an order for a pet
*
* @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required)
* @return \Swagger\Client\Model\Order
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function placeOrder($body) {
// parse inputs
$resourcePath = "/store/order";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "POST";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// body params
$_tempBody = null;
if (isset($body)) {
$_tempBody = $body;
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Order');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
$e->setResponseObject($data);
break;
}
throw $e;
}
if (!$response) {
return null;
}
return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order');
}
/**
* getOrderById
*
* Find purchase order by ID
*
* @param string $order_id ID of pet that needs to be fetched (required)
* @return \Swagger\Client\Model\Order
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getOrderById($order_id) {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
}
// parse inputs
$resourcePath = "/store/order/{orderId}";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "GET";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// path params
if($order_id !== null) {
$resourcePath = str_replace("{" . "orderId" . "}",
$this->apiClient->getSerializer()->toPathValue($order_id),
$resourcePath);
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Order');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
$e->setResponseObject($data);
break;
}
throw $e;
}
if (!$response) {
return null;
}
return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order');
}
/**
* deleteOrder
*
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @return void
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function deleteOrder($order_id) {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
}
// parse inputs
$resourcePath = "/store/order/{orderId}";
$resourcePath = str_replace("{format}", "json", $resourcePath);
$method = "DELETE";
$httpBody = '';
$queryParams = array();
$headerParams = array();
$formParams = array();
$_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml'));
if (!is_null($_header_accept)) {
$headerParams['Accept'] = $_header_accept;
}
$headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array());
// path params
if($order_id !== null) {
$resourcePath = str_replace("{" . "orderId" . "}",
$this->apiClient->getSerializer()->toPathValue($order_id),
$resourcePath);
}
// for model (json/xml)
if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present
} else if (count($formParams) > 0) {
// for HTTP post (form)
$httpBody = $formParams;
}
// make the API Call
try {
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
switch ($e->getCode()) {
}
throw $e;
}
}
}

View File

@ -19,206 +19,206 @@ namespace Swagger\Client;
class ApiClient {
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
public static $PUT = "PUT";
public static $DELETE = "DELETE";
/** @var Configuration */
protected $config;
/** @var ObjectSerializer */
protected $serializer;
/**
* @param Configuration $config config for this ApiClient
*/
function __construct(Configuration $config = null) {
if ($config == null) {
$config = Configuration::getDefaultConfiguration();
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
public static $PUT = "PUT";
public static $DELETE = "DELETE";
/** @var Configuration */
protected $config;
/** @var ObjectSerializer */
protected $serializer;
/**
* @param Configuration $config config for this ApiClient
*/
function __construct(Configuration $config = null) {
if ($config == null) {
$config = Configuration::getDefaultConfiguration();
}
$this->config = $config;
$this->serializer = new ObjectSerializer();
}
/**
* get the config
* @return Configuration
*/
public function getConfig() {
return $this->config;
}
/**
* get the serializer
* @return ObjectSerializer
*/
public function getSerializer() {
return $this->serializer;
}
/**
* Get API key (with prefix if set)
* @param string $apiKey name of apikey
* @return string API key with the prefix
*/
public function getApiKeyWithPrefix($apiKeyIdentifier) {
$prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier);
$apiKey = $this->config->getApiKey($apiKeyIdentifier);
if (!isset($apiKey)) {
return null;
}
if (isset($prefix)) {
$keyWithPrefix = $prefix." ".$apiKey;
} else {
$keyWithPrefix = $apiKey;
}
return $keyWithPrefix;
}
$this->config = $config;
$this->serializer = new ObjectSerializer();
}
/**
* get the config
* @return Configuration
*/
public function getConfig() {
return $this->config;
}
/**
* get the serializer
* @return ObjectSerializer
*/
public function getSerializer() {
return $this->serializer;
}
/**
* Get API key (with prefix if set)
* @param string $apiKey name of apikey
* @return string API key with the prefix
*/
public function getApiKeyWithPrefix($apiKey) {
$prefix = $this->config->getApiKeyPrefix($apiKey);
$apiKey = $this->config->getApiKey($apiKey);
if (!isset($apiKey)) {
return null;
}
if (isset($prefix)) {
$keyWithPrefix = $prefix." ".$apiKey;
} else {
$keyWithPrefix = $apiKey;
}
return $keyWithPrefix;
}
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
* @param array $queryParams parameters to be place in query URL
* @param array $postData parameters to be placed in POST body
* @param array $headerParams parameters to be place in request header
* @throws \Swagger\Client\ApiException on a non 2xx response
* @return mixed
*/
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
/**
* @param string $resourcePath path to method endpoint
* @param string $method method to call
* @param array $queryParams parameters to be place in query URL
* @param array $postData parameters to be placed in POST body
* @param array $headerParams parameters to be place in request header
* @throws \Swagger\Client\ApiException on a non 2xx response
* @return mixed
*/
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
$headers = array();
# construct the http header
$headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
$headers = array();
# construct the http header
$headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
// form data
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
$postData = http_build_query($postData);
}
else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
}
$url = $this->config->getHost() . $resourcePath;
$curl = curl_init();
// set timeout, if needed
if ($this->config->getCurlTimeout() != 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
}
// return the result on success, rather than just TRUE
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (! empty($queryParams)) {
$url = ($url . '?' . http_build_query($queryParams));
}
if ($method == self::$POST) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PATCH) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PUT) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$DELETE) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
// Set user agent
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
// debugging for curl
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
} else {
curl_setopt($curl, CURLOPT_VERBOSE, 0);
}
// obtain the HTTP response headers
curl_setopt($curl, CURLOPT_HEADER, 1);
// Make the request
$response = curl_exec($curl);
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = substr($response, 0, $http_header_size);
$http_body = substr($response, $http_header_size);
$response_info = curl_getinfo($curl);
// debug HTTP response body
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
}
// Handle the response
if ($response_info['http_code'] == 0) {
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
// return raw body if response is a file
if ($responseType == '\SplFileObject') {
return array($http_body, $http_header);
}
$data = json_decode($http_body);
if (json_last_error() > 0) { // if response is a string
$data = $http_body;
}
} else {
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
$response_info['http_code'], $http_header, $http_body);
}
return array($data, $http_header);
}
// form data
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
$postData = http_build_query($postData);
/*
* return the header 'Accept' based on an array of Accept provided
*
* @param string[] $accept Array of header
* @return string Accept (e.g. application/json)
*/
public static function selectHeaderAccept($accept) {
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
return NULL;
} elseif (preg_grep("/application\/json/i", $accept)) {
return 'application/json';
} else {
return implode(',', $accept);
}
}
else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
$postData = json_encode($this->serializer->sanitizeForSerialization($postData));
/*
* return the content type based on an array of content-type provided
*
* @param string[] content_type_array Array fo content-type
* @return string Content-Type (e.g. application/json)
*/
public static function selectHeaderContentType($content_type) {
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
return 'application/json';
} elseif (preg_grep("/application\/json/i", $content_type)) {
return 'application/json';
} else {
return implode(',', $content_type);
}
}
$url = $this->config->getHost() . $resourcePath;
$curl = curl_init();
// set timeout, if needed
if ($this->config->getCurlTimeout() != 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
}
// return the result on success, rather than just TRUE
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (! empty($queryParams)) {
$url = ($url . '?' . http_build_query($queryParams));
}
if ($method == self::$POST) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PATCH) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$PUT) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method == self::$DELETE) {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
} else if ($method != self::$GET) {
throw new ApiException('Method ' . $method . ' is not recognized.');
}
curl_setopt($curl, CURLOPT_URL, $url);
// Set user agent
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
// debugging for curl
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile());
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a'));
} else {
curl_setopt($curl, CURLOPT_VERBOSE, 0);
}
// obtain the HTTP response headers
curl_setopt($curl, CURLOPT_HEADER, 1);
// Make the request
$response = curl_exec($curl);
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = substr($response, 0, $http_header_size);
$http_body = substr($response, $http_header_size);
$response_info = curl_getinfo($curl);
// debug HTTP response body
if ($this->config->getDebug()) {
error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile());
}
// Handle the response
if ($response_info['http_code'] == 0) {
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
// return raw body if response is a file
if ($responseType == '\SplFileObject') {
return array($http_body, $http_header);
}
$data = json_decode($http_body);
if (json_last_error() > 0) { // if response is a string
$data = $http_body;
}
} else {
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
$response_info['http_code'], $http_header, $http_body);
}
return array($data, $http_header);
}
/*
* return the header 'Accept' based on an array of Accept provided
*
* @param string[] $accept Array of header
* @return string Accept (e.g. application/json)
*/
public static function selectHeaderAccept($accept) {
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
return NULL;
} elseif (preg_grep("/application\/json/i", $accept)) {
return 'application/json';
} else {
return implode(',', $accept);
}
}
/*
* return the content type based on an array of content-type provided
*
* @param string[] content_type_array Array fo content-type
* @return string Content-Type (e.g. application/json)
*/
public static function selectHeaderContentType($content_type) {
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
return 'application/json';
} elseif (preg_grep("/application\/json/i", $content_type)) {
return 'application/json';
} else {
return implode(',', $content_type);
}
}
}

View File

@ -21,50 +21,50 @@ use \Exception;
class ApiException extends Exception {
/** @var string The HTTP body of the server response. */
protected $responseBody;
/** @var string[] The HTTP header of the server response. */
protected $responseHeaders;
/**
* The deserialized response object
*/
protected $responseObject;
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Get the HTTP response header
*
* @return string HTTP response header
*/
public function getResponseHeaders() {
return $this->responseHeaders;
}
/**
* Get the HTTP response body
*
* @return string HTTP response body
*/
public function getResponseBody() {
return $this->responseBody;
}
/**
* sets the deseralized response object (during deserialization)
* @param mixed $obj
*/
public function setResponseObject($obj) {
$this->responseObject = $obj;
}
public function getResponseObject() {
return $this->responseObject;
}
/** @var string The HTTP body of the server response. */
protected $responseBody;
/** @var string[] The HTTP header of the server response. */
protected $responseHeaders;
/**
* The deserialized response object
*/
protected $responseObject;
public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) {
parent::__construct($message, $code);
$this->responseHeaders = $responseHeaders;
$this->responseBody = $responseBody;
}
/**
* Get the HTTP response header
*
* @return string HTTP response header
*/
public function getResponseHeaders() {
return $this->responseHeaders;
}
/**
* Get the HTTP response body
*
* @return string HTTP response body
*/
public function getResponseBody() {
return $this->responseBody;
}
/**
* sets the deseralized response object (during deserialization)
* @param mixed $obj
*/
public function setResponseObject($obj) {
$this->responseObject = $obj;
}
public function getResponseObject() {
return $this->responseObject;
}
}

View File

@ -19,262 +19,292 @@ namespace Swagger\Client;
class Configuration {
private static $defaultConfiguration = null;
private static $defaultConfiguration = null;
/** @var string[] Associate array to store API key(s) */
protected $apiKeys = array();
/** string[] Associate array to store API prefix (e.g. Bearer) */
protected $apiKeyPrefixes = array();
/** @var string Username for HTTP basic authentication */
protected $username = '';
/** @var string Password for HTTP basic authentication */
protected $password = '';
/** @var \Swagger\Client\ApiClient The default instance of ApiClient */
protected $defaultHeaders = array();
/** @var string The host */
protected $host = 'http://localhost';
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
protected $curlTimeout = 0;
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
protected $userAgent = "PHP-Swagger";
/** @var bool Debug switch (default set to false) */
protected $debug = false;
/** @var string Debug file location (log to STDOUT by default) */
protected $debugFile = 'php://output';
/** @var string Debug file location (log to STDOUT by default) */
protected $tempFolderPath;
/** @var string[] Associate array to store API key(s) */
protected $apiKeys = array();
/**
* @param string $tempFolderPath
*/
public function __construct() {
$this->tempFolderPath = sys_get_temp_dir();
}
/** string[] Associate array to store API prefix (e.g. Bearer) */
protected $apiKeyPrefixes = array();
/** @var string Username for HTTP basic authentication */
protected $username = '';
/** @var string Password for HTTP basic authentication */
protected $password = '';
/** @var \Swagger\Client\ApiClient The default instance of ApiClient */
protected $defaultHeaders = array();
/** @var string The host */
protected $host = 'http://localhost';
/** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */
protected $curlTimeout = 0;
/** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */
protected $userAgent = "PHP-Swagger";
/** @var bool Debug switch (default set to false) */
protected $debug = false;
/** @var string Debug file location (log to STDOUT by default) */
protected $debugFile = 'php://output';
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKey($key, $value) {
$this->apiKeys[$key] = $value;
return $this;
}
/**
* @param $key
* @return string
*/
public function getApiKey($key) {
return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null;
}
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKeyPrefix($key, $value) {
$this->apiKeyPrefixes[$key] = $value;
return $this;
}
/**
* @param $key
* @return string
*/
public function getApiKeyPrefix($key) {
return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null;
}
/**
* @param string $username
* @return Configuration
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* @param string $password
* @return Configuration
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* add default header
*
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
* @return ApiClient
*/
public function addDefaultHeader($headerName, $headerValue) {
if (!is_string($headerName)) {
throw new \InvalidArgumentException('Header name must be a string.');
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKey($key, $value) {
$this->apiKeys[$key] = $value;
return $this;
}
/**
* @param $key
* @return string
*/
public function getApiKey($key) {
return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null;
}
/**
* @param string $key
* @param string $value
* @return Configuration
*/
public function setApiKeyPrefix($key, $value) {
$this->apiKeyPrefixes[$key] = $value;
return $this;
}
/**
* @param $key
* @return string
*/
public function getApiKeyPrefix($key) {
return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null;
}
/**
* @param string $username
* @return Configuration
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* @param string $password
* @return Configuration
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* add default header
*
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
* @return ApiClient
*/
public function addDefaultHeader($headerName, $headerValue) {
if (!is_string($headerName)) {
throw new \InvalidArgumentException('Header name must be a string.');
}
$this->defaultHeaders[$headerName] = $headerValue;
return $this;
}
/**
* get the default header
*
* @return array default header
*/
public function getDefaultHeaders() {
return $this->defaultHeaders;
}
/**
* delete a default header
* @param string $headerName the header to delete
* @return Configuration
*/
public function deleteDefaultHeader($headerName) {
unset($this->defaultHeaders[$headerName]);
}
/**
* @param string $host
* @return Configuration
*/
public function setHost($host) {
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/**
* set the user agent of the api client
*
* @param string $userAgent the user agent of the api client
* @return ApiClient
*/
public function setUserAgent($userAgent) {
if (!is_string($userAgent)) {
throw new \InvalidArgumentException('User-agent must be a string.');
}
$this->userAgent = $userAgent;
return $this;
}
/**
* get the user agent of the api client
*
* @return string user agent
*/
public function getUserAgent() {
return $this->userAgent;
}
/**
* set the HTTP timeout value
*
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
* @return ApiClient
*/
public function setCurlTimeout($seconds) {
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
}
$this->curlTimeout = $seconds;
return $this;
}
/**
* get the HTTP timeout value
*
* @return string HTTP timeout value
*/
public function getCurlTimeout() {
return $this->curlTimeout;
}
/**
* @param bool $debug
* @return Configuration
*/
public function setDebug($debug) {
$this->debug = $debug;
return $this;
}
/**
* @return bool
*/
public function getDebug() {
return $this->debug;
}
/**
* @param string $debugFile
* @return Configuration
*/
public function setDebugFile($debugFile) {
$this->debugFile = $debugFile;
return $this;
}
/**
* @return string
*/
public function getDebugFile() {
return $this->debugFile;
}
/**
* @param string $debugFile
* @return Configuration
*/
public function setTempFolderPath($tempFolderPath) {
$this->tempFolderPath = $tempFolderPath;
return $this;
}
/**
* @return string
*/
public function getTempFolderPath() {
return $this->tempFolderPath;
}
$this->defaultHeaders[$headerName] = $headerValue;
return $this;
}
/**
* get the default header
*
* @return array default header
*/
public function getDefaultHeaders() {
return $this->defaultHeaders;
}
/**
* delete a default header
* @param string $headerName the header to delete
* @return Configuration
*/
public function deleteDefaultHeader($headerName) {
unset($this->defaultHeaders[$headerName]);
}
/**
* @param string $host
* @return Configuration
*/
public function setHost($host) {
$this->host = $host;
return $this;
}
/**
* @return string
*/
public function getHost() {
return $this->host;
}
/**
* set the user agent of the api client
*
* @param string $userAgent the user agent of the api client
* @return ApiClient
*/
public function setUserAgent($userAgent) {
if (!is_string($userAgent)) {
throw new \InvalidArgumentException('User-agent must be a string.');
/**
* @return Configuration
*/
public static function getDefaultConfiguration() {
if (self::$defaultConfiguration == null) {
return new Configuration();
}
return self::$defaultConfiguration;
}
$this->userAgent = $userAgent;
return $this;
}
/**
* get the user agent of the api client
*
* @return string user agent
*/
public function getUserAgent() {
return $this->userAgent;
}
/**
* set the HTTP timeout value
*
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
* @return ApiClient
*/
public function setCurlTimeout($seconds) {
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.');
/**
* @param Configuration $config
*/
public static function setDefaultConfiguration(Configuration $config) {
self::$defaultConfiguration = $config;
}
$this->curlTimeout = $seconds;
return $this;
}
/**
* get the HTTP timeout value
*
* @return string HTTP timeout value
*/
public function getCurlTimeout() {
return $this->curlTimeout;
}
/**
* @param bool $debug
* @return Configuration
*/
public function setDebug($debug) {
$this->debug = $debug;
return $this;
}
/**
* @return bool
*/
public function getDebug() {
return $this->debug;
}
/**
* @param string $debugFile
* @return Configuration
*/
public function setDebugFile($debugFile) {
$this->debugFile = $debugFile;
return $this;
}
/**
* @return string
*/
public function getDebugFile() {
return $this->debugFile;
}
/**
* @return Configuration
*/
public static function getDefaultConfiguration() {
if (self::$defaultConfiguration == null) {
return new Configuration();
/*
* return the report for debugging
*/
public static function toDebugReport() {
$report = "PHP SDK (Swagger\Client) Debug Report:\n";
$report .= " OS: ".php_uname()."\n";
$report .= " PHP Version: ".phpversion()."\n";
$report .= " Swagger Spec Version: 1.0.0\n";
$report .= " SDK Package Version: 1.0.0\n";
return $report;
}
return self::$defaultConfiguration;
}
public static function setDefaultConfiguration(Configuration $config) {
self::$defaultConfiguration = $config;
}
/*
* return the report for debuggin
*/
public static function toDebugReport() {
$report = "PHP SDK (Swagger\Client) Debug Report:\n";
$report .= " OS: ".php_uname()."\n";
$report .= " PHP Version: ".phpversion()."\n";
$report .= " Swagger Spec Version: 1.0.0\n";
$report .= " SDK Package Version: 1.0.0\n";
return $report;
}
}

View File

@ -27,101 +27,101 @@ namespace Swagger\Client\Model;
use \ArrayAccess;
class Category implements ArrayAccess {
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'name' => 'string'
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'name' => 'name'
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'name' => 'setName'
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'name' => 'getName'
);
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'name' => 'string'
);
/** @var int $id */
protected $id;
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'name' => 'name'
);
/** @var string $name */
protected $name;
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'name' => 'setName'
);
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->name = $data["name"];
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'name' => 'getName'
);
/** @var int $id */
protected $id;
/** @var string $name */
protected $name;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->name = $data["name"];
}
}
}
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* set name
* @param string $name
* @return $this
*/
public function setName($name) {
$this->name = $name;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* set name
* @param string $name
* @return $this
*/
public function setName($name) {
$this->name = $name;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
}
}
}
}

View File

@ -27,205 +27,205 @@ namespace Swagger\Client\Model;
use \ArrayAccess;
class Order implements ArrayAccess {
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'pet_id' => 'int',
'quantity' => 'int',
'ship_date' => '\DateTime',
'status' => 'string',
'complete' => 'bool'
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'pet_id' => 'petId',
'quantity' => 'quantity',
'ship_date' => 'shipDate',
'status' => 'status',
'complete' => 'complete'
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'pet_id' => 'setPetId',
'quantity' => 'setQuantity',
'ship_date' => 'setShipDate',
'status' => 'setStatus',
'complete' => 'setComplete'
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'pet_id' => 'getPetId',
'quantity' => 'getQuantity',
'ship_date' => 'getShipDate',
'status' => 'getStatus',
'complete' => 'getComplete'
);
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'pet_id' => 'int',
'quantity' => 'int',
'ship_date' => '\DateTime',
'status' => 'string',
'complete' => 'bool'
);
/** @var int $id */
protected $id;
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'pet_id' => 'petId',
'quantity' => 'quantity',
'ship_date' => 'shipDate',
'status' => 'status',
'complete' => 'complete'
);
/** @var int $pet_id */
protected $pet_id;
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'pet_id' => 'setPetId',
'quantity' => 'setQuantity',
'ship_date' => 'setShipDate',
'status' => 'setStatus',
'complete' => 'setComplete'
);
/** @var int $quantity */
protected $quantity;
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'pet_id' => 'getPetId',
'quantity' => 'getQuantity',
'ship_date' => 'getShipDate',
'status' => 'getStatus',
'complete' => 'getComplete'
);
/** @var \DateTime $ship_date */
protected $ship_date;
/** @var string $status Order Status */
protected $status;
/** @var bool $complete */
protected $complete;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->pet_id = $data["pet_id"];
$this->quantity = $data["quantity"];
$this->ship_date = $data["ship_date"];
$this->status = $data["status"];
$this->complete = $data["complete"];
/** @var int $id */
protected $id;
/** @var int $pet_id */
protected $pet_id;
/** @var int $quantity */
protected $quantity;
/** @var \DateTime $ship_date */
protected $ship_date;
/** @var string $status Order Status */
protected $status;
/** @var bool $complete */
protected $complete;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->pet_id = $data["pet_id"];
$this->quantity = $data["quantity"];
$this->ship_date = $data["ship_date"];
$this->status = $data["status"];
$this->complete = $data["complete"];
}
}
}
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get pet_id
* @return int
*/
public function getPetId() {
return $this->pet_id;
}
/**
* set pet_id
* @param int $pet_id
* @return $this
*/
public function setPetId($pet_id) {
$this->pet_id = $pet_id;
return $this;
}
/**
* get quantity
* @return int
*/
public function getQuantity() {
return $this->quantity;
}
/**
* set quantity
* @param int $quantity
* @return $this
*/
public function setQuantity($quantity) {
$this->quantity = $quantity;
return $this;
}
/**
* get ship_date
* @return \DateTime
*/
public function getShipDate() {
return $this->ship_date;
}
/**
* set ship_date
* @param \DateTime $ship_date
* @return $this
*/
public function setShipDate($ship_date) {
$this->ship_date = $ship_date;
return $this;
}
/**
* get status
* @return string
*/
public function getStatus() {
return $this->status;
}
/**
* set status
* @param string $status
* @return $this
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
/**
* get complete
* @return bool
*/
public function getComplete() {
return $this->complete;
}
/**
* set complete
* @param bool $complete
* @return $this
*/
public function setComplete($complete) {
$this->complete = $complete;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get pet_id
* @return int
*/
public function getPetId() {
return $this->pet_id;
}
/**
* set pet_id
* @param int $pet_id
* @return $this
*/
public function setPetId($pet_id) {
$this->pet_id = $pet_id;
return $this;
}
/**
* get quantity
* @return int
*/
public function getQuantity() {
return $this->quantity;
}
/**
* set quantity
* @param int $quantity
* @return $this
*/
public function setQuantity($quantity) {
$this->quantity = $quantity;
return $this;
}
/**
* get ship_date
* @return \DateTime
*/
public function getShipDate() {
return $this->ship_date;
}
/**
* set ship_date
* @param \DateTime $ship_date
* @return $this
*/
public function setShipDate($ship_date) {
$this->ship_date = $ship_date;
return $this;
}
/**
* get status
* @return string
*/
public function getStatus() {
return $this->status;
}
/**
* set status
* @param string $status
* @return $this
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
/**
* get complete
* @return bool
*/
public function getComplete() {
return $this->complete;
}
/**
* set complete
* @param bool $complete
* @return $this
*/
public function setComplete($complete) {
$this->complete = $complete;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
}
}
}
}

View File

@ -27,205 +27,205 @@ namespace Swagger\Client\Model;
use \ArrayAccess;
class Pet implements ArrayAccess {
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'category' => '\Swagger\Client\Model\Category',
'name' => 'string',
'photo_urls' => 'string[]',
'tags' => '\Swagger\Client\Model\Tag[]',
'status' => 'string'
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'category' => 'category',
'name' => 'name',
'photo_urls' => 'photoUrls',
'tags' => 'tags',
'status' => 'status'
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'category' => 'setCategory',
'name' => 'setName',
'photo_urls' => 'setPhotoUrls',
'tags' => 'setTags',
'status' => 'setStatus'
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'category' => 'getCategory',
'name' => 'getName',
'photo_urls' => 'getPhotoUrls',
'tags' => 'getTags',
'status' => 'getStatus'
);
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'category' => '\Swagger\Client\Model\Category',
'name' => 'string',
'photo_urls' => 'string[]',
'tags' => '\Swagger\Client\Model\Tag[]',
'status' => 'string'
);
/** @var int $id */
protected $id;
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'category' => 'category',
'name' => 'name',
'photo_urls' => 'photoUrls',
'tags' => 'tags',
'status' => 'status'
);
/** @var \Swagger\Client\Model\Category $category */
protected $category;
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'category' => 'setCategory',
'name' => 'setName',
'photo_urls' => 'setPhotoUrls',
'tags' => 'setTags',
'status' => 'setStatus'
);
/** @var string $name */
protected $name;
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'category' => 'getCategory',
'name' => 'getName',
'photo_urls' => 'getPhotoUrls',
'tags' => 'getTags',
'status' => 'getStatus'
);
/** @var string[] $photo_urls */
protected $photo_urls;
/** @var \Swagger\Client\Model\Tag[] $tags */
protected $tags;
/** @var string $status pet status in the store */
protected $status;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->category = $data["category"];
$this->name = $data["name"];
$this->photo_urls = $data["photo_urls"];
$this->tags = $data["tags"];
$this->status = $data["status"];
/** @var int $id */
protected $id;
/** @var \Swagger\Client\Model\Category $category */
protected $category;
/** @var string $name */
protected $name;
/** @var string[] $photo_urls */
protected $photo_urls;
/** @var \Swagger\Client\Model\Tag[] $tags */
protected $tags;
/** @var string $status pet status in the store */
protected $status;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->category = $data["category"];
$this->name = $data["name"];
$this->photo_urls = $data["photo_urls"];
$this->tags = $data["tags"];
$this->status = $data["status"];
}
}
}
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get category
* @return \Swagger\Client\Model\Category
*/
public function getCategory() {
return $this->category;
}
/**
* set category
* @param \Swagger\Client\Model\Category $category
* @return $this
*/
public function setCategory($category) {
$this->category = $category;
return $this;
}
/**
* get name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* set name
* @param string $name
* @return $this
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
* get photo_urls
* @return string[]
*/
public function getPhotoUrls() {
return $this->photo_urls;
}
/**
* set photo_urls
* @param string[] $photo_urls
* @return $this
*/
public function setPhotoUrls($photo_urls) {
$this->photo_urls = $photo_urls;
return $this;
}
/**
* get tags
* @return \Swagger\Client\Model\Tag[]
*/
public function getTags() {
return $this->tags;
}
/**
* set tags
* @param \Swagger\Client\Model\Tag[] $tags
* @return $this
*/
public function setTags($tags) {
$this->tags = $tags;
return $this;
}
/**
* get status
* @return string
*/
public function getStatus() {
return $this->status;
}
/**
* set status
* @param string $status
* @return $this
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get category
* @return \Swagger\Client\Model\Category
*/
public function getCategory() {
return $this->category;
}
/**
* set category
* @param \Swagger\Client\Model\Category $category
* @return $this
*/
public function setCategory($category) {
$this->category = $category;
return $this;
}
/**
* get name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* set name
* @param string $name
* @return $this
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
* get photo_urls
* @return string[]
*/
public function getPhotoUrls() {
return $this->photo_urls;
}
/**
* set photo_urls
* @param string[] $photo_urls
* @return $this
*/
public function setPhotoUrls($photo_urls) {
$this->photo_urls = $photo_urls;
return $this;
}
/**
* get tags
* @return \Swagger\Client\Model\Tag[]
*/
public function getTags() {
return $this->tags;
}
/**
* set tags
* @param \Swagger\Client\Model\Tag[] $tags
* @return $this
*/
public function setTags($tags) {
$this->tags = $tags;
return $this;
}
/**
* get status
* @return string
*/
public function getStatus() {
return $this->status;
}
/**
* set status
* @param string $status
* @return $this
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
}
}
}
}

View File

@ -27,101 +27,101 @@ namespace Swagger\Client\Model;
use \ArrayAccess;
class Tag implements ArrayAccess {
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'name' => 'string'
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'name' => 'name'
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'name' => 'setName'
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'name' => 'getName'
);
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'name' => 'string'
);
/** @var int $id */
protected $id;
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'name' => 'name'
);
/** @var string $name */
protected $name;
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'name' => 'setName'
);
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->name = $data["name"];
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'name' => 'getName'
);
/** @var int $id */
protected $id;
/** @var string $name */
protected $name;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->name = $data["name"];
}
}
}
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* set name
* @param string $name
* @return $this
*/
public function setName($name) {
$this->name = $name;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get name
* @return string
*/
public function getName() {
return $this->name;
}
/**
* set name
* @param string $name
* @return $this
*/
public function setName($name) {
$this->name = $name;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
}
}
}
}

View File

@ -27,257 +27,257 @@ namespace Swagger\Client\Model;
use \ArrayAccess;
class User implements ArrayAccess {
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'username' => 'string',
'first_name' => 'string',
'last_name' => 'string',
'email' => 'string',
'password' => 'string',
'phone' => 'string',
'user_status' => 'int'
);
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'username' => 'username',
'first_name' => 'firstName',
'last_name' => 'lastName',
'email' => 'email',
'password' => 'password',
'phone' => 'phone',
'user_status' => 'userStatus'
);
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'username' => 'setUsername',
'first_name' => 'setFirstName',
'last_name' => 'setLastName',
'email' => 'setEmail',
'password' => 'setPassword',
'phone' => 'setPhone',
'user_status' => 'setUserStatus'
);
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'username' => 'getUsername',
'first_name' => 'getFirstName',
'last_name' => 'getLastName',
'email' => 'getEmail',
'password' => 'getPassword',
'phone' => 'getPhone',
'user_status' => 'getUserStatus'
);
/** @var string[] Array of property to type mappings. Used for (de)serialization */
static $swaggerTypes = array(
'id' => 'int',
'username' => 'string',
'first_name' => 'string',
'last_name' => 'string',
'email' => 'string',
'password' => 'string',
'phone' => 'string',
'user_status' => 'int'
);
/** @var int $id */
protected $id;
/** @var string[] Array of attributes where the key is the local name, and the value is the original name */
static $attributeMap = array(
'id' => 'id',
'username' => 'username',
'first_name' => 'firstName',
'last_name' => 'lastName',
'email' => 'email',
'password' => 'password',
'phone' => 'phone',
'user_status' => 'userStatus'
);
/** @var string $username */
protected $username;
/** @var string[] Array of attributes to setter functions (for deserialization of responses) */
static $setters = array(
'id' => 'setId',
'username' => 'setUsername',
'first_name' => 'setFirstName',
'last_name' => 'setLastName',
'email' => 'setEmail',
'password' => 'setPassword',
'phone' => 'setPhone',
'user_status' => 'setUserStatus'
);
/** @var string $first_name */
protected $first_name;
/** @var string[] Array of attributes to getter functions (for serialization of requests) */
static $getters = array(
'id' => 'getId',
'username' => 'getUsername',
'first_name' => 'getFirstName',
'last_name' => 'getLastName',
'email' => 'getEmail',
'password' => 'getPassword',
'phone' => 'getPhone',
'user_status' => 'getUserStatus'
);
/** @var string $last_name */
protected $last_name;
/** @var string $email */
protected $email;
/** @var string $password */
protected $password;
/** @var string $phone */
protected $phone;
/** @var int $user_status User Status */
protected $user_status;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->username = $data["username"];
$this->first_name = $data["first_name"];
$this->last_name = $data["last_name"];
$this->email = $data["email"];
$this->password = $data["password"];
$this->phone = $data["phone"];
$this->user_status = $data["user_status"];
/** @var int $id */
protected $id;
/** @var string $username */
protected $username;
/** @var string $first_name */
protected $first_name;
/** @var string $last_name */
protected $last_name;
/** @var string $email */
protected $email;
/** @var string $password */
protected $password;
/** @var string $phone */
protected $phone;
/** @var int $user_status User Status */
protected $user_status;
public function __construct(array $data = null) {
if ($data != null) {
$this->id = $data["id"];
$this->username = $data["username"];
$this->first_name = $data["first_name"];
$this->last_name = $data["last_name"];
$this->email = $data["email"];
$this->password = $data["password"];
$this->phone = $data["phone"];
$this->user_status = $data["user_status"];
}
}
}
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get username
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* set username
* @param string $username
* @return $this
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* get first_name
* @return string
*/
public function getFirstName() {
return $this->first_name;
}
/**
* set first_name
* @param string $first_name
* @return $this
*/
public function setFirstName($first_name) {
$this->first_name = $first_name;
return $this;
}
/**
* get last_name
* @return string
*/
public function getLastName() {
return $this->last_name;
}
/**
* set last_name
* @param string $last_name
* @return $this
*/
public function setLastName($last_name) {
$this->last_name = $last_name;
return $this;
}
/**
* get email
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* set email
* @param string $email
* @return $this
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
/**
* get password
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* set password
* @param string $password
* @return $this
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* get phone
* @return string
*/
public function getPhone() {
return $this->phone;
}
/**
* set phone
* @param string $phone
* @return $this
*/
public function setPhone($phone) {
$this->phone = $phone;
return $this;
}
/**
* get user_status
* @return int
*/
public function getUserStatus() {
return $this->user_status;
}
/**
* set user_status
* @param int $user_status
* @return $this
*/
public function setUserStatus($user_status) {
$this->user_status = $user_status;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
/**
* get id
* @return int
*/
public function getId() {
return $this->id;
}
/**
* set id
* @param int $id
* @return $this
*/
public function setId($id) {
$this->id = $id;
return $this;
}
/**
* get username
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* set username
* @param string $username
* @return $this
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* get first_name
* @return string
*/
public function getFirstName() {
return $this->first_name;
}
/**
* set first_name
* @param string $first_name
* @return $this
*/
public function setFirstName($first_name) {
$this->first_name = $first_name;
return $this;
}
/**
* get last_name
* @return string
*/
public function getLastName() {
return $this->last_name;
}
/**
* set last_name
* @param string $last_name
* @return $this
*/
public function setLastName($last_name) {
$this->last_name = $last_name;
return $this;
}
/**
* get email
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* set email
* @param string $email
* @return $this
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
/**
* get password
* @return string
*/
public function getPassword() {
return $this->password;
}
/**
* set password
* @param string $password
* @return $this
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* get phone
* @return string
*/
public function getPhone() {
return $this->phone;
}
/**
* set phone
* @param string $phone
* @return $this
*/
public function setPhone($phone) {
$this->phone = $phone;
return $this;
}
/**
* get user_status
* @return int
*/
public function getUserStatus() {
return $this->user_status;
}
/**
* set user_status
* @param int $user_status
* @return $this
*/
public function setUserStatus($user_status) {
$this->user_status = $user_status;
return $this;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset, $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
return json_encode(get_object_vars($this));
}
}
}
}

View File

@ -9,29 +9,29 @@ class ObjectSerializer {
* @return string serialized form of $data
*/
public function sanitizeForSerialization($data) {
if (is_scalar($data) || null === $data) {
$sanitized = $data;
} else if ($data instanceof \DateTime) {
$sanitized = $data->format(\DateTime::ISO8601);
} else if (is_array($data)) {
foreach ($data as $property => $value) {
$data[$property] = $this->sanitizeForSerialization($value);
if (is_scalar($data) || null === $data) {
$sanitized = $data;
} else if ($data instanceof \DateTime) {
$sanitized = $data->format(\DateTime::ISO8601);
} else if (is_array($data)) {
foreach ($data as $property => $value) {
$data[$property] = $this->sanitizeForSerialization($value);
}
$sanitized = $data;
} else if (is_object($data)) {
$values = array();
foreach (array_keys($data::$swaggerTypes) as $property) {
$getter = $data::$getters[$property];
if ($data->$getter() !== null) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter());
}
}
$sanitized = $values;
} else {
$sanitized = (string)$data;
}
$sanitized = $data;
} else if (is_object($data)) {
$values = array();
foreach (array_keys($data::$swaggerTypes) as $property) {
$getter = $data::$getters[$property];
if ($data->$getter() !== null) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter());
}
}
$sanitized = $values;
} else {
$sanitized = (string)$data;
}
return $sanitized;
return $sanitized;
}
/**
@ -41,7 +41,7 @@ class ObjectSerializer {
* @return string the serialized object
*/
public function toPathValue($value) {
return rawurlencode($this->toString($value));
return rawurlencode($this->toString($value));
}
/**
@ -53,11 +53,11 @@ class ObjectSerializer {
* @return string the serialized object
*/
public function toQueryValue($object) {
if (is_array($object)) {
return implode(',', $object);
} else {
return $this->toString($object);
}
if (is_array($object)) {
return implode(',', $object);
} else {
return $this->toString($object);
}
}
/**
@ -68,7 +68,7 @@ class ObjectSerializer {
* @return string the header string
*/
public function toHeaderValue($value) {
return $this->toString($value);
return $this->toString($value);
}
/**
@ -79,11 +79,11 @@ class ObjectSerializer {
* @return string the form string
*/
public function toFormValue($value) {
if ($value instanceof SplFileObject) {
return $value->getRealPath();
} else {
return $this->toString($value);
}
if ($value instanceof SplFileObject) {
return $value->getRealPath();
} else {
return $this->toString($value);
}
}
/**
@ -94,11 +94,11 @@ class ObjectSerializer {
* @return string the header string
*/
public function toString($value) {
if ($value instanceof \DateTime) { // datetime in ISO8601 format
return $value->format(\DateTime::ISO8601);
} else {
return $value;
}
if ($value instanceof \DateTime) { // datetime in ISO8601 format
return $value->format(\DateTime::ISO8601);
} else {
return $value;
}
}
/**
@ -109,65 +109,63 @@ class ObjectSerializer {
* @return object an instance of $class
*/
public function deserialize($data, $class, $httpHeader=null) {
if (null === $data) {
$deserialized = null;
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
$inner = substr($class, 4, -1);
$deserialized = array();
if(strrpos($inner, ",") !== false) {
$subClass_array = explode(',', $inner, 2);
$subClass = $subClass_array[1];
foreach ($data as $key => $value) {
$deserialized[$key] = $this->deserialize($value, $subClass);
}
if (null === $data) {
$deserialized = null;
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
$inner = substr($class, 4, -1);
$deserialized = array();
if(strrpos($inner, ",") !== false) {
$subClass_array = explode(',', $inner, 2);
$subClass = $subClass_array[1];
foreach ($data as $key => $value) {
$deserialized[$key] = $this->deserialize($value, $subClass);
}
}
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
$subClass = substr($class, 0, -2);
$values = array();
foreach ($data as $key => $value) {
$values[] = $this->deserialize($value, $subClass);
}
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} elseif ($class === '\SplFileObject') {
# determine temp folder path
$tmpFolderPath = Configuration::getDefaultConfiguration()->getTempFolderPath();
print_r($tmpFolderPath);
# determine file name
if (preg_match('/Content-Disposition: inline; filename=(.*)$/i', $httpHeader, $match)) {
$filename = $tmpFolderPath.$match[1];
} else {
print_r($tmpFolderPath);
$filename = tempnam($tmpFolderPath, '');
}
$deserialized = new \SplFileObject($filename, "w");
$byte_written = $deserialized->fwrite($data);
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile());
} else {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
$propertySetter = $instance::$setters[$property];
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
continue;
}
$propertyValue = $data->{$instance::$attributeMap[$property]};
if (isset($propertyValue)) {
$instance->$propertySetter($this->deserialize($propertyValue, $type));
}
}
$deserialized = $instance;
}
} elseif (strcasecmp(substr($class, -2),'[]') == 0) {
$subClass = substr($class, 0, -2);
$values = array();
foreach ($data as $key => $value) {
$values[] = $this->deserialize($value, $subClass);
}
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} elseif ($class === '\SplFileObject') {
# determine temp folder path
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
$tmpFolderPath = sys_get_temp_dir();
} else {
$tmpFolderPath = Configuration::tempFolderPath;
}
# determine file name
if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) {
$filename = $tmpFolderPath.$match[1];
} else {
$filename = tempnam($tmpFolderPath, '');
}
$deserialized = new \SplFileObject($filename, "w");
$byte_written = $deserialized->fwrite($data);
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile());
} else {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
$propertySetter = $instance::$setters[$property];
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
continue;
}
$propertyValue = $data->{$instance::$attributeMap[$property]};
if (isset($propertyValue)) {
$instance->$propertySetter($this->deserialize($propertyValue, $type));
}
}
$deserialized = $instance;
}
return $deserialized;
return $deserialized;
}
}

View File

@ -12,12 +12,15 @@ require_once(__DIR__ . '/SwaggerClient-php/autoload.php');
// to enable logging
//SwaggerClient\Configuration::$debug = true;
//SwaggerClient\Configuration::$debug_file = '/var/tmp/php_debug.log';
Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/');
$petId = 10005; // ID of pet that needs to be fetched
try {
// get pet by id
//$pet_api = new SwaggerClient\PetAPI($api_client);
$pet_api = new Swagger\Client\Api\PetAPI();
$pet_api->getApiClient()->getConfig()->setTempFolderPath('/var/tmp/php/');
print_r($pet_api->getApiClient()->getConfig()->getTempFolderPath());
// test default header
//$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
// return Pet (model)