2
0

ProblemDetails.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <?php
  2. /**
  3. * ProblemDetails
  4. *
  5. * PHP version 8.1
  6. *
  7. * @category Class
  8. * @package WikipaliApi
  9. * @author OpenAPI Generator team
  10. * @link https://openapi-generator.tech
  11. */
  12. /**
  13. * MINT API
  14. *
  15. * International Academy Of Pali Tipitaka(国际巴利三藏学院) 由 `php openapi/scripts/generate.php` 依据 api-v13 的路由与控制器源码生成。 响应统一封装为 `{ok, message, data}`;`ok=false` 时 `message` 为错误信息。
  16. *
  17. * The version of the OpenAPI document: 2026.9.28
  18. * Generated by: https://openapi-generator.tech
  19. * Generator version: 7.25.0
  20. */
  21. /**
  22. * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
  23. * https://openapi-generator.tech
  24. * Do not edit the class manually.
  25. */
  26. namespace WikipaliApi\Model;
  27. use \ArrayAccess;
  28. use \WikipaliApi\ObjectSerializer;
  29. /**
  30. * ProblemDetails Class Doc Comment
  31. *
  32. * @category Class
  33. * @description RFC 9457 Problem Details,v3 端点的错误响应体。 由 bootstrap/app.php 的异常处理器统一渲染,控制器不自己拼。 media type 是 application/problem+json。
  34. * @package WikipaliApi
  35. * @author OpenAPI Generator team
  36. * @link https://openapi-generator.tech
  37. * @implements \ArrayAccess<string, mixed>
  38. */
  39. class ProblemDetails implements ModelInterface, ArrayAccess, \JsonSerializable
  40. {
  41. public const DISCRIMINATOR = null;
  42. /**
  43. * The original name of the model.
  44. *
  45. * @var string
  46. */
  47. protected static $openAPIModelName = 'ProblemDetails';
  48. /**
  49. * Array of property to type mappings. Used for (de)serialization
  50. *
  51. * @var string[]
  52. */
  53. protected static $openAPITypes = [
  54. 'type' => 'string',
  55. 'title' => 'string',
  56. 'status' => 'int',
  57. 'detail' => 'string',
  58. 'instance' => 'string',
  59. 'errors' => 'array<string,string[]>'
  60. ];
  61. /**
  62. * Array of property to format mappings. Used for (de)serialization
  63. *
  64. * @var string[]
  65. * @phpstan-var array<string, string|null>
  66. * @psalm-var array<string, string|null>
  67. */
  68. protected static $openAPIFormats = [
  69. 'type' => null,
  70. 'title' => null,
  71. 'status' => null,
  72. 'detail' => null,
  73. 'instance' => null,
  74. 'errors' => null
  75. ];
  76. /**
  77. * Array of nullable properties. Used for (de)serialization
  78. *
  79. * @var boolean[]
  80. */
  81. protected static array $openAPINullables = [
  82. 'type' => false,
  83. 'title' => false,
  84. 'status' => false,
  85. 'detail' => false,
  86. 'instance' => false,
  87. 'errors' => false
  88. ];
  89. /**
  90. * If a nullable field gets set to null, insert it here
  91. *
  92. * @var boolean[]
  93. */
  94. protected array $openAPINullablesSetToNull = [];
  95. /**
  96. * Array of property to type mappings. Used for (de)serialization
  97. *
  98. * @return array
  99. */
  100. public static function openAPITypes()
  101. {
  102. return self::$openAPITypes;
  103. }
  104. /**
  105. * Array of property to format mappings. Used for (de)serialization
  106. *
  107. * @return array
  108. */
  109. public static function openAPIFormats()
  110. {
  111. return self::$openAPIFormats;
  112. }
  113. /**
  114. * Array of nullable properties
  115. *
  116. * @return array
  117. */
  118. protected static function openAPINullables(): array
  119. {
  120. return self::$openAPINullables;
  121. }
  122. /**
  123. * Array of nullable field names deliberately set to null
  124. *
  125. * @return boolean[]
  126. */
  127. private function getOpenAPINullablesSetToNull(): array
  128. {
  129. return $this->openAPINullablesSetToNull;
  130. }
  131. /**
  132. * Setter - Array of nullable field names deliberately set to null
  133. *
  134. * @param boolean[] $openAPINullablesSetToNull
  135. */
  136. private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
  137. {
  138. $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
  139. }
  140. /**
  141. * Checks if a property is nullable
  142. *
  143. * @param string $property
  144. * @return bool
  145. */
  146. public static function isNullable(string $property): bool
  147. {
  148. return self::openAPINullables()[$property] ?? false;
  149. }
  150. /**
  151. * Checks if a nullable property is set to null.
  152. *
  153. * @param string $property
  154. * @return bool
  155. */
  156. public function isNullableSetToNull(string $property): bool
  157. {
  158. return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
  159. }
  160. /**
  161. * Array of attributes where the key is the local name,
  162. * and the value is the original name
  163. *
  164. * @var string[]
  165. */
  166. protected static $attributeMap = [
  167. 'type' => 'type',
  168. 'title' => 'title',
  169. 'status' => 'status',
  170. 'detail' => 'detail',
  171. 'instance' => 'instance',
  172. 'errors' => 'errors'
  173. ];
  174. /**
  175. * Array of attributes to setter functions (for deserialization of responses)
  176. *
  177. * @var string[]
  178. */
  179. protected static $setters = [
  180. 'type' => 'setType',
  181. 'title' => 'setTitle',
  182. 'status' => 'setStatus',
  183. 'detail' => 'setDetail',
  184. 'instance' => 'setInstance',
  185. 'errors' => 'setErrors'
  186. ];
  187. /**
  188. * Array of attributes to getter functions (for serialization of requests)
  189. *
  190. * @var string[]
  191. */
  192. protected static $getters = [
  193. 'type' => 'getType',
  194. 'title' => 'getTitle',
  195. 'status' => 'getStatus',
  196. 'detail' => 'getDetail',
  197. 'instance' => 'getInstance',
  198. 'errors' => 'getErrors'
  199. ];
  200. /**
  201. * Array of attributes where the key is the local name,
  202. * and the value is the original name
  203. *
  204. * @return array
  205. */
  206. public static function attributeMap()
  207. {
  208. return self::$attributeMap;
  209. }
  210. /**
  211. * Array of attributes to setter functions (for deserialization of responses)
  212. *
  213. * @return array
  214. */
  215. public static function setters()
  216. {
  217. return self::$setters;
  218. }
  219. /**
  220. * Array of attributes to getter functions (for serialization of requests)
  221. *
  222. * @return array
  223. */
  224. public static function getters()
  225. {
  226. return self::$getters;
  227. }
  228. /**
  229. * The original name of the model.
  230. *
  231. * @return string
  232. */
  233. public function getModelName()
  234. {
  235. return self::$openAPIModelName;
  236. }
  237. /**
  238. * Associative array for storing property values
  239. *
  240. * @var mixed[]
  241. */
  242. protected $container = [];
  243. /**
  244. * Constructor
  245. *
  246. * @param mixed[]|null $data Associated array of property values
  247. * initializing the model
  248. */
  249. public function __construct(?array $data = null)
  250. {
  251. $this->setIfExists('type', $data ?? [], null);
  252. $this->setIfExists('title', $data ?? [], null);
  253. $this->setIfExists('status', $data ?? [], null);
  254. $this->setIfExists('detail', $data ?? [], null);
  255. $this->setIfExists('instance', $data ?? [], null);
  256. $this->setIfExists('errors', $data ?? [], null);
  257. }
  258. /**
  259. * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
  260. * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
  261. * $this->openAPINullablesSetToNull array
  262. *
  263. * @param string $variableName
  264. * @param array $fields
  265. * @param mixed $defaultValue
  266. */
  267. private function setIfExists(string $variableName, array $fields, $defaultValue): void
  268. {
  269. if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
  270. $this->openAPINullablesSetToNull[] = $variableName;
  271. }
  272. $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
  273. }
  274. /**
  275. * Show all the invalid properties with reasons.
  276. *
  277. * @return array invalid properties with reasons
  278. */
  279. public function listInvalidProperties()
  280. {
  281. $invalidProperties = [];
  282. if ($this->container['type'] === null) {
  283. $invalidProperties[] = "'type' can't be null";
  284. }
  285. if ($this->container['title'] === null) {
  286. $invalidProperties[] = "'title' can't be null";
  287. }
  288. if ($this->container['status'] === null) {
  289. $invalidProperties[] = "'status' can't be null";
  290. }
  291. return $invalidProperties;
  292. }
  293. /**
  294. * Validate all the properties in the model
  295. * return true if all passed
  296. *
  297. * @return bool True if all properties are valid
  298. */
  299. public function valid()
  300. {
  301. return count($this->listInvalidProperties()) === 0;
  302. }
  303. /**
  304. * Gets type
  305. *
  306. * @return string
  307. */
  308. public function getType()
  309. {
  310. return $this->container['type'];
  311. }
  312. /**
  313. * Sets type
  314. *
  315. * @param string $type 问题类型标识,形如 urn:problem:not-found
  316. *
  317. * @return self
  318. */
  319. public function setType($type)
  320. {
  321. if (is_null($type)) {
  322. throw new \InvalidArgumentException('non-nullable type cannot be null');
  323. }
  324. $this->container['type'] = $type;
  325. return $this;
  326. }
  327. /**
  328. * Gets title
  329. *
  330. * @return string
  331. */
  332. public function getTitle()
  333. {
  334. return $this->container['title'];
  335. }
  336. /**
  337. * Sets title
  338. *
  339. * @param string $title 稳定的英文摘要,同类问题恒定,供机器识别
  340. *
  341. * @return self
  342. */
  343. public function setTitle($title)
  344. {
  345. if (is_null($title)) {
  346. throw new \InvalidArgumentException('non-nullable title cannot be null');
  347. }
  348. $this->container['title'] = $title;
  349. return $this;
  350. }
  351. /**
  352. * Gets status
  353. *
  354. * @return int
  355. */
  356. public function getStatus()
  357. {
  358. return $this->container['status'];
  359. }
  360. /**
  361. * Sets status
  362. *
  363. * @param int $status status
  364. *
  365. * @return self
  366. */
  367. public function setStatus($status)
  368. {
  369. if (is_null($status)) {
  370. throw new \InvalidArgumentException('non-nullable status cannot be null');
  371. }
  372. $this->container['status'] = $status;
  373. return $this;
  374. }
  375. /**
  376. * Gets detail
  377. *
  378. * @return string|null
  379. */
  380. public function getDetail()
  381. {
  382. return $this->container['detail'];
  383. }
  384. /**
  385. * Sets detail
  386. *
  387. * @param string|null $detail 面向人的文案,已本地化;5xx 在生产环境会省略以免泄露内部信息
  388. *
  389. * @return self
  390. */
  391. public function setDetail($detail)
  392. {
  393. if (is_null($detail)) {
  394. throw new \InvalidArgumentException('non-nullable detail cannot be null');
  395. }
  396. $this->container['detail'] = $detail;
  397. return $this;
  398. }
  399. /**
  400. * Gets instance
  401. *
  402. * @return string|null
  403. */
  404. public function getInstance()
  405. {
  406. return $this->container['instance'];
  407. }
  408. /**
  409. * Sets instance
  410. *
  411. * @param string|null $instance 出问题的请求 URI
  412. *
  413. * @return self
  414. */
  415. public function setInstance($instance)
  416. {
  417. if (is_null($instance)) {
  418. throw new \InvalidArgumentException('non-nullable instance cannot be null');
  419. }
  420. $this->container['instance'] = $instance;
  421. return $this;
  422. }
  423. /**
  424. * Gets errors
  425. *
  426. * @return array<string,string[]>|null
  427. */
  428. public function getErrors()
  429. {
  430. return $this->container['errors'];
  431. }
  432. /**
  433. * Sets errors
  434. *
  435. * @param array<string,string[]>|null $errors 字段级校验错误,仅 422 时出现
  436. *
  437. * @return self
  438. */
  439. public function setErrors($errors)
  440. {
  441. if (is_null($errors)) {
  442. throw new \InvalidArgumentException('non-nullable errors cannot be null');
  443. }
  444. $this->container['errors'] = $errors;
  445. return $this;
  446. }
  447. /**
  448. * Returns true if offset exists. False otherwise.
  449. *
  450. * @param integer|string $offset Offset
  451. *
  452. * @return boolean
  453. */
  454. public function offsetExists(mixed $offset): bool
  455. {
  456. return isset($this->container[$offset]);
  457. }
  458. /**
  459. * Gets offset.
  460. *
  461. * @param integer|string $offset Offset
  462. *
  463. * @return mixed|null
  464. */
  465. #[\ReturnTypeWillChange]
  466. public function offsetGet(mixed $offset)
  467. {
  468. return $this->container[$offset] ?? null;
  469. }
  470. /**
  471. * Sets value based on offset.
  472. *
  473. * @param int|null $offset Offset
  474. * @param mixed $value Value to be set
  475. *
  476. * @return void
  477. */
  478. public function offsetSet($offset, $value): void
  479. {
  480. if (is_null($offset)) {
  481. $this->container[] = $value;
  482. } else {
  483. $this->container[$offset] = $value;
  484. }
  485. }
  486. /**
  487. * Unsets offset.
  488. *
  489. * @param integer|string $offset Offset
  490. *
  491. * @return void
  492. */
  493. public function offsetUnset(mixed $offset): void
  494. {
  495. unset($this->container[$offset]);
  496. }
  497. /**
  498. * Serializes the object to a value that can be serialized natively by json_encode().
  499. * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
  500. *
  501. * @return mixed Returns data which can be serialized by json_encode(), which is a value
  502. * of any type other than a resource.
  503. */
  504. #[\ReturnTypeWillChange]
  505. public function jsonSerialize()
  506. {
  507. return ObjectSerializer::sanitizeForSerialization($this);
  508. }
  509. /**
  510. * Gets the string presentation of the object
  511. *
  512. * @return string
  513. */
  514. public function __toString()
  515. {
  516. return json_encode(
  517. ObjectSerializer::sanitizeForSerialization($this),
  518. JSON_PRETTY_PRINT
  519. );
  520. }
  521. /**
  522. * Gets a header-safe presentation of the object
  523. *
  524. * @return string
  525. */
  526. public function toHeaderValue()
  527. {
  528. return json_encode(ObjectSerializer::sanitizeForSerialization($this));
  529. }
  530. }