forked from loafle/openapi-generator-original
update coding style based on CodeSniffer
This commit is contained in:
@@ -1,14 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* ObjectSerializer
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2015 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
class ObjectSerializer {
|
||||
/**
|
||||
* ObjectSerializer Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @package {{invokerPackage}}
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class ObjectSerializer
|
||||
{
|
||||
|
||||
/**
|
||||
* Build a JSON POST object
|
||||
*
|
||||
* @param mixed $data the data to serialize
|
||||
*
|
||||
* @return string serialized form of $data
|
||||
*/
|
||||
public function sanitizeForSerialization($data) {
|
||||
public function sanitizeForSerialization($data)
|
||||
{
|
||||
if (is_scalar($data) || null === $data) {
|
||||
$sanitized = $data;
|
||||
} else if ($data instanceof \DateTime) {
|
||||
@@ -37,10 +82,13 @@ class ObjectSerializer {
|
||||
/**
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the path, by url-encoding.
|
||||
*
|
||||
* @param string $value a string which will be part of the path
|
||||
*
|
||||
* @return string the serialized object
|
||||
*/
|
||||
public function toPathValue($value) {
|
||||
public function toPathValue($value)
|
||||
{
|
||||
return rawurlencode($this->toString($value));
|
||||
}
|
||||
|
||||
@@ -49,10 +97,13 @@ class ObjectSerializer {
|
||||
* the query, by imploding comma-separated if it's an object.
|
||||
* If it's a string, pass through unchanged. It will be url-encoded
|
||||
* later.
|
||||
*
|
||||
* @param object $object an object to be serialized to a string
|
||||
*
|
||||
* @return string the serialized object
|
||||
*/
|
||||
public function toQueryValue($object) {
|
||||
public function toQueryValue($object)
|
||||
{
|
||||
if (is_array($object)) {
|
||||
return implode(',', $object);
|
||||
} else {
|
||||
@@ -64,10 +115,13 @@ class ObjectSerializer {
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the header. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string $value a string which will be part of the header
|
||||
*
|
||||
* @return string the header string
|
||||
*/
|
||||
public function toHeaderValue($value) {
|
||||
public function toHeaderValue($value)
|
||||
{
|
||||
return $this->toString($value);
|
||||
}
|
||||
|
||||
@@ -75,10 +129,13 @@ class ObjectSerializer {
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the http body (form parameter). If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string $value the value of the form parameter
|
||||
*
|
||||
* @return string the form string
|
||||
*/
|
||||
public function toFormValue($value) {
|
||||
public function toFormValue($value)
|
||||
{
|
||||
if ($value instanceof SplFileObject) {
|
||||
return $value->getRealPath();
|
||||
} else {
|
||||
@@ -90,10 +147,13 @@ class ObjectSerializer {
|
||||
* Take value and turn it into a string suitable for inclusion in
|
||||
* the parameter. If it's a string, pass through unchanged
|
||||
* If it's a datetime object, format it in ISO8601
|
||||
*
|
||||
* @param string $value the value of the parameter
|
||||
*
|
||||
* @return string the header string
|
||||
*/
|
||||
public function toString($value) {
|
||||
public function toString($value)
|
||||
{
|
||||
if ($value instanceof \DateTime) { // datetime in ISO8601 format
|
||||
return $value->format(\DateTime::ISO8601);
|
||||
} else {
|
||||
@@ -104,37 +164,40 @@ class ObjectSerializer {
|
||||
/**
|
||||
* Deserialize a JSON string into an object
|
||||
*
|
||||
* @param mixed $data object or primitive to be deserialized
|
||||
* @param string $class class name is passed as a string
|
||||
* @param mixed $data object or primitive to be deserialized
|
||||
* @param string $class class name is passed as a string
|
||||
* @param string $httpHeader HTTP headers
|
||||
*
|
||||
* @return object an instance of $class
|
||||
*/
|
||||
public function deserialize($data, $class, $httpHeader=null) {
|
||||
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]
|
||||
} 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) {
|
||||
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) {
|
||||
} 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') {
|
||||
} 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 file name
|
||||
// determine file name
|
||||
if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) {
|
||||
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1];
|
||||
} else {
|
||||
@@ -142,7 +205,7 @@ class ObjectSerializer {
|
||||
}
|
||||
$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 after processing.\n" , 3, Configuration::getDefaultConfiguration()->getDebugFile());
|
||||
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n", 3, Configuration::getDefaultConfiguration()->getDebugFile());
|
||||
|
||||
} else {
|
||||
$instance = new $class();
|
||||
@@ -150,7 +213,7 @@ class ObjectSerializer {
|
||||
$propertySetter = $instance::$setters[$property];
|
||||
|
||||
if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
$propertyValue = $data->{$instance::$attributeMap[$property]};
|
||||
|
||||
Reference in New Issue
Block a user