diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
index e2ddba4bf3..c6e6d65596 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
@@ -79,7 +79,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("boolean", "bool");
typeMapping.put("date", "\\DateTime");
typeMapping.put("datetime", "\\DateTime");
- typeMapping.put("file", "string");
+ typeMapping.put("file", "\\SplFileObject");
typeMapping.put("map", "map");
typeMapping.put("array", "array");
typeMapping.put("list", "array");
diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache
index 2862a0e053..3a4f8dfc8b 100644
--- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache
+++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache
@@ -90,7 +90,7 @@ class ApiClient {
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
* @return mixed
*/
- public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) {
+ public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
$headers = array();
@@ -174,6 +174,11 @@ class ApiClient {
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;
diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache
index 56a61e97c9..26999668b9 100644
--- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache
+++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache
@@ -79,7 +79,11 @@ class ObjectSerializer {
* @return string the form string
*/
public function toFormValue($value) {
- return $this->toString($value);
+ if ($value instanceof SplFileObject) {
+ return $value->getRealPath();
+ } else {
+ return $this->toString($value);
+ }
}
/**
@@ -104,7 +108,7 @@ class ObjectSerializer {
* @param string $class class name is passed as a string
* @return object an instance of $class
*/
- public function deserialize($data, $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]
@@ -129,6 +133,24 @@ class ObjectSerializer {
} 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 to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file);
+
} else {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
@@ -148,4 +170,4 @@ class ObjectSerializer {
return $deserialized;
}
-}
\ No newline at end of file
+}
diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache
index fb0a6f99e7..367ba037d5 100644
--- a/modules/swagger-codegen/src/main/resources/php/api.mustache
+++ b/modules/swagger-codegen/src/main/resources/php/api.mustache
@@ -134,13 +134,13 @@ class {{classname}} {
{{/authMethods}}
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
} catch (ApiException $e) {
switch ($e->getCode()) { {{#responses}}{{#dataType}}
case {{code}}:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader);
$e->setResponseObject($data);
break;{{/dataType}}{{/responses}}
}
diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache
index b85ad28941..6874706697 100644
--- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache
+++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache
@@ -263,4 +263,18 @@ class Configuration {
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;
+ }
+
}
diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache
index 35795bf8c0..1d24152953 100644
--- a/modules/swagger-codegen/src/main/resources/php/model.mustache
+++ b/modules/swagger-codegen/src/main/resources/php/model.mustache
@@ -100,9 +100,9 @@ class {{classname}} implements ArrayAccess {
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
- return json_encode($this, JSON_PRETTY_PRINT);
+ return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
- return json_encode($this);
+ return json_encode(get_object_vars($this));
}
}
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php
index b6766d8d13..afbe199169 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php
@@ -110,7 +110,7 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -171,7 +171,7 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -231,13 +231,13 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, '\Swagger\Client\Model\Pet[]');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -302,13 +302,13 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, '\Swagger\Client\Model\Pet[]');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -375,9 +375,6 @@ class PetApi {
$httpBody = $formParams;
}
- //TODO support oauth
-
-
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
if (isset($apiKey)) {
$headerParams['api_key'] = $apiKey;
@@ -385,15 +382,18 @@ class PetApi {
+
+ //TODO support oauth
+
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, '\Swagger\Client\Model\Pet');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -473,7 +473,7 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -544,7 +544,7 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -563,7 +563,7 @@ class PetApi {
*
* @param int $pet_id ID of pet to update (required)
* @param string $additional_metadata Additional data to pass to server (required)
- * @param string $file file to upload (required)
+ * @param \SplFileObject $file file to upload (required)
* @return void
* @throws \Swagger\Client\ApiException on non-2xx response
*/
@@ -619,7 +619,7 @@ class PetApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php
index 237ba3f1ac..5c9d38a8b5 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php
@@ -109,13 +109,13 @@ class StoreApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, 'map[string,int]');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -178,13 +178,13 @@ class StoreApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, '\Swagger\Client\Model\Order');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -253,13 +253,13 @@ class StoreApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, '\Swagger\Client\Model\Order');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -328,7 +328,7 @@ class StoreApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php
index 1d0765bbb8..a95d93bb55 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php
@@ -107,7 +107,7 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -165,7 +165,7 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -223,7 +223,7 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -284,13 +284,13 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, 'string');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -348,7 +348,7 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -412,13 +412,13 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
- $headerParams);
+ $headerParams, '\Swagger\Client\Model\User');
} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
- $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User');
+ $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader);
$e->setResponseObject($data);
break;
}
@@ -492,7 +492,7 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
@@ -556,7 +556,7 @@ class UserApi {
// make the API Call
try {
- $response = $this->apiClient->callAPI($resourcePath, $method,
+ $response = $this->apiClient->callApi($resourcePath, $method,
$queryParams, $httpBody,
$headerParams);
} catch (ApiException $e) {
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php
index 66204f0c4f..92d8c2aa11 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php
@@ -90,7 +90,7 @@ class ApiClient {
* @throws \Swagger\Client\ApiException on a non 2xx response
* @return mixed
*/
- public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) {
+ public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
$headers = array();
@@ -174,6 +174,11 @@ class ApiClient {
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;
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php
index a407fe4dd4..f4ccef391e 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php
@@ -263,4 +263,18 @@ class Configuration {
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;
+ }
+
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php
index 75aaf2eeea..9995dccdd4 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php
@@ -119,9 +119,9 @@ class Category implements ArrayAccess {
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
- return json_encode($this, JSON_PRETTY_PRINT);
+ return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
- return json_encode($this);
+ return json_encode(get_object_vars($this));
}
}
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php
index c7a433c3d8..2e0386d0ed 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php
@@ -223,9 +223,9 @@ class Order implements ArrayAccess {
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
- return json_encode($this, JSON_PRETTY_PRINT);
+ return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
- return json_encode($this);
+ return json_encode(get_object_vars($this));
}
}
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php
index cbe27e1fce..a7b259a2fb 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php
@@ -223,9 +223,9 @@ class Pet implements ArrayAccess {
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
- return json_encode($this, JSON_PRETTY_PRINT);
+ return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
- return json_encode($this);
+ return json_encode(get_object_vars($this));
}
}
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php
index 3fd785f001..6e8ae3e27a 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php
@@ -119,9 +119,9 @@ class Tag implements ArrayAccess {
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
- return json_encode($this, JSON_PRETTY_PRINT);
+ return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
- return json_encode($this);
+ return json_encode(get_object_vars($this));
}
}
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php
index 2bb31056bd..b1e2d2b809 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php
@@ -275,9 +275,9 @@ class User implements ArrayAccess {
public function __toString() {
if (defined('JSON_PRETTY_PRINT')) {
- return json_encode($this, JSON_PRETTY_PRINT);
+ return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
} else {
- return json_encode($this);
+ return json_encode(get_object_vars($this));
}
}
}
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php
index 802a49bc01..d002b33685 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php
@@ -79,7 +79,11 @@ class ObjectSerializer {
* @return string the form string
*/
public function toFormValue($value) {
- return $this->toString($value);
+ if ($value instanceof SplFileObject) {
+ return $value->getRealPath();
+ } else {
+ return $this->toString($value);
+ }
}
/**
@@ -104,7 +108,7 @@ class ObjectSerializer {
* @param string $class class name is passed as a string
* @return object an instance of $class
*/
- public function deserialize($data, $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]
@@ -129,6 +133,24 @@ class ObjectSerializer {
} 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 to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file);
+
} else {
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
@@ -148,4 +170,4 @@ class ObjectSerializer {
return $deserialized;
}
-}
\ No newline at end of file
+}
diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon
deleted file mode 100644
index c067c2c290..0000000000
--- a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon
+++ /dev/null
@@ -1,5 +0,0 @@
-main: Contrib
-title: php-coveralls
-internal: yes
-todo: yes
-wipeout: yes
diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml
deleted file mode 100644
index 82a58e1b32..0000000000
--- a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
- The coding standard for standard PHP application
- */img/*
- */images/*
- */less/*
- */css/*
- */js/*
- *.html
- *.twig
- *.yml
- *.xml
- *.txt
- *.less
- *.css
- *.js
- *.jpg
- *.jpeg
- *.png
- *.gif
-
-
-
-
-
-
-
-
-
-
-
diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml
deleted file mode 100644
index 27d3193e74..0000000000
--- a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
- My custom rule set that checks my code...
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/travis/empty b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/travis/empty
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php
index f5383a9a4d..55aae557a2 100644
--- a/samples/client/petstore/php/test.php
+++ b/samples/client/petstore/php/test.php
@@ -19,7 +19,7 @@ try {
//$pet_api = new SwaggerClient\PetAPI($api_client);
$pet_api = new Swagger\Client\Api\PetAPI();
// test default header
- $pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
+ //$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
// return Pet (model)
$response = $pet_api->getPetById($petId);
// to test __toString()
@@ -28,26 +28,26 @@ try {
// add pet (post json)
$new_pet_id = 10005;
$new_pet = new Swagger\Client\Model\Pet;
- $new_pet->id = $new_pet_id;
- $new_pet->name = "PHP Unit Test";
+ $new_pet->setId($new_pet_id);
+ $new_pet->setName("PHP Unit Test");
// new tag
$tag= new Swagger\Client\Model\Tag;
- $tag->id = $new_pet_id; // use the same id as pet
+ $tag->setId($new_pet_id); // use the same id as pet
//$tag->name = "test php tag";
// new category
$category = new Swagger\Client\Model\Category;
- $category->id = 0; // use the same id as pet
+ $category->setId(10005); // use the same id as pet
//$category->name = "test php category";
- $new_pet->tags = array($tag);
- $new_pet->category = $category;
+ $new_pet->setTags(array($tag));
+ $new_pet->setCategory($category);
$pet_api = new Swagger\Client\Api\PetAPI();
// add a new pet (model)
$add_response = $pet_api->addPet($new_pet);
// test upload file (exception)
- $upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
+ //$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
} catch (Swagger\Client\Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";