Configuration.php 15 KB

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