1: <?php
2: /**
3: * Configuration
4: * PHP version 7.4
5: *
6: * @category Class
7: * @package Ally\PetStore
8: * @author OpenAPI Generator team
9: * @link https://openapi-generator.tech
10: */
11:
12: /**
13: * OpenAPI Petstore
14: *
15: * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
16: *
17: * The version of the OpenAPI document: 1.0.0
18: * Generated by: https://openapi-generator.tech
19: * OpenAPI Generator version: 6.1.0-SNAPSHOT
20: */
21:
22: /**
23: * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
24: * https://openapi-generator.tech
25: * Do not edit the class manually.
26: */
27:
28: namespace Ally\PetStore;
29:
30: /**
31: * Configuration Class Doc Comment
32: * PHP version 7.4
33: *
34: * @category Class
35: * @package Ally\PetStore
36: * @author OpenAPI Generator team
37: * @link https://openapi-generator.tech
38: */
39: class Configuration
40: {
41: public const BOOLEAN_FORMAT_INT = 'int';
42: public const BOOLEAN_FORMAT_STRING = 'string';
43:
44: /**
45: * @var Configuration
46: */
47: private static $defaultConfiguration;
48:
49: /**
50: * Associate array to store API key(s)
51: *
52: * @var string[]
53: */
54: protected $apiKeys = [];
55:
56: /**
57: * Associate array to store API prefix (e.g. Bearer)
58: *
59: * @var string[]
60: */
61: protected $apiKeyPrefixes = [];
62:
63: /**
64: * Access token for OAuth/Bearer authentication
65: *
66: * @var string
67: */
68: protected $accessToken = '';
69:
70: /**
71: * Boolean format for query string
72: *
73: * @var string
74: */
75: protected $booleanFormatForQueryString = self::BOOLEAN_FORMAT_INT;
76:
77: /**
78: * Username for HTTP basic authentication
79: *
80: * @var string
81: */
82: protected $username = '';
83:
84: /**
85: * Password for HTTP basic authentication
86: *
87: * @var string
88: */
89: protected $password = '';
90:
91: /**
92: * The host
93: *
94: * @var string
95: */
96: protected $host = 'http://petstore.swagger.io/v2';
97:
98: /**
99: * User agent of the HTTP request, set to "OpenAPI-Generator/{version}/PHP" by default
100: *
101: * @var string
102: */
103: protected $userAgent = 'OpenAPI-Generator/1.0.0/PHP';
104:
105: /**
106: * Debug switch (default set to false)
107: *
108: * @var bool
109: */
110: protected $debug = false;
111:
112: /**
113: * Debug file location (log to STDOUT by default)
114: *
115: * @var string
116: */
117: protected $debugFile = 'php://output';
118:
119: /**
120: * Debug file location (log to STDOUT by default)
121: *
122: * @var string
123: */
124: protected $tempFolderPath;
125:
126: /**
127: * Constructor
128: */
129: public function __construct()
130: {
131: $this->tempFolderPath = sys_get_temp_dir();
132: }
133:
134: /**
135: * Sets API key
136: *
137: * @param string $apiKeyIdentifier API key identifier (authentication scheme)
138: * @param string $key API key or token
139: *
140: * @return $this
141: */
142: public function setApiKey($apiKeyIdentifier, $key)
143: {
144: $this->apiKeys[$apiKeyIdentifier] = $key;
145: return $this;
146: }
147:
148: /**
149: * Gets API key
150: *
151: * @param string $apiKeyIdentifier API key identifier (authentication scheme)
152: *
153: * @return null|string API key or token
154: */
155: public function getApiKey($apiKeyIdentifier)
156: {
157: return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null;
158: }
159:
160: /**
161: * Sets the prefix for API key (e.g. Bearer)
162: *
163: * @param string $apiKeyIdentifier API key identifier (authentication scheme)
164: * @param string $prefix API key prefix, e.g. Bearer
165: *
166: * @return $this
167: */
168: public function setApiKeyPrefix($apiKeyIdentifier, $prefix)
169: {
170: $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
171: return $this;
172: }
173:
174: /**
175: * Gets API key prefix
176: *
177: * @param string $apiKeyIdentifier API key identifier (authentication scheme)
178: *
179: * @return null|string
180: */
181: public function getApiKeyPrefix($apiKeyIdentifier)
182: {
183: return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null;
184: }
185:
186: /**
187: * Sets the access token for OAuth
188: *
189: * @param string $accessToken Token for OAuth
190: *
191: * @return $this
192: */
193: public function setAccessToken($accessToken)
194: {
195: $this->accessToken = $accessToken;
196: return $this;
197: }
198:
199: /**
200: * Gets the access token for OAuth
201: *
202: * @return string Access token for OAuth
203: */
204: public function getAccessToken()
205: {
206: return $this->accessToken;
207: }
208:
209: /**
210: * Sets boolean format for query string.
211: *
212: * @param string $booleanFormatForQueryString Boolean format for query string
213: *
214: * @return $this
215: */
216: public function setBooleanFormatForQueryString(string $booleanFormat)
217: {
218: $this->booleanFormatForQueryString = $booleanFormat;
219:
220: return $this;
221: }
222:
223: /**
224: * Gets boolean format for query string.
225: *
226: * @return string Boolean format for query string
227: */
228: public function getBooleanFormatForQueryString(): string
229: {
230: return $this->booleanFormatForQueryString;
231: }
232:
233: /**
234: * Sets the username for HTTP basic authentication
235: *
236: * @param string $username Username for HTTP basic authentication
237: *
238: * @return $this
239: */
240: public function setUsername($username)
241: {
242: $this->username = $username;
243: return $this;
244: }
245:
246: /**
247: * Gets the username for HTTP basic authentication
248: *
249: * @return string Username for HTTP basic authentication
250: */
251: public function getUsername()
252: {
253: return $this->username;
254: }
255:
256: /**
257: * Sets the password for HTTP basic authentication
258: *
259: * @param string $password Password for HTTP basic authentication
260: *
261: * @return $this
262: */
263: public function setPassword($password)
264: {
265: $this->password = $password;
266: return $this;
267: }
268:
269: /**
270: * Gets the password for HTTP basic authentication
271: *
272: * @return string Password for HTTP basic authentication
273: */
274: public function getPassword()
275: {
276: return $this->password;
277: }
278:
279: /**
280: * Sets the host
281: *
282: * @param string $host Host
283: *
284: * @return $this
285: */
286: public function setHost($host)
287: {
288: $this->host = $host;
289: return $this;
290: }
291:
292: /**
293: * Gets the host
294: *
295: * @return string Host
296: */
297: public function getHost()
298: {
299: return $this->host;
300: }
301:
302: /**
303: * Sets the user agent of the api client
304: *
305: * @param string $userAgent the user agent of the api client
306: *
307: * @throws \InvalidArgumentException
308: * @return $this
309: */
310: public function setUserAgent($userAgent)
311: {
312: if (!is_string($userAgent)) {
313: throw new \InvalidArgumentException('User-agent must be a string.');
314: }
315:
316: $this->userAgent = $userAgent;
317: return $this;
318: }
319:
320: /**
321: * Gets the user agent of the api client
322: *
323: * @return string user agent
324: */
325: public function getUserAgent()
326: {
327: return $this->userAgent;
328: }
329:
330: /**
331: * Sets debug flag
332: *
333: * @param bool $debug Debug flag
334: *
335: * @return $this
336: */
337: public function setDebug($debug)
338: {
339: $this->debug = $debug;
340: return $this;
341: }
342:
343: /**
344: * Gets the debug flag
345: *
346: * @return bool
347: */
348: public function getDebug()
349: {
350: return $this->debug;
351: }
352:
353: /**
354: * Sets the debug file
355: *
356: * @param string $debugFile Debug file
357: *
358: * @return $this
359: */
360: public function setDebugFile($debugFile)
361: {
362: $this->debugFile = $debugFile;
363: return $this;
364: }
365:
366: /**
367: * Gets the debug file
368: *
369: * @return string
370: */
371: public function getDebugFile()
372: {
373: return $this->debugFile;
374: }
375:
376: /**
377: * Sets the temp folder path
378: *
379: * @param string $tempFolderPath Temp folder path
380: *
381: * @return $this
382: */
383: public function setTempFolderPath($tempFolderPath)
384: {
385: $this->tempFolderPath = $tempFolderPath;
386: return $this;
387: }
388:
389: /**
390: * Gets the temp folder path
391: *
392: * @return string Temp folder path
393: */
394: public function getTempFolderPath()
395: {
396: return $this->tempFolderPath;
397: }
398:
399: /**
400: * Gets the default configuration instance
401: *
402: * @return Configuration
403: */
404: public static function getDefaultConfiguration()
405: {
406: if (self::$defaultConfiguration === null) {
407: self::$defaultConfiguration = new Configuration();
408: }
409:
410: return self::$defaultConfiguration;
411: }
412:
413: /**
414: * Sets the default configuration instance
415: *
416: * @param Configuration $config An instance of the Configuration Object
417: *
418: * @return void
419: */
420: public static function setDefaultConfiguration(Configuration $config)
421: {
422: self::$defaultConfiguration = $config;
423: }
424:
425: /**
426: * Gets the essential information for debugging
427: *
428: * @return string The report for debugging
429: */
430: public static function toDebugReport()
431: {
432: $report = 'PHP SDK (Ally\PetStore) Debug Report:' . PHP_EOL;
433: $report .= ' OS: ' . php_uname() . PHP_EOL;
434: $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL;
435: $report .= ' The version of the OpenAPI document: 1.0.0' . PHP_EOL;
436: $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL;
437:
438: return $report;
439: }
440:
441: /**
442: * Get API key (with prefix if set)
443: *
444: * @param string $apiKeyIdentifier name of apikey
445: *
446: * @return null|string API key with the prefix
447: */
448: public function getApiKeyWithPrefix($apiKeyIdentifier)
449: {
450: $prefix = $this->getApiKeyPrefix($apiKeyIdentifier);
451: $apiKey = $this->getApiKey($apiKeyIdentifier);
452:
453: if ($apiKey === null) {
454: return null;
455: }
456:
457: if ($prefix === null) {
458: $keyWithPrefix = $apiKey;
459: } else {
460: $keyWithPrefix = $prefix . ' ' . $apiKey;
461: }
462:
463: return $keyWithPrefix;
464: }
465:
466: /**
467: * Returns an array of host settings
468: *
469: * @return array an array of host settings
470: */
471: public function getHostSettings()
472: {
473: return [
474: [
475: "url" => "http://petstore.swagger.io/v2",
476: "description" => "No description provided",
477: ]
478: ];
479: }
480:
481: /**
482: * Returns URL based on host settings, index and variables
483: *
484: * @param array $hostSettings array of host settings, generated from getHostSettings() or equivalent from the API clients
485: * @param int $hostIndex index of the host settings
486: * @param array|null $variables hash of variable and the corresponding value (optional)
487: * @return string URL based on host settings
488: */
489: public static function getHostString(array $hostsSettings, $hostIndex, array $variables = null)
490: {
491: if (null === $variables) {
492: $variables = [];
493: }
494:
495: // check array index out of bound
496: if ($hostIndex < 0 || $hostIndex >= count($hostsSettings)) {
497: throw new \InvalidArgumentException("Invalid index $hostIndex when selecting the host. Must be less than ".count($hostsSettings));
498: }
499:
500: $host = $hostsSettings[$hostIndex];
501: $url = $host["url"];
502:
503: // go through variable and assign a value
504: foreach ($host["variables"] ?? [] as $name => $variable) {
505: if (array_key_exists($name, $variables)) { // check to see if it's in the variables provided by the user
506: if (!isset($variable['enum_values']) || in_array($variables[$name], $variable["enum_values"], true)) { // check to see if the value is in the enum
507: $url = str_replace("{".$name."}", $variables[$name], $url);
508: } else {
509: throw new \InvalidArgumentException("The variable `$name` in the host URL has invalid value ".$variables[$name].". Must be ".join(',', $variable["enum_values"]).".");
510: }
511: } else {
512: // use default value
513: $url = str_replace("{".$name."}", $variable["default_value"], $url);
514: }
515: }
516:
517: return $url;
518: }
519:
520: /**
521: * Returns URL based on the index and variables
522: *
523: * @param int $index index of the host settings
524: * @param array|null $variables hash of variable and the corresponding value (optional)
525: * @return string URL based on host settings
526: */
527: public function getHostFromSettings($index, $variables = null)
528: {
529: return self::getHostString($this->getHostSettings(), $index, $variables);
530: }
531: }
532: