TipitakaChapterChannelsApi.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. /**
  3. * TipitakaChapterChannelsApi
  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.11.9
  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. * TipitakaChapterChannelsApi Class Doc Comment
  42. *
  43. * @category Class
  44. * @package WikipaliApi
  45. * @author OpenAPI Generator team
  46. * @link https://openapi-generator.tech
  47. */
  48. class TipitakaChapterChannelsApi
  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. 'getApiV3TipitakaChapterChannelsBookPara' => [
  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 getApiV3TipitakaChapterChannelsBookPara
  116. *
  117. * 列出一章的 channel
  118. *
  119. * @param int $book 书号 (required)
  120. * @param int $para 章节起始段落号 (required)
  121. * @param int|null $per_page 每页数量,最大 200 (optional, default to 100)
  122. * @param int|null $page 页码 (optional, default to 1)
  123. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'] to see the possible values for this operation
  124. *
  125. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  126. * @throws \InvalidArgumentException
  127. * @return \WikipaliApi\Model\GetApiV3TipitakaChapterChannelsBookPara200Response|\WikipaliApi\Model\ProblemDetails
  128. */
  129. public function getApiV3TipitakaChapterChannelsBookPara($book, $para, $per_page = 100, $page = 1, string $contentType = self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'][0])
  130. {
  131. list($response) = $this->getApiV3TipitakaChapterChannelsBookParaWithHttpInfo($book, $para, $per_page, $page, $contentType);
  132. return $response;
  133. }
  134. /**
  135. * Operation getApiV3TipitakaChapterChannelsBookParaWithHttpInfo
  136. *
  137. * 列出一章的 channel
  138. *
  139. * @param int $book 书号 (required)
  140. * @param int $para 章节起始段落号 (required)
  141. * @param int|null $per_page 每页数量,最大 200 (optional, default to 100)
  142. * @param int|null $page 页码 (optional, default to 1)
  143. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'] to see the possible values for this operation
  144. *
  145. * @throws \WikipaliApi\ApiException on non-2xx response or if the response body is not in the expected format
  146. * @throws \InvalidArgumentException
  147. * @return array of \WikipaliApi\Model\GetApiV3TipitakaChapterChannelsBookPara200Response|\WikipaliApi\Model\ProblemDetails, HTTP status code, HTTP response headers (array of strings)
  148. */
  149. public function getApiV3TipitakaChapterChannelsBookParaWithHttpInfo($book, $para, $per_page = 100, $page = 1, string $contentType = self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'][0])
  150. {
  151. $request = $this->getApiV3TipitakaChapterChannelsBookParaRequest($book, $para, $per_page, $page, $contentType);
  152. try {
  153. $options = $this->createHttpClientOption();
  154. try {
  155. $response = $this->client->send($request, $options);
  156. } catch (RequestException $e) {
  157. throw new ApiException(
  158. "[{$e->getCode()}] {$e->getMessage()}",
  159. (int) $e->getCode(),
  160. $e->getResponse() ? $e->getResponse()->getHeaders() : null,
  161. $e->getResponse() ? (string) $e->getResponse()->getBody() : null
  162. );
  163. } catch (ConnectException $e) {
  164. throw new ApiException(
  165. "[{$e->getCode()}] {$e->getMessage()}",
  166. (int) $e->getCode(),
  167. null,
  168. null
  169. );
  170. }
  171. $statusCode = $response->getStatusCode();
  172. switch($statusCode) {
  173. case 200:
  174. return $this->handleResponseWithDataType(
  175. '\WikipaliApi\Model\GetApiV3TipitakaChapterChannelsBookPara200Response',
  176. $request,
  177. $response,
  178. );
  179. case 422:
  180. return $this->handleResponseWithDataType(
  181. '\WikipaliApi\Model\ProblemDetails',
  182. $request,
  183. $response,
  184. );
  185. }
  186. if ($statusCode < 200 || $statusCode > 299) {
  187. throw new ApiException(
  188. sprintf(
  189. '[%d] Error connecting to the API (%s)',
  190. $statusCode,
  191. (string) $request->getUri()
  192. ),
  193. $statusCode,
  194. $response->getHeaders(),
  195. (string) $response->getBody()
  196. );
  197. }
  198. return $this->handleResponseWithDataType(
  199. '\WikipaliApi\Model\GetApiV3TipitakaChapterChannelsBookPara200Response',
  200. $request,
  201. $response,
  202. );
  203. } catch (ApiException $e) {
  204. switch ($e->getCode()) {
  205. case 200:
  206. $data = ObjectSerializer::deserialize(
  207. $e->getResponseBody(),
  208. '\WikipaliApi\Model\GetApiV3TipitakaChapterChannelsBookPara200Response',
  209. $e->getResponseHeaders()
  210. );
  211. $e->setResponseObject($data);
  212. throw $e;
  213. case 422:
  214. $data = ObjectSerializer::deserialize(
  215. $e->getResponseBody(),
  216. '\WikipaliApi\Model\ProblemDetails',
  217. $e->getResponseHeaders()
  218. );
  219. $e->setResponseObject($data);
  220. throw $e;
  221. }
  222. throw $e;
  223. }
  224. }
  225. /**
  226. * Operation getApiV3TipitakaChapterChannelsBookParaAsync
  227. *
  228. * 列出一章的 channel
  229. *
  230. * @param int $book 书号 (required)
  231. * @param int $para 章节起始段落号 (required)
  232. * @param int|null $per_page 每页数量,最大 200 (optional, default to 100)
  233. * @param int|null $page 页码 (optional, default to 1)
  234. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'] to see the possible values for this operation
  235. *
  236. * @throws \InvalidArgumentException
  237. * @return \GuzzleHttp\Promise\PromiseInterface
  238. */
  239. public function getApiV3TipitakaChapterChannelsBookParaAsync($book, $para, $per_page = 100, $page = 1, string $contentType = self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'][0])
  240. {
  241. return $this->getApiV3TipitakaChapterChannelsBookParaAsyncWithHttpInfo($book, $para, $per_page, $page, $contentType)
  242. ->then(
  243. function ($response) {
  244. return $response[0];
  245. }
  246. );
  247. }
  248. /**
  249. * Operation getApiV3TipitakaChapterChannelsBookParaAsyncWithHttpInfo
  250. *
  251. * 列出一章的 channel
  252. *
  253. * @param int $book 书号 (required)
  254. * @param int $para 章节起始段落号 (required)
  255. * @param int|null $per_page 每页数量,最大 200 (optional, default to 100)
  256. * @param int|null $page 页码 (optional, default to 1)
  257. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'] to see the possible values for this operation
  258. *
  259. * @throws \InvalidArgumentException
  260. * @return \GuzzleHttp\Promise\PromiseInterface
  261. */
  262. public function getApiV3TipitakaChapterChannelsBookParaAsyncWithHttpInfo($book, $para, $per_page = 100, $page = 1, string $contentType = self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'][0])
  263. {
  264. $returnType = '\WikipaliApi\Model\GetApiV3TipitakaChapterChannelsBookPara200Response';
  265. $request = $this->getApiV3TipitakaChapterChannelsBookParaRequest($book, $para, $per_page, $page, $contentType);
  266. return $this->client
  267. ->sendAsync($request, $this->createHttpClientOption())
  268. ->then(
  269. function ($response) use ($returnType) {
  270. if ($returnType === '\SplFileObject') {
  271. $content = $response->getBody(); //stream goes to serializer
  272. } else {
  273. $content = (string) $response->getBody();
  274. if ($returnType !== 'string') {
  275. $content = json_decode($content);
  276. }
  277. }
  278. return [
  279. ObjectSerializer::deserialize($content, $returnType, []),
  280. $response->getStatusCode(),
  281. $response->getHeaders()
  282. ];
  283. },
  284. function ($exception) {
  285. $response = $exception->getResponse();
  286. $statusCode = $response->getStatusCode();
  287. throw new ApiException(
  288. sprintf(
  289. '[%d] Error connecting to the API (%s)',
  290. $statusCode,
  291. $exception->getRequest()->getUri()
  292. ),
  293. $statusCode,
  294. $response->getHeaders(),
  295. (string) $response->getBody()
  296. );
  297. }
  298. );
  299. }
  300. /**
  301. * Create request for operation 'getApiV3TipitakaChapterChannelsBookPara'
  302. *
  303. * @param int $book 书号 (required)
  304. * @param int $para 章节起始段落号 (required)
  305. * @param int|null $per_page 每页数量,最大 200 (optional, default to 100)
  306. * @param int|null $page 页码 (optional, default to 1)
  307. * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'] to see the possible values for this operation
  308. *
  309. * @throws \InvalidArgumentException
  310. * @return \GuzzleHttp\Psr7\Request
  311. */
  312. public function getApiV3TipitakaChapterChannelsBookParaRequest($book, $para, $per_page = 100, $page = 1, string $contentType = self::contentTypes['getApiV3TipitakaChapterChannelsBookPara'][0])
  313. {
  314. // verify the required parameter 'book' is set
  315. if ($book === null || (is_array($book) && count($book) === 0)) {
  316. throw new \InvalidArgumentException(
  317. 'Missing the required parameter $book when calling getApiV3TipitakaChapterChannelsBookPara'
  318. );
  319. }
  320. // verify the required parameter 'para' is set
  321. if ($para === null || (is_array($para) && count($para) === 0)) {
  322. throw new \InvalidArgumentException(
  323. 'Missing the required parameter $para when calling getApiV3TipitakaChapterChannelsBookPara'
  324. );
  325. }
  326. $resourcePath = '/v3/tipitaka-chapter-channels/{book}/{para}';
  327. $formParams = [];
  328. $queryParams = [];
  329. $headerParams = [];
  330. $httpBody = '';
  331. $multipart = false;
  332. // query params
  333. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  334. $per_page,
  335. 'per_page', // param base name
  336. 'integer', // openApiType
  337. 'form', // style
  338. true, // explode
  339. false // required
  340. ) ?? []);
  341. // query params
  342. $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
  343. $page,
  344. 'page', // param base name
  345. 'integer', // openApiType
  346. 'form', // style
  347. true, // explode
  348. false // required
  349. ) ?? []);
  350. // path params
  351. if ($book !== null) {
  352. $resourcePath = str_replace(
  353. '{book}',
  354. ObjectSerializer::toPathValue($book),
  355. $resourcePath
  356. );
  357. }
  358. // path params
  359. if ($para !== null) {
  360. $resourcePath = str_replace(
  361. '{para}',
  362. ObjectSerializer::toPathValue($para),
  363. $resourcePath
  364. );
  365. }
  366. $headers = $this->headerSelector->selectHeaders(
  367. ['application/json', 'application/problem+json', ],
  368. $contentType,
  369. $multipart
  370. );
  371. // for model (json/xml)
  372. if (count($formParams) > 0) {
  373. if ($multipart) {
  374. $multipartContents = [];
  375. foreach ($formParams as $formParamName => $formParamValue) {
  376. $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
  377. foreach ($formParamValueItems as $formParamValueItem) {
  378. $multipartContents[] = [
  379. 'name' => $formParamName,
  380. 'contents' => $formParamValueItem
  381. ];
  382. }
  383. }
  384. // for HTTP post (form)
  385. $httpBody = new MultipartStream($multipartContents);
  386. } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
  387. # if Content-Type contains "application/json", json_encode the form parameters
  388. try {
  389. $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR);
  390. } catch (\JsonException $e) {
  391. throw new \InvalidArgumentException('json_encode error: ' . $e->getMessage(), 0, $e);
  392. }
  393. } else {
  394. // for HTTP post (form)
  395. $httpBody = ObjectSerializer::buildQuery($formParams);
  396. }
  397. }
  398. // this endpoint requires Bearer authentication (access token)
  399. if (!empty($this->config->getAccessToken())) {
  400. $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
  401. }
  402. $defaultHeaders = [];
  403. if ($this->config->getUserAgent()) {
  404. $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
  405. }
  406. $headers = array_merge(
  407. $defaultHeaders,
  408. $headerParams,
  409. $headers
  410. );
  411. $operationHost = $this->config->getHost();
  412. $query = ObjectSerializer::buildQuery($queryParams);
  413. return new Request(
  414. 'GET',
  415. $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
  416. $headers,
  417. $httpBody
  418. );
  419. }
  420. /**
  421. * Create http client option
  422. *
  423. * @throws \RuntimeException on file opening failure
  424. * @return array of http client options
  425. */
  426. protected function createHttpClientOption()
  427. {
  428. $options = [];
  429. if ($this->config->getDebug()) {
  430. $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
  431. if (!$options[RequestOptions::DEBUG]) {
  432. throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
  433. }
  434. }
  435. if ($this->config->getCertFile()) {
  436. $options[RequestOptions::CERT] = $this->config->getCertFile();
  437. }
  438. if ($this->config->getKeyFile()) {
  439. $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
  440. }
  441. return $options;
  442. }
  443. private function handleResponseWithDataType(
  444. string $dataType,
  445. RequestInterface $request,
  446. ResponseInterface $response
  447. ): array {
  448. if ($dataType === '\SplFileObject') {
  449. $content = $response->getBody(); //stream goes to serializer
  450. } else {
  451. $content = (string) $response->getBody();
  452. if ($dataType !== 'string') {
  453. try {
  454. $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
  455. } catch (\JsonException $exception) {
  456. throw new ApiException(
  457. sprintf(
  458. 'Error JSON decoding server response (%s)',
  459. $request->getUri()
  460. ),
  461. $response->getStatusCode(),
  462. $response->getHeaders(),
  463. $content
  464. );
  465. }
  466. }
  467. }
  468. return [
  469. ObjectSerializer::deserialize($content, $dataType, []),
  470. $response->getStatusCode(),
  471. $response->getHeaders()
  472. ];
  473. }
  474. private function responseWithinRangeCode(
  475. string $rangeCode,
  476. int $statusCode
  477. ): bool {
  478. $left = (int) ($rangeCode[0].'00');
  479. $right = (int) ($rangeCode[0].'99');
  480. return $statusCode >= $left && $statusCode <= $right;
  481. }
  482. }