1
1
<?php
2
2
/**
3
3
* ApiClient
4
- *
4
+ *
5
5
* PHP version 5
6
6
*
7
7
* @category Class
8
- * @package { {invokerPackage} }
8
+ * @package { {invokerPackage} }
9
9
* @author http://github.com/swagger-api/swagger-codegen
10
10
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
11
11
* @link https://github.com/swagger-api/swagger-codegen
26
26
* limitations under the License.
27
27
*/
28
28
/**
29
- * NOTE: This class is auto generated by the swagger code generator program.
30
- * https://github.com/swagger-api/swagger-codegen
29
+ * NOTE: This class is auto generated by the swagger code generator program.
30
+ * https://github.com/swagger-api/swagger-codegen
31
31
* Do not edit the class manually.
32
32
*/
33
33
@@ -37,7 +37,7 @@ namespace {{invokerPackage}};
37
37
* ApiClient Class Doc Comment
38
38
*
39
39
* @category Class
40
- * @package { {invokerPackage} }
40
+ * @package { {invokerPackage} }
41
41
* @author http://github.com/swagger-api/swagger-codegen
42
42
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
43
43
* @link https://github.com/swagger-api/swagger-codegen
@@ -52,19 +52,19 @@ class ApiClient
52
52
public static $OPTIONS = " OPTIONS" ;
53
53
public static $PUT = " PUT" ;
54
54
public static $DELETE = " DELETE" ;
55
-
56
- /**
55
+
56
+ /**
57
57
* Configuration
58
58
* @var Configuration
59
59
*/
60
60
protected $config ;
61
-
61
+
62
62
/**
63
63
* Object Serializer
64
64
* @var ObjectSerializer
65
65
*/
66
66
protected $serializer ;
67
-
67
+
68
68
/**
69
69
* Constructor of the class
70
70
* @param Configuration $config config for this ApiClient
@@ -74,11 +74,11 @@ class ApiClient
74
74
if ($config == null) {
75
75
$config = Configuration::getDefaultConfiguration();
76
76
}
77
-
77
+
78
78
$this->config = $config;
79
79
$this->serializer = new ObjectSerializer();
80
80
}
81
-
81
+
82
82
/**
83
83
* Get the config
84
84
* @return Configuration
@@ -87,7 +87,7 @@ class ApiClient
87
87
{
88
88
return $this -> config ;
89
89
}
90
-
90
+
91
91
/**
92
92
* Get the serializer
93
93
* @return ObjectSerializer
@@ -96,7 +96,7 @@ class ApiClient
96
96
{
97
97
return $this -> serializer ;
98
98
}
99
-
99
+
100
100
/**
101
101
* Get API key (with prefix if set)
102
102
* @param string $apiKeyIdentifier name of apikey
@@ -106,20 +106,20 @@ class ApiClient
106
106
{
107
107
$prefix = $this -> config -> getApiKeyPrefix ($apiKeyIdentifier );
108
108
$apiKey = $this -> config -> getApiKey ($apiKeyIdentifier );
109
-
109
+
110
110
if (! isset($apiKey )) {
111
111
return null;
112
112
}
113
-
113
+
114
114
if (isset($prefix)) {
115
115
$keyWithPrefix = $prefix ." " .$apiKey ;
116
116
} else {
117
117
$keyWithPrefix = $apiKey ;
118
118
}
119
-
119
+
120
120
return $keyWithPrefix;
121
121
}
122
-
122
+
123
123
/**
124
124
* Make the HTTP call (Sync)
125
125
* @param string $resourcePath path to method endpoint
@@ -133,42 +133,48 @@ class ApiClient
133
133
*/
134
134
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null)
135
135
{
136
-
136
+
137
137
$headers = array();
138
-
138
+
139
139
// construct the http header
140
140
$headerParams = array_merge(
141
- (array)$this -> config -> getDefaultHeaders (),
141
+ (array)$this -> config -> getDefaultHeaders (),
142
142
(array)$headerParams
143
143
);
144
-
144
+
145
145
foreach ($headerParams as $key => $val ) {
146
146
$headers [] = " $key: $val" ;
147
147
}
148
-
148
+
149
149
// form data
150
150
if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) {
151
151
$postData = http_build_query($postData );
152
152
} else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model
153
153
$postData = json_encode($this -> serializer -> sanitizeForSerialization ($postData ));
154
154
}
155
-
155
+
156
156
$url = $this->config->getHost() . $resourcePath;
157
-
157
+
158
158
$curl = curl_init();
159
159
// set timeout, if needed
160
160
if ($this->config->getCurlTimeout() != 0) {
161
161
curl_setopt($curl , CURLOPT_TIMEOUT, $this -> config -> getCurlTimeout ());
162
162
}
163
163
// return the result on success, rather than just TRUE
164
164
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
165
-
165
+
166
166
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
167
-
167
+
168
+ // disable SSL verification, if needed
169
+ if ($this->config->getSSLVerification() == false) {
170
+ curl_setopt($curl , CURLOPT_SSL_VERIFYPEER, 0);
171
+ curl_setopt($curl , CURLOPT_SSL_VERIFYHOST, 0);
172
+ }
173
+
168
174
if (! empty($queryParams)) {
169
175
$url = ($url . ' ?' . http_build_query($queryParams ));
170
176
}
171
-
177
+
172
178
if ($method == self::$POST) {
173
179
curl_setopt($curl , CURLOPT_POST, true );
174
180
curl_setopt($curl , CURLOPT_POSTFIELDS, $postData );
@@ -190,44 +196,44 @@ class ApiClient
190
196
throw new ApiException(' Method ' . $method . ' is not recognized.' );
191
197
}
192
198
curl_setopt($curl, CURLOPT_URL, $url);
193
-
199
+
194
200
// Set user agent
195
201
curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent());
196
-
202
+
197
203
// debugging for curl
198
204
if ($this->config->getDebug()) {
199
205
error_log(" [DEBUG] HTTP Request body ~BEGIN~\n " .print_r($postData , true )." \n ~END~\n " , 3, $this -> config -> getDebugFile ());
200
-
206
+
201
207
curl_setopt($curl , CURLOPT_VERBOSE, 1);
202
208
curl_setopt($curl , CURLOPT_STDERR, fopen($this -> config -> getDebugFile (), ' a' ));
203
209
} else {
204
210
curl_setopt($curl , CURLOPT_VERBOSE, 0);
205
211
}
206
-
212
+
207
213
// obtain the HTTP response headers
208
214
curl_setopt($curl, CURLOPT_HEADER, 1);
209
-
215
+
210
216
// Make the request
211
217
$response = curl_exec($curl);
212
218
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
213
219
$http_header = substr($response, 0, $http_header_size);
214
220
$http_body = substr($response, $http_header_size);
215
221
$response_info = curl_getinfo($curl);
216
-
222
+
217
223
// debug HTTP response body
218
224
if ($this->config->getDebug()) {
219
225
error_log(" [DEBUG] HTTP Response body ~BEGIN~\n " .print_r($http_body , true )." \n ~END~\n " , 3, $this -> config -> getDebugFile ());
220
226
}
221
-
227
+
222
228
// Handle the response
223
229
if ($response_info['http_code'] == 0) {
224
230
throw new ApiException(" API call to $url timed out: " .serialize($response_info ), 0, null, null);
225
231
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
226
- // return raw body if response is a file
232
+ // return raw body if response is a file
227
233
if ($responseType == ' \S plFileObject' ) {
228
234
return array($http_body , $http_header );
229
235
}
230
-
236
+
231
237
$data = json_decode($http_body);
232
238
if (json_last_error() > 0) { // if response is a string
233
239
$data = $http_body ;
@@ -240,7 +246,7 @@ class ApiClient
240
246
}
241
247
return array($data, $http_header);
242
248
}
243
-
249
+
244
250
/**
245
251
* Return the header 'Accept' based on an array of Accept provided
246
252
*
@@ -258,7 +264,7 @@ class ApiClient
258
264
return implode(' ,' , $accept );
259
265
}
260
266
}
261
-
267
+
262
268
/**
263
269
* Return the content type based on an array of content-type provided
264
270
*
0 commit comments