diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 8927cbbecb3..9db41df2aee 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -1,11 +1,11 @@ config = $config; $this->serializer = new ObjectSerializer(); } - + /** * Get the config * @return Configuration @@ -87,7 +87,7 @@ class ApiClient { return $this->config; } - + /** * Get the serializer * @return ObjectSerializer @@ -96,7 +96,7 @@ class ApiClient { return $this->serializer; } - + /** * Get API key (with prefix if set) * @param string $apiKeyIdentifier name of apikey @@ -106,20 +106,20 @@ class ApiClient { $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; } - + /** * Make the HTTP call (Sync) * @param string $resourcePath path to method endpoint @@ -133,28 +133,28 @@ class ApiClient */ public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { - + $headers = array(); - + // construct the http header $headerParams = array_merge( - (array)$this->config->getDefaultHeaders(), + (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) { @@ -162,13 +162,19 @@ class ApiClient } // return the result on success, rather than just TRUE curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - + + // disable SSL verification, if needed + if ($this->config->getSSLVerification() == false) { + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); + } + 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); @@ -190,44 +196,44 @@ class ApiClient 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 + // 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; @@ -240,7 +246,7 @@ class ApiClient } return array($data, $http_header); } - + /** * Return the header 'Accept' based on an array of Accept provided * @@ -258,7 +264,7 @@ class ApiClient return implode(',', $accept); } } - + /** * Return the content type based on an array of content-type provided * diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 981085c6378..96bc8a1b660 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -27,8 +27,8 @@ */ /** - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen + * 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. */ @@ -48,70 +48,70 @@ class Configuration { private static $_defaultConfiguration = null; - - /** + + /** * Associate array to store API key(s) * * @var string[] */ protected $apiKeys = array(); - + /** * Associate array to store API prefix (e.g. Bearer) * * @var string[] */ protected $apiKeyPrefixes = array(); - - /** + + /** * Username for HTTP basic authentication * * @var string */ protected $username = ''; - + /** * Password for HTTP basic authentication * * @var string */ protected $password = ''; - + /** * The default instance of ApiClient * * @var \{{invokerPackage}}\ApiClient */ protected $defaultHeaders = array(); - + /** * The host * * @var string */ protected $host = '{{basePath}}'; - + /** * Timeout (second) of the HTTP request, by default set to 0, no timeout * - * @var string + * @var string */ protected $curlTimeout = 0; - + /** * User agent of the HTTP request, set to "PHP-Swagger" by default * * @var string */ protected $userAgent = "PHP-Swagger/{{artifactVersion}}"; - + /** * Debug switch (default set to false) * * @var bool */ protected $debug = false; - + /** * Debug file location (log to STDOUT by default) * @@ -126,6 +126,15 @@ class Configuration */ protected $tempFolderPath; + /** + * Indicates if SSL verification should be enabled or disabled. + * + * This is useful if the host uses a self-signed SSL certificate. + * + * @var boolean True if the certificate should be validated, false otherwise. + */ + protected $sslVerification = true; + /** * Constructor */ @@ -133,7 +142,7 @@ class Configuration { $this->tempFolderPath = sys_get_temp_dir(); } - + /** * Sets API key * @@ -147,7 +156,7 @@ class Configuration $this->apiKeys[$apiKeyIdentifier] = $key; return $this; } - + /** * Gets API key * @@ -159,7 +168,7 @@ class Configuration { return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; } - + /** * Sets the prefix for API key (e.g. Bearer) * @@ -173,7 +182,7 @@ class Configuration $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix; return $this; } - + /** * Gets API key prefix * @@ -185,7 +194,7 @@ class Configuration { return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; } - + /** * Sets the username for HTTP basic authentication * @@ -198,7 +207,7 @@ class Configuration $this->username = $username; return $this; } - + /** * Gets the username for HTTP basic authentication * @@ -208,7 +217,7 @@ class Configuration { return $this->username; } - + /** * Sets the password for HTTP basic authentication * @@ -221,7 +230,7 @@ class Configuration $this->password = $password; return $this; } - + /** * Gets the password for HTTP basic authentication * @@ -231,7 +240,7 @@ class Configuration { return $this->password; } - + /** * Adds a default header * @@ -245,11 +254,11 @@ class Configuration if (!is_string($headerName)) { throw new \InvalidArgumentException('Header name must be a string.'); } - + $this->defaultHeaders[$headerName] = $headerValue; return $this; } - + /** * Gets the default header * @@ -259,7 +268,7 @@ class Configuration { return $this->defaultHeaders; } - + /** * Deletes a default header * @@ -271,7 +280,7 @@ class Configuration { unset($this->defaultHeaders[$headerName]); } - + /** * Sets the host * @@ -284,7 +293,7 @@ class Configuration $this->host = $host; return $this; } - + /** * Gets the host * @@ -294,7 +303,7 @@ class Configuration { return $this->host; } - + /** * Sets the user agent of the api client * @@ -307,11 +316,11 @@ class Configuration if (!is_string($userAgent)) { throw new \InvalidArgumentException('User-agent must be a string.'); } - + $this->userAgent = $userAgent; return $this; } - + /** * Gets the user agent of the api client * @@ -321,7 +330,7 @@ class Configuration { return $this->userAgent; } - + /** * Sets the HTTP timeout value * @@ -334,11 +343,11 @@ class Configuration if (!is_numeric($seconds) || $seconds < 0) { throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); } - + $this->curlTimeout = $seconds; return $this; } - + /** * Gets the HTTP timeout value * @@ -348,10 +357,10 @@ class Configuration { return $this->curlTimeout; } - + /** * Sets debug flag - * + * * @param bool $debug Debug flag * * @return Configuration @@ -361,7 +370,7 @@ class Configuration $this->debug = $debug; return $this; } - + /** * Gets the debug flag * @@ -371,7 +380,7 @@ class Configuration { return $this->debug; } - + /** * Sets the debug file * @@ -384,7 +393,7 @@ class Configuration $this->debugFile = $debugFile; return $this; } - + /** * Gets the debug file * @@ -394,7 +403,7 @@ class Configuration { return $this->debugFile; } - + /** * Sets the temp folder path * @@ -407,7 +416,7 @@ class Configuration $this->tempFolderPath = $tempFolderPath; return $this; } - + /** * Gets the temp folder path * @@ -417,7 +426,30 @@ class Configuration { return $this->tempFolderPath; } - + + /** + * Sets if SSL verification should be enabled or disabled + * + * @param boolean $sslVerification True if the certificate should be validated, false otherwise + * + * @return Configuration + */ + public function setSSLVerification($sslVerification) + { + $this->sslVerification = $sslVerification; + return $this; + } + + /** + * Gets if SSL verification should be enabled or disabled + * + * @return boolean True if the certificate should be validated, false otherwise + */ + public function getSSLVerification() + { + return $this->sslVerification; + } + /** * Gets the default configuration instance * @@ -428,10 +460,10 @@ class Configuration if (self::$_defaultConfiguration == null) { self::$_defaultConfiguration = new Configuration(); } - + return self::$_defaultConfiguration; } - + /** * Sets the detault configuration instance * @@ -443,7 +475,7 @@ class Configuration { self::$_defaultConfiguration = $config; } - + /** * Gets the essential information for debugging * @@ -457,8 +489,8 @@ class Configuration $report .= " Swagger Spec Version: {{version}}\n"; $report .= " SDK Package Version: {{artifactVersion}}\n"; $report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n"; - + return $report; } - + }