UpgradeApi.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. /**
  3. * UpgradeApi
  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.10.15
  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\Api;
  26. use GuzzleHttp\Client;
  27. use GuzzleHttp\ClientInterface;
  28. use GuzzleHttp\Exception\ConnectException;
  29. use GuzzleHttp\Exception\RequestException;
  30. use GuzzleHttp\Psr7\MultipartStream;
  31. use GuzzleHttp\Psr7\Request;
  32. use GuzzleHttp\RequestOptions;
  33. use Psr\Http\Message\RequestInterface;
  34. use Psr\Http\Message\ResponseInterface;
  35. use WikipaliApi\ApiException;
  36. use WikipaliApi\Configuration;
  37. use WikipaliApi\FormDataProcessor;
  38. use WikipaliApi\HeaderSelector;
  39. use WikipaliApi\ObjectSerializer;
  40. /**
  41. * UpgradeApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class UpgradeApi
  49. {
  50. /**
  51. * @var ClientInterface
  52. */
  53. protected $client;
  54. /**
  55. * @var Configuration
  56. */
  57. protected $config;
  58. /**
  59. * @var HeaderSelector
  60. */
  61. protected $headerSelector;
  62. /**
  63. * @var int Host index
  64. */
  65. protected $hostIndex;
  66. /** @var string[] $contentTypes **/
  67. public const contentTypes = [
  68. 'getApiV3Upgrade' => [
  69. 'application/json',
  70. ],
  71. ];
  72. /**
  73. * @param ClientInterface $client
  74. * @param Configuration $config
  75. * @param HeaderSelector $selector
  76. * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
  77. */
  78. public function __construct(
  79. ?ClientInterface $client = null,
  80. ?Configuration $config = null,
  81. ?HeaderSelector $selector = null,
  82. int $hostIndex = 0
  83. ) {
  84. $this->client = $client ?: new Client();
  85. $this->config = $config ?: Configuration::getDefaultConfiguration();
  86. $this->headerSelector = $selector ?: new HeaderSelector();
  87. $this->hostIndex = $hostIndex;
  88. }
  89. /**
  90. * Set the host index
  91. *
  92. * @param int $hostIndex Host index (required)
  93. */
  94. public function setHostIndex($hostIndex): void
  95. {
  96. $this->hostIndex = $hostIndex;
  97. }
  98. /**
  99. * Get the host index
  100. *
  101. * @return int Host index
  102. */
  103. public function getHostIndex()
  104. {
  105. return $this->hostIndex;
  106. }
  107. /**
  108. * @return Configuration
  109. */
  110. public function getConfig()
  111. {
  112. return $this->config;
  113. }
  114. /**
  115. * Operation getApiV3Upgrade
  116. *
  117. * 客户端升级检查
  118. *
  119. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Upgrade'] to see the possible values for this operation
  120. *
  121. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  122. * @throws \InvalidArgumentException
  123. * @return \WikipaliApi\Model\GetApiV3SearchSearch200Response
  124. */
  125. public function getApiV3Upgrade(string $contentType = self::contentTypes['getApiV3Upgrade'][0])
  126. {
  127. list($response) = $this->getApiV3UpgradeWithHttpInfo($contentType);
  128. return $response;
  129. }
  130. /**
  131. * Operation getApiV3UpgradeWithHttpInfo
  132. *
  133. * 客户端升级检查
  134. *
  135. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Upgrade'] to see the possible values for this operation
  136. *
  137. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  138. * @throws \InvalidArgumentException
  139. * @return array of \WikipaliApi\Model\GetApiV3SearchSearch200Response, HTTP status code, HTTP response headers (array of strings)
  140. */
  141. public function getApiV3UpgradeWithHttpInfo(string $contentType = self::contentTypes['getApiV3Upgrade'][0])
  142. {
  143. $request = $this->getApiV3UpgradeRequest($contentType);
  144. try {
  145. $options = $this->createHttpClientOption();
  146. try {
  147. $response = $this->client->send($request, $options);
  148. } catch (RequestException $e) {
  149. throw new ApiException(
  150. "[{$e->getCode()}] {$e->getMessage()}",
  151. (int) $e->getCode(),
  152. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  153. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  154. );
  155. } catch (ConnectException $e) {
  156. throw new ApiException(
  157. "[{$e->getCode()}] {$e->getMessage()}",
  158. (int) $e->getCode(),
  159. null,
  160. null
  161. );
  162. }
  163. $statusCode = $response->getStatusCode();
  164. switch($statusCode) {
  165. case 200:
  166. return $this->handleResponseWithDataType(
  167. '\WikipaliApi\Model\GetApiV3SearchSearch200Response',
  168. $request,
  169. $response,
  170. );
  171. }
  172. if ($statusCode < 200 || $statusCode > 299) {
  173. throw new ApiException(
  174. sprintf(
  175. '[%d] Error connecting to the API (%s)',
  176. $statusCode,
  177. (string) $request->getUri()
  178. ),
  179. $statusCode,
  180. $response->getHeaders(),
  181. (string) $response->getBody()
  182. );
  183. }
  184. return $this->handleResponseWithDataType(
  185. '\WikipaliApi\Model\GetApiV3SearchSearch200Response',
  186. $request,
  187. $response,
  188. );
  189. } catch (ApiException $e) {
  190. switch ($e->getCode()) {
  191. case 200:
  192. $data = ObjectSerializer::deserialize(
  193. $e->getResponseBody(),
  194. '\WikipaliApi\Model\GetApiV3SearchSearch200Response',
  195. $e->getResponseHeaders()
  196. );
  197. $e->setResponseObject($data);
  198. throw $e;
  199. }
  200. throw $e;
  201. }
  202. }
  203. /**
  204. * Operation getApiV3UpgradeAsync
  205. *
  206. * 客户端升级检查
  207. *
  208. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Upgrade'] to see the possible values for this operation
  209. *
  210. * @throws \InvalidArgumentException
  211. * @return \GuzzleHttp\Promise\PromiseInterface
  212. */
  213. public function getApiV3UpgradeAsync(string $contentType = self::contentTypes['getApiV3Upgrade'][0])
  214. {
  215. return $this->getApiV3UpgradeAsyncWithHttpInfo($contentType)
  216. ->then(
  217. function ($response) {
  218. return $response[0];
  219. }
  220. );
  221. }
  222. /**
  223. * Operation getApiV3UpgradeAsyncWithHttpInfo
  224. *
  225. * 客户端升级检查
  226. *
  227. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Upgrade'] to see the possible values for this operation
  228. *
  229. * @throws \InvalidArgumentException
  230. * @return \GuzzleHttp\Promise\PromiseInterface
  231. */
  232. public function getApiV3UpgradeAsyncWithHttpInfo(string $contentType = self::contentTypes['getApiV3Upgrade'][0])
  233. {
  234. $returnType = '\WikipaliApi\Model\GetApiV3SearchSearch200Response';
  235. $request = $this->getApiV3UpgradeRequest($contentType);
  236. return $this->client
  237. ->sendAsync($request, $this->createHttpClientOption())
  238. ->then(
  239. function ($response) use ($returnType) {
  240. if ($returnType === '\SplFileObject') {
  241. $content = $response->getBody(); //stream goes to serializer
  242. } else {
  243. $content = (string) $response->getBody();
  244. if ($returnType !== 'string') {
  245. $content = json_decode($content);
  246. }
  247. }
  248. return [
  249. ObjectSerializer::deserialize($content, $returnType, []),
  250. $response->getStatusCode(),
  251. $response->getHeaders()
  252. ];
  253. },
  254. function ($exception) {
  255. $response = $exception->getResponse();
  256. $statusCode = $response->getStatusCode();
  257. throw new ApiException(
  258. sprintf(
  259. '[%d] Error connecting to the API (%s)',
  260. $statusCode,
  261. $exception->getRequest()->getUri()
  262. ),
  263. $statusCode,
  264. $response->getHeaders(),
  265. (string) $response->getBody()
  266. );
  267. }
  268. );
  269. }
  270. /**
  271. * Create request for operation 'getApiV3Upgrade'
  272. *
  273. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3Upgrade'] to see the possible values for this operation
  274. *
  275. * @throws \InvalidArgumentException
  276. * @return \GuzzleHttp\Psr7\Request
  277. */
  278. public function getApiV3UpgradeRequest(string $contentType = self::contentTypes['getApiV3Upgrade'][0])
  279. {
  280. $resourcePath = '/v3/upgrade';
  281. $formParams = [];
  282. $queryParams = [];
  283. $headerParams = [];
  284. $httpBody = '';
  285. $multipart = false;
  286. $headers = $this->headerSelector->selectHeaders(
  287. ['application/json', ],
  288. $contentType,
  289. $multipart
  290. );
  291. // for model (json/xml)
  292. if (count($formParams) > 0) {
  293. if ($multipart) {
  294. $multipartContents = [];
  295. foreach ($formParams as $formParamName => $formParamValue) {
  296. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  297. foreach ($formParamValueItems as $formParamValueItem) {
  298. $multipartContents[] = [
  299. 'name' => $formParamName,
  300. 'contents' => $formParamValueItem
  301. ];
  302. }
  303. }
  304. // for HTTP post (form)
  305. $httpBody = new MultipartStream($multipartContents);
  306. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  307. # if Content-Type contains "application/json", json_encode the form parameters
  308. try {
  309. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  310. } catch (\JsonException $e) {
  311. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  312. }
  313. } else {
  314. // for HTTP post (form)
  315. $httpBody = ObjectSerializer::buildQuery($formParams);
  316. }
  317. }
  318. // this endpoint requires Bearer authentication (access token)
  319. if (!empty($this->config->getAccessToken())) {
  320. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  321. }
  322. $defaultHeaders = [];
  323. if ($this->config->getUserAgent()) {
  324. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  325. }
  326. $headers = array_merge(
  327. $defaultHeaders,
  328. $headerParams,
  329. $headers
  330. );
  331. $operationHost = $this->config->getHost();
  332. $query = ObjectSerializer::buildQuery($queryParams);
  333. return new Request(
  334. 'GET',
  335. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  336. $headers,
  337. $httpBody
  338. );
  339. }
  340. /**
  341. * Create http client option
  342. *
  343. * @throws \RuntimeException on file opening failure
  344. * @return array of http client options
  345. */
  346. protected function createHttpClientOption()
  347. {
  348. $options = [];
  349. if ($this->config->getDebug()) {
  350. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  351. if (!$options[RequestOptions::DEBUG]) {
  352. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  353. }
  354. }
  355. if ($this->config->getCertFile()) {
  356. $options[RequestOptions::CERT] = $this->config->getCertFile();
  357. }
  358. if ($this->config->getKeyFile()) {
  359. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  360. }
  361. return $options;
  362. }
  363. private function handleResponseWithDataType(
  364. string $dataType,
  365. RequestInterface $request,
  366. ResponseInterface $response
  367. ): array {
  368. if ($dataType === '\SplFileObject') {
  369. $content = $response->getBody(); //stream goes to serializer
  370. } else {
  371. $content = (string) $response->getBody();
  372. if ($dataType !== 'string') {
  373. try {
  374. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  375. } catch (\JsonException $exception) {
  376. throw new ApiException(
  377. sprintf(
  378. 'Error JSON decoding server response (%s)',
  379. $request->getUri()
  380. ),
  381. $response->getStatusCode(),
  382. $response->getHeaders(),
  383. $content
  384. );
  385. }
  386. }
  387. }
  388. return [
  389. ObjectSerializer::deserialize($content, $dataType, []),
  390. $response->getStatusCode(),
  391. $response->getHeaders()
  392. ];
  393. }
  394. private function responseWithinRangeCode(
  395. string $rangeCode,
  396. int $statusCode
  397. ): bool {
  398. $left = (int) ($rangeCode[0].'00');
  399. $right = (int) ($rangeCode[0].'99');
  400. return $statusCode >= $left && $statusCode <= $right;
  401. }
  402. }