diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index e89dd01d51e..9550de6d193 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -204,7 +204,7 @@ class ObjectSerializer * * @return object|array|null an single or an array of $class instances */ - public static function deserialize($data, $class, $httpHeaders = null, $discriminator = null) + public static function deserialize($data, $class, $httpHeaders = null) { if (null === $data) { return null; @@ -215,7 +215,7 @@ class ObjectSerializer $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { - $deserialized[$key] = self::deserialize($value, $subClass, null, $discriminator); + $deserialized[$key] = self::deserialize($value, $subClass, null); } } return $deserialized; @@ -223,7 +223,7 @@ class ObjectSerializer $subClass = substr($class, 0, -2); $values = []; foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass, null, $discriminator); + $values[] = self::deserialize($value, $subClass, null); } return $values; } elseif ($class === 'object') { @@ -261,6 +261,7 @@ class ObjectSerializer return $deserialized; } else { // If a discriminator is defined and points to a valid subclass, use it. + $discriminator = $class::DISCRIMINATOR; if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { $subclass = '\{{invokerPackage}}\Model\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { @@ -277,7 +278,7 @@ class ObjectSerializer $propertyValue = $data->{$instance::attributeMap()[$property]}; if (isset($propertyValue)) { - $instance->$propertySetter(self::deserialize($propertyValue, $type, null, $discriminator)); + $instance->$propertySetter(self::deserialize($propertyValue, $type, null)); } } return $instance; diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 2148d1ea9ad..1768ff7ac5e 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -284,7 +284,7 @@ use \{{invokerPackage}}\ObjectSerializer; ); {{#returnType}} - return [$this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader{{#discriminator}}, '{{discriminator}}'{{/discriminator}}), $statusCode, $httpHeader]; + return [$this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader]; {{/returnType}} {{^returnType}} return [null, $statusCode, $httpHeader]; diff --git a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache index 1e221b78377..f7ab60ad616 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache @@ -1,5 +1,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ArrayAccess { + const DISCRIMINATOR = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}}; + /** * The original name of the model. * @var string @@ -103,8 +105,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple {{#discriminator}} // Initialize discriminator property with the model name. - $discrimintor = array_search('{{discriminator}}', self::$attributeMap); - $this->container[$discrimintor] = static::$swaggerModelName; + $discriminator = array_search('{{discriminator}}', self::$attributeMap); + $this->container[$discriminator] = static::$swaggerModelName; {{/discriminator}} } @@ -370,4 +372,4 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this)); } -} \ No newline at end of file +} diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/.php_cs b/samples/client/petstore-security-test/php/SwaggerClient-php/.php_cs new file mode 100644 index 00000000000..6b8e23c818a --- /dev/null +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/.php_cs @@ -0,0 +1,18 @@ +level(Symfony\CS\FixerInterface::PSR2_LEVEL) + ->setUsingCache(true) + ->fixers( + [ + 'ordered_use', + 'phpdoc_order', + 'short_array_syntax', + 'strict', + 'strict_param' + ] + ) + ->finder( + Symfony\CS\Finder\DefaultFinder::create() + ->in(__DIR__) + ); diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/.travis.yml b/samples/client/petstore-security-test/php/SwaggerClient-php/.travis.yml index 3c97d942552..d77f3825f6f 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/.travis.yml +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/.travis.yml @@ -7,4 +7,4 @@ php: - 7.0 - hhvm before_install: "composer install" -script: "phpunit lib/Tests" +script: "vendor/bin/phpunit" diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/README.md b/samples/client/petstore-security-test/php/SwaggerClient-php/README.md index baa8eb42188..e25623732e0 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/README.md +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/README.md @@ -4,7 +4,6 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: - API version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r -- Build date: 2016-08-05T11:24:40.650+02:00 - Build package: class io.swagger.codegen.languages.PhpClientCodegen ## Requirements @@ -46,7 +45,7 @@ To run the unit tests: ``` composer install -./vendor/bin/phpunit lib/Tests +./vendor/bin/phpunit ``` ## Getting Started @@ -86,20 +85,20 @@ Class | Method | HTTP request | Description ## Documentation For Authorization +## api_key + +- **Type**: API key +- **API key parameter name**: api_key */ ' " =end -- \r\n \n \r +- **Location**: HTTP header + ## petstore_auth - **Type**: OAuth - **Flow**: implicit - **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog - **Scopes**: - - **write:pets**: modify pets in your account */ ' " =end -- \r\n \n \r - - **read:pets**: read your pets */ ' " =end -- \r\n \n \r - -## api_key - -- **Type**: API key -- **API key parameter name**: api_key */ ' " =end -- \r\n \n \r -- **Location**: HTTP header + - **write:pets**: modify pets in your account *_/ ' \" =end -- \\r\\n \\n \\r + - **read:pets**: read your pets *_/ ' \" =end -- \\r\\n \\n \\r ## Author diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/composer.json b/samples/client/petstore-security-test/php/SwaggerClient-php/composer.json index b9290bdacb9..78602f3be45 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/composer.json +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/composer.json @@ -8,7 +8,7 @@ "api" ], "homepage": "http://swagger.io", - "license": "Apache v2", + "license": "Apache-2.0", "authors": [ { "name": "Swagger and contributors", @@ -24,7 +24,8 @@ "require-dev": { "phpunit/phpunit": "~4.8", "satooshi/php-coveralls": "~1.0", - "squizlabs/php_codesniffer": "~2.6" + "squizlabs/php_codesniffer": "~2.6", + "friendsofphp/php-cs-fixer": "~1.12" }, "autoload": { "psr-4": { "Swagger\\Client\\" : "lib/" } diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php index 5ce09b9a7ec..d399e789de5 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -40,9 +40,9 @@ namespace Swagger\Client\Api; -use \Swagger\Client\Configuration; use \Swagger\Client\ApiClient; use \Swagger\Client\ApiException; +use \Swagger\Client\Configuration; use \Swagger\Client\ObjectSerializer; /** @@ -56,7 +56,6 @@ use \Swagger\Client\ObjectSerializer; */ class FakeApi { - /** * API Client * @@ -71,7 +70,7 @@ class FakeApi */ public function __construct(\Swagger\Client\ApiClient $apiClient = null) { - if ($apiClient == null) { + if ($apiClient === null) { $apiClient = new ApiClient(); $apiClient->getConfig()->setHost('https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'); } @@ -108,8 +107,8 @@ class FakeApi * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * * @param string $test_code_inject____end____rn_n_r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) - * @return void * @throws \Swagger\Client\ApiException on non-2xx response + * @return void */ public function testCodeInjectEndRnNR($test_code_inject____end____rn_n_r = null) { @@ -123,22 +122,22 @@ class FakeApi * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * * @param string $test_code_inject____end____rn_n_r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r (optional) - * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response + * @return array of null, HTTP status code, HTTP response headers (array of strings) */ public function testCodeInjectEndRnNRWithHttpInfo($test_code_inject____end____rn_n_r = null) { // parse inputs $resourcePath = "/fake"; $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', '*_/ \" =end --')); + $queryParams = []; + $headerParams = []; + $formParams = []; + $_header_accept = $this->apiClient->selectHeaderAccept(['application/json', '*_/ \" =end --']); if (!is_null($_header_accept)) { $headerParams['Accept'] = $_header_accept; } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','*_/ \" =end --')); + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json', '*_/ \" =end --']); // default format to json $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -166,7 +165,7 @@ class FakeApi '/fake' ); - return array(null, $statusCode, $httpHeader); + return [null, $statusCode, $httpHeader]; } catch (ApiException $e) { switch ($e->getCode()) { } @@ -174,5 +173,4 @@ class FakeApi throw $e; } } - } diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php index 5f774a834d3..c8d7f70fedb 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php @@ -52,7 +52,6 @@ namespace Swagger\Client; */ class ApiClient { - public static $PATCH = "PATCH"; public static $POST = "POST"; public static $GET = "GET"; @@ -82,7 +81,7 @@ class ApiClient */ public function __construct(\Swagger\Client\Configuration $config = null) { - if ($config == null) { + if ($config === null) { $config = Configuration::getDefaultConfiguration(); } @@ -151,8 +150,7 @@ class ApiClient */ public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null, $endpointPath = null) { - - $headers = array(); + $headers = []; // construct the http header $headerParams = array_merge( @@ -165,9 +163,9 @@ class ApiClient } // form data - if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { + if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers, true)) { $postData = http_build_query($postData); - } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model + } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers, true)) { // json model $postData = json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($postData)); } @@ -175,7 +173,7 @@ class ApiClient $curl = curl_init(); // set timeout, if needed - if ($this->config->getCurlTimeout() != 0) { + if ($this->config->getCurlTimeout() !== 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); } // return the result on success, rather than just true @@ -184,7 +182,7 @@ class ApiClient curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // disable SSL verification, if needed - if ($this->config->getSSLVerification() == false) { + if ($this->config->getSSLVerification() === false) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); } @@ -193,24 +191,24 @@ class ApiClient $url = ($url . '?' . http_build_query($queryParams)); } - if ($method == self::$POST) { + if ($method === self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method == self::$HEAD) { + } elseif ($method === self::$HEAD) { curl_setopt($curl, CURLOPT_NOBODY, true); - } elseif ($method == self::$OPTIONS) { + } elseif ($method === self::$OPTIONS) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method == self::$PATCH) { + } elseif ($method === self::$PATCH) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method == self::$PUT) { + } elseif ($method === self::$PUT) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method == self::$DELETE) { + } elseif ($method === self::$DELETE) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method != self::$GET) { + } elseif ($method !== self::$GET) { throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -244,7 +242,7 @@ class ApiClient } // Handle the response - if ($response_info['http_code'] == 0) { + if ($response_info['http_code'] === 0) { $curl_error_message = curl_error($curl); // curl_exec can sometimes fail but still return a blank message from curl_error(). @@ -260,8 +258,8 @@ class ApiClient throw $exception; } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) { // return raw body if response is a file - if ($responseType == '\SplFileObject' || $responseType == 'string') { - return array($http_body, $response_info['http_code'], $http_header); + if ($responseType === '\SplFileObject' || $responseType === 'string') { + return [$http_body, $response_info['http_code'], $http_header]; } $data = json_decode($http_body); @@ -281,7 +279,7 @@ class ApiClient $data ); } - return array($data, $response_info['http_code'], $http_header); + return [$data, $response_info['http_code'], $http_header]; } /** @@ -330,7 +328,7 @@ class ApiClient protected function httpParseHeaders($raw_headers) { // ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986 - $headers = array(); + $headers = []; $key = ''; foreach (explode("\n", $raw_headers) as $h) { @@ -340,14 +338,14 @@ class ApiClient if (!isset($headers[$h[0]])) { $headers[$h[0]] = trim($h[1]); } elseif (is_array($headers[$h[0]])) { - $headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); + $headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]); } else { - $headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); + $headers[$h[0]] = array_merge([$headers[$h[0]]], [trim($h[1])]); } $key = $h[0]; } else { - if (substr($h[0], 0, 1) == "\t") { + if (substr($h[0], 0, 1) === "\t") { $headers[$key] .= "\r\n\t".trim($h[0]); } elseif (!$key) { $headers[0] = trim($h[0]); diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php index 12c2b9b0ea2..69c7ce6bcbd 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php @@ -52,7 +52,6 @@ namespace Swagger\Client; */ class Configuration { - private static $defaultConfiguration = null; /** @@ -60,14 +59,14 @@ class Configuration * * @var string[] */ - protected $apiKeys = array(); + protected $apiKeys = []; /** * Associate array to store API prefix (e.g. Bearer) * * @var string[] */ - protected $apiKeyPrefixes = array(); + protected $apiKeyPrefixes = []; /** * Access token for OAuth @@ -91,11 +90,11 @@ class Configuration protected $password = ''; /** - * The default instance of ApiClient + * The default header(s) * - * @var \Swagger\Client\ApiClient + * @var array */ - protected $defaultHeaders = array(); + protected $defaultHeaders = []; /** * The host @@ -283,7 +282,7 @@ class Configuration * @param string $headerName header name (e.g. Token) * @param string $headerValue header value (e.g. 1z8wp3) * - * @return ApiClient + * @return Configuration */ public function addDefaultHeader($headerName, $headerValue) { @@ -345,7 +344,7 @@ class Configuration * * @param string $userAgent the user agent of the api client * - * @return ApiClient + * @return Configuration */ public function setUserAgent($userAgent) { @@ -372,7 +371,7 @@ class Configuration * * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] * - * @return ApiClient + * @return Configuration */ public function setCurlTimeout($seconds) { @@ -493,7 +492,7 @@ class Configuration */ public static function getDefaultConfiguration() { - if (self::$defaultConfiguration == null) { + if (self::$defaultConfiguration === null) { self::$defaultConfiguration = new Configuration(); } diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php index c4baed23baa..2eade42511f 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -48,7 +48,7 @@ use \ArrayAccess; * * @category Class */ // @description Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r -/** +/** * @package Swagger\Client * @author http://github.com/swagger-api/swagger-codegen * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License v2 @@ -56,6 +56,8 @@ use \ArrayAccess; */ class ModelReturn implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string @@ -66,9 +68,9 @@ class ModelReturn implements ArrayAccess * Array of property to type mappings. Used for (de)serialization * @var string[] */ - protected static $swaggerTypes = array( + protected static $swaggerTypes = [ 'return' => 'int' - ); + ]; public static function swaggerTypes() { @@ -79,36 +81,38 @@ class ModelReturn implements ArrayAccess * Array of attributes where the key is the local name, and the value is the original name * @var string[] */ - protected static $attributeMap = array( + protected static $attributeMap = [ 'return' => 'return' - ); + ]; + + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = [ + 'return' => 'setReturn' + ]; + + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = [ + 'return' => 'getReturn' + ]; public static function attributeMap() { return self::$attributeMap; } - /** - * Array of attributes to setter functions (for deserialization of responses) - * @var string[] - */ - protected static $setters = array( - 'return' => 'setReturn' - ); - public static function setters() { return self::$setters; } - /** - * Array of attributes to getter functions (for serialization of requests) - * @var string[] - */ - protected static $getters = array( - 'return' => 'getReturn' - ); - public static function getters() { return self::$getters; @@ -122,11 +126,11 @@ class ModelReturn implements ArrayAccess * Associative array for storing property values * @var mixed[] */ - protected $container = array(); + protected $container = []; /** * Constructor - * @param mixed[] $data Associated array of property value initalizing the model + * @param mixed[] $data Associated array of property values initializing the model */ public function __construct(array $data = null) { @@ -140,7 +144,7 @@ class ModelReturn implements ArrayAccess */ public function listInvalidProperties() { - $invalid_properties = array(); + $invalid_properties = []; return $invalid_properties; } @@ -235,4 +239,3 @@ class ModelReturn implements ArrayAccess } } - diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php index f5ce9361286..c72c36f24fd 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -52,13 +52,12 @@ namespace Swagger\Client; */ class ObjectSerializer { - /** * Serialize data * * @param mixed $data the data to serialize * - * @return string serialized form of $data + * @return string|object serialized form of $data */ public static function sanitizeForSerialization($data) { @@ -72,7 +71,7 @@ class ObjectSerializer } return $data; } elseif (is_object($data)) { - $values = array(); + $values = []; foreach (array_keys($data::swaggerTypes()) as $property) { $getter = $data::getters()[$property]; if ($data->$getter() !== null) { @@ -121,7 +120,7 @@ class ObjectSerializer * 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 + * @param string[]|string|\DateTime $object an object to be serialized to a string * * @return string the serialized object */ @@ -153,7 +152,7 @@ class ObjectSerializer * 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 + * @param string|\SplFileObject $value the value of the form parameter * * @return string the form string */ @@ -171,7 +170,7 @@ class ObjectSerializer * 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 + * @param string|\DateTime $value the value of the parameter * * @return string the header string */ @@ -187,9 +186,10 @@ class ObjectSerializer /** * Serialize an array to a string. * - * @param array $collection collection to serialize to a string - * @param string $collectionFormat the format use for serialization (csv, + * @param array $collection collection to serialize to a string + * @param string $collectionFormat the format use for serialization (csv, * ssv, tsv, pipes, multi) + * @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array * * @return string */ @@ -220,33 +220,33 @@ 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 string $httpHeaders HTTP headers - * @param string $discriminator discriminator if polymorphism is used + * @param mixed $data object or primitive to be deserialized + * @param string $class class name is passed as a string + * @param string[] $httpHeaders HTTP headers + * @param string $discriminator discriminator if polymorphism is used * - * @return object an instance of $class + * @return object|array|null an single or an array of $class instances */ - public static function deserialize($data, $class, $httpHeaders = null, $discriminator = null) + public static function deserialize($data, $class, $httpHeaders = null) { if (null === $data) { return null; } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int] $inner = substr($class, 4, -1); - $deserialized = array(); + $deserialized = []; if (strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { - $deserialized[$key] = self::deserialize($value, $subClass, null, $discriminator); + $deserialized[$key] = self::deserialize($value, $subClass, null); } } return $deserialized; - } elseif (strcasecmp(substr($class, -2), '[]') == 0) { + } elseif (strcasecmp(substr($class, -2), '[]') === 0) { $subClass = substr($class, 0, -2); - $values = array(); + $values = []; foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass, null, $discriminator); + $values[] = self::deserialize($value, $subClass, null); } return $values; } elseif ($class === 'object') { @@ -264,7 +264,7 @@ class ObjectSerializer } else { return null; } - } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { + } elseif (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { settype($data, $class); return $data; } elseif ($class === '\SplFileObject') { @@ -277,7 +277,6 @@ class ObjectSerializer } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - if (Configuration::getDefaultConfiguration()->getDebug()) { error_log("[DEBUG] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.".PHP_EOL, 3, Configuration::getDefaultConfiguration()->getDebugFile()); } @@ -285,6 +284,7 @@ class ObjectSerializer return $deserialized; } else { // If a discriminator is defined and points to a valid subclass, use it. + $discriminator = $class::DISCRIMINATOR; if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { $subclass = '\Swagger\Client\Model\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { @@ -301,7 +301,7 @@ class ObjectSerializer $propertyValue = $data->{$instance::attributeMap()[$property]}; if (isset($propertyValue)) { - $instance->$propertySetter(self::deserialize($propertyValue, $type, null, $discriminator)); + $instance->$propertySetter(self::deserialize($propertyValue, $type, null)); } } return $instance; diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/phpunit.xml.dist b/samples/client/petstore-security-test/php/SwaggerClient-php/phpunit.xml.dist new file mode 100644 index 00000000000..c12ee148477 --- /dev/null +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + ./test/Api + ./test/Model + + + + + + ./lib/Api + ./lib/Model + + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php index 0cbdb8b1220..60c0799ecc3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class AdditionalPropertiesClass implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php index 9344dd618f7..06625475509 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Animal implements ArrayAccess { + const DISCRIMINATOR = 'className'; + /** * The original name of the model. * @var string @@ -126,8 +128,8 @@ class Animal implements ArrayAccess $this->container['color'] = isset($data['color']) ? $data['color'] : 'red'; // Initialize discriminator property with the model name. - $discrimintor = array_search('className', self::$attributeMap); - $this->container[$discrimintor] = static::$swaggerModelName; + $discriminator = array_search('className', self::$attributeMap); + $this->container[$discriminator] = static::$swaggerModelName; } /** diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php index 185f7b2e772..a814b227c14 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class AnimalFarm implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php index dd78695f4ae..1240d1f3efb 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class ApiResponse implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php index f21da5a742d..060c16dc443 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class ArrayOfArrayOfNumberOnly implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php index d9b64bbe0ae..eac1a959200 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class ArrayOfNumberOnly implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php index be4bc7b0231..e3266c65b0c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class ArrayTest implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php index fdaa49e31f8..fbab168ade9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Cat extends Animal implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string 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 1258907ffec..b3f6ffc1c7c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Category implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php index 558469ed5db..55ef2a1918a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Client implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php index 898e96f5373..2888805e717 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Dog extends Animal implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php index 548de3b160f..c2bc15def85 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class EnumArrays implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php index dcfd407d690..b0ba03e5748 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class EnumTest implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index 39fc6cf385a..72c8f79a357 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class FormatTest implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php index 75520744546..6251620638f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class HasOnlyReadOnly implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php index ee1dfc365b8..986d9b1d81a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class MapTest implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php index 7c8801f342b..8af27a9c528 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class MixedPropertiesAndAdditionalPropertiesClass implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php index 1e0117d85fe..d1d79f9fd6c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php @@ -43,6 +43,8 @@ use \ArrayAccess; */ class Model200Response implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php index 092b3e51db3..d185af146f4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class ModelList implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php index 2723f3869b5..379acc123a6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -43,6 +43,8 @@ use \ArrayAccess; */ class ModelReturn implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php index ab38479e880..9722713dc26 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -43,6 +43,8 @@ use \ArrayAccess; */ class Name implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php index bb57967f248..3603f9bdd9f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class NumberOnly implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string 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 096af928d31..a50b997b635 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Order implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string 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 1b05883874d..fe9f255f75c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Pet implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php index 47efccc34b5..838792fa0c1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class ReadOnlyFirst implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php index 514073dbb09..ad2e8394bc7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class SpecialModelName implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string 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 d6d2fb62f2c..29578f37802 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class Tag implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string 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 a69ea12f254..ca36471adce 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -42,6 +42,8 @@ use \ArrayAccess; */ class User implements ArrayAccess { + const DISCRIMINATOR = null; + /** * The original name of the model. * @var string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 9ba48f42977..fbb2e8b1e45 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -214,7 +214,7 @@ class ObjectSerializer * * @return object|array|null an single or an array of $class instances */ - public static function deserialize($data, $class, $httpHeaders = null, $discriminator = null) + public static function deserialize($data, $class, $httpHeaders = null) { if (null === $data) { return null; @@ -225,7 +225,7 @@ class ObjectSerializer $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { - $deserialized[$key] = self::deserialize($value, $subClass, null, $discriminator); + $deserialized[$key] = self::deserialize($value, $subClass, null); } } return $deserialized; @@ -233,7 +233,7 @@ class ObjectSerializer $subClass = substr($class, 0, -2); $values = []; foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass, null, $discriminator); + $values[] = self::deserialize($value, $subClass, null); } return $values; } elseif ($class === 'object') { @@ -271,6 +271,7 @@ class ObjectSerializer return $deserialized; } else { // If a discriminator is defined and points to a valid subclass, use it. + $discriminator = $class::DISCRIMINATOR; if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { $subclass = '\Swagger\Client\Model\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { @@ -287,7 +288,7 @@ class ObjectSerializer $propertyValue = $data->{$instance::attributeMap()[$property]}; if (isset($propertyValue)) { - $instance->$propertySetter(self::deserialize($propertyValue, $type, null, $discriminator)); + $instance->$propertySetter(self::deserialize($propertyValue, $type, null)); } } return $instance;