forked from loafle/openapi-generator-original
update coding style based on CodeSniffer
This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* ApiClient
|
||||
*
|
||||
* 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
|
||||
*
|
||||
@@ -14,10 +25,25 @@
|
||||
* 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 ApiClient {
|
||||
/**
|
||||
* ApiClient 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 ApiClient
|
||||
{
|
||||
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
@@ -25,16 +51,24 @@ class ApiClient {
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
/** @var Configuration */
|
||||
/**
|
||||
* Configuration
|
||||
* @var Configuration
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/** @var ObjectSerializer */
|
||||
/**
|
||||
* Object Serializer
|
||||
* @var ObjectSerializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
* @param Configuration $config config for this ApiClient
|
||||
*/
|
||||
function __construct(Configuration $config = null) {
|
||||
function __construct(Configuration $config = null)
|
||||
{
|
||||
if ($config == null) {
|
||||
$config = Configuration::getDefaultConfiguration();
|
||||
}
|
||||
@@ -44,27 +78,30 @@ class ApiClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* get the config
|
||||
* Get the config
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfig() {
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the serializer
|
||||
* Get the serializer
|
||||
* @return ObjectSerializer
|
||||
*/
|
||||
public function getSerializer() {
|
||||
public function getSerializer()
|
||||
{
|
||||
return $this->serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get API key (with prefix if set)
|
||||
* @param string $apiKey name of apikey
|
||||
* @param string $apiKeyIdentifier name of apikey
|
||||
* @return string API key with the prefix
|
||||
*/
|
||||
public function getApiKeyWithPrefix($apiKeyIdentifier) {
|
||||
public function getApiKeyWithPrefix($apiKeyIdentifier)
|
||||
{
|
||||
$prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier);
|
||||
$apiKey = $this->config->getApiKey($apiKeyIdentifier);
|
||||
|
||||
@@ -82,20 +119,26 @@ class ApiClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the HTTP call (Sync)
|
||||
* @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
|
||||
* @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
|
||||
* @param string $responseType expected response type of the endpoint
|
||||
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
|
||||
* @return mixed
|
||||
*/
|
||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
|
||||
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);
|
||||
// construct the http header
|
||||
$headerParams = array_merge(
|
||||
(array)$this->config->getDefaultHeaders(),
|
||||
(array)$headerParams
|
||||
);
|
||||
|
||||
foreach ($headerParams as $key => $val) {
|
||||
$headers[] = "$key: $val";
|
||||
@@ -104,8 +147,7 @@ class ApiClient {
|
||||
// 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
|
||||
} 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));
|
||||
}
|
||||
|
||||
@@ -184,21 +226,25 @@ class ApiClient {
|
||||
$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);
|
||||
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
|
||||
/**
|
||||
* 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) {
|
||||
public static function selectHeaderAccept($accept)
|
||||
{
|
||||
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||
return NULL;
|
||||
return null;
|
||||
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||
return 'application/json';
|
||||
} else {
|
||||
@@ -206,13 +252,15 @@ class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the content type based on an array of content-type provided
|
||||
/**
|
||||
* Return the content type based on an array of content-type provided
|
||||
*
|
||||
* @param string[] $content_type Array fo content-type
|
||||
*
|
||||
* @param string[] content_type_array Array fo content-type
|
||||
* @return string Content-Type (e.g. application/json)
|
||||
*/
|
||||
public static function selectHeaderContentType($content_type) {
|
||||
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)) {
|
||||
|
||||
Reference in New Issue
Block a user