PostApiV3MarkupPreviewsRequest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <?php
  2. /**
  3. * PostApiV3MarkupPreviewsRequest
  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: 1.0.0
  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. * PostApiV3MarkupPreviewsRequest Class Doc Comment
  31. *
  32. * @category Class
  33. * @package WikipaliApi
  34. * @author OpenAPI Generator team
  35. * @link https://openapi-generator.tech
  36. * @implements \ArrayAccess<string, mixed>
  37. */
  38. class PostApiV3MarkupPreviewsRequest implements ModelInterface, ArrayAccess, \JsonSerializable
  39. {
  40. public const DISCRIMINATOR = null;
  41. /**
  42. * The original name of the model.
  43. *
  44. * @var string
  45. */
  46. protected static $openAPIModelName = 'post_api_v3_markup_previews_request';
  47. /**
  48. * Array of property to type mappings. Used for (de)serialization
  49. *
  50. * @var string[]
  51. */
  52. protected static $openAPITypes = [
  53. 'content' => 'string',
  54. 'content_type' => 'string',
  55. 'channels' => 'string[]',
  56. 'lang' => 'string'
  57. ];
  58. /**
  59. * Array of property to format mappings. Used for (de)serialization
  60. *
  61. * @var string[]
  62. * @phpstan-var array<string, string|null>
  63. * @psalm-var array<string, string|null>
  64. */
  65. protected static $openAPIFormats = [
  66. 'content' => null,
  67. 'content_type' => null,
  68. 'channels' => null,
  69. 'lang' => null
  70. ];
  71. /**
  72. * Array of nullable properties. Used for (de)serialization
  73. *
  74. * @var boolean[]
  75. */
  76. protected static array $openAPINullables = [
  77. 'content' => false,
  78. 'content_type' => false,
  79. 'channels' => false,
  80. 'lang' => false
  81. ];
  82. /**
  83. * If a nullable field gets set to null, insert it here
  84. *
  85. * @var boolean[]
  86. */
  87. protected array $openAPINullablesSetToNull = [];
  88. /**
  89. * Array of property to type mappings. Used for (de)serialization
  90. *
  91. * @return array
  92. */
  93. public static function openAPITypes()
  94. {
  95. return self::$openAPITypes;
  96. }
  97. /**
  98. * Array of property to format mappings. Used for (de)serialization
  99. *
  100. * @return array
  101. */
  102. public static function openAPIFormats()
  103. {
  104. return self::$openAPIFormats;
  105. }
  106. /**
  107. * Array of nullable properties
  108. *
  109. * @return array
  110. */
  111. protected static function openAPINullables(): array
  112. {
  113. return self::$openAPINullables;
  114. }
  115. /**
  116. * Array of nullable field names deliberately set to null
  117. *
  118. * @return boolean[]
  119. */
  120. private function getOpenAPINullablesSetToNull(): array
  121. {
  122. return $this->openAPINullablesSetToNull;
  123. }
  124. /**
  125. * Setter - Array of nullable field names deliberately set to null
  126. *
  127. * @param boolean[] $openAPINullablesSetToNull
  128. */
  129. private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
  130. {
  131. $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
  132. }
  133. /**
  134. * Checks if a property is nullable
  135. *
  136. * @param string $property
  137. * @return bool
  138. */
  139. public static function isNullable(string $property): bool
  140. {
  141. return self::openAPINullables()[$property] ?? false;
  142. }
  143. /**
  144. * Checks if a nullable property is set to null.
  145. *
  146. * @param string $property
  147. * @return bool
  148. */
  149. public function isNullableSetToNull(string $property): bool
  150. {
  151. return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
  152. }
  153. /**
  154. * Array of attributes where the key is the local name,
  155. * and the value is the original name
  156. *
  157. * @var string[]
  158. */
  159. protected static $attributeMap = [
  160. 'content' => 'content',
  161. 'content_type' => 'content_type',
  162. 'channels' => 'channels',
  163. 'lang' => 'lang'
  164. ];
  165. /**
  166. * Array of attributes to setter functions (for deserialization of responses)
  167. *
  168. * @var string[]
  169. */
  170. protected static $setters = [
  171. 'content' => 'setContent',
  172. 'content_type' => 'setContentType',
  173. 'channels' => 'setChannels',
  174. 'lang' => 'setLang'
  175. ];
  176. /**
  177. * Array of attributes to getter functions (for serialization of requests)
  178. *
  179. * @var string[]
  180. */
  181. protected static $getters = [
  182. 'content' => 'getContent',
  183. 'content_type' => 'getContentType',
  184. 'channels' => 'getChannels',
  185. 'lang' => 'getLang'
  186. ];
  187. /**
  188. * Array of attributes where the key is the local name,
  189. * and the value is the original name
  190. *
  191. * @return array
  192. */
  193. public static function attributeMap()
  194. {
  195. return self::$attributeMap;
  196. }
  197. /**
  198. * Array of attributes to setter functions (for deserialization of responses)
  199. *
  200. * @return array
  201. */
  202. public static function setters()
  203. {
  204. return self::$setters;
  205. }
  206. /**
  207. * Array of attributes to getter functions (for serialization of requests)
  208. *
  209. * @return array
  210. */
  211. public static function getters()
  212. {
  213. return self::$getters;
  214. }
  215. /**
  216. * The original name of the model.
  217. *
  218. * @return string
  219. */
  220. public function getModelName()
  221. {
  222. return self::$openAPIModelName;
  223. }
  224. public const CONTENT_TYPE_MARKDOWN = 'markdown';
  225. public const CONTENT_TYPE_MARKDOWN_E2 = 'markdown-e2';
  226. /**
  227. * Gets allowable values of the enum
  228. *
  229. * @return string[]
  230. */
  231. public function getContentTypeAllowableValues()
  232. {
  233. return [
  234. self::CONTENT_TYPE_MARKDOWN,
  235. self::CONTENT_TYPE_MARKDOWN_E2,
  236. ];
  237. }
  238. /**
  239. * Associative array for storing property values
  240. *
  241. * @var mixed[]
  242. */
  243. protected $container = [];
  244. /**
  245. * Constructor
  246. *
  247. * @param mixed[]|null $data Associated array of property values
  248. * initializing the model
  249. */
  250. public function __construct(?array $data = null)
  251. {
  252. $this->setIfExists('content', $data ?? [], null);
  253. $this->setIfExists('content_type', $data ?? [], 'markdown');
  254. $this->setIfExists('channels', $data ?? [], null);
  255. $this->setIfExists('lang', $data ?? [], null);
  256. }
  257. /**
  258. * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
  259. * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
  260. * $this->openAPINullablesSetToNull array
  261. *
  262. * @param string $variableName
  263. * @param array $fields
  264. * @param mixed $defaultValue
  265. */
  266. private function setIfExists(string $variableName, array $fields, $defaultValue): void
  267. {
  268. if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
  269. $this->openAPINullablesSetToNull[] = $variableName;
  270. }
  271. $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
  272. }
  273. /**
  274. * Show all the invalid properties with reasons.
  275. *
  276. * @return array invalid properties with reasons
  277. */
  278. public function listInvalidProperties()
  279. {
  280. $invalidProperties = [];
  281. if ($this->container['content'] === null) {
  282. $invalidProperties[] = "'content' can't be null";
  283. }
  284. $allowedValues = $this->getContentTypeAllowableValues();
  285. if (!is_null($this->container['content_type']) && !in_array($this->container['content_type'], $allowedValues, true)) {
  286. $invalidProperties[] = sprintf(
  287. "invalid value '%s' for 'content_type', must be one of '%s'",
  288. $this->container['content_type'],
  289. implode("', '", $allowedValues)
  290. );
  291. }
  292. return $invalidProperties;
  293. }
  294. /**
  295. * Validate all the properties in the model
  296. * return true if all passed
  297. *
  298. * @return bool True if all properties are valid
  299. */
  300. public function valid()
  301. {
  302. return count($this->listInvalidProperties()) === 0;
  303. }
  304. /**
  305. * Gets content
  306. *
  307. * @return string
  308. */
  309. public function getContent()
  310. {
  311. return $this->container['content'];
  312. }
  313. /**
  314. * Sets content
  315. *
  316. * @param string $content 源码,最多 20000 字
  317. *
  318. * @return self
  319. */
  320. public function setContent($content)
  321. {
  322. if (is_null($content)) {
  323. throw new \InvalidArgumentException('non-nullable content cannot be null');
  324. }
  325. $this->container['content'] = $content;
  326. return $this;
  327. }
  328. /**
  329. * Gets content_type
  330. *
  331. * @return string|null
  332. */
  333. public function getContentType()
  334. {
  335. return $this->container['content_type'];
  336. }
  337. /**
  338. * Sets content_type
  339. *
  340. * @param string|null $content_type 方言
  341. *
  342. * @return self
  343. */
  344. public function setContentType($content_type)
  345. {
  346. if (is_null($content_type)) {
  347. throw new \InvalidArgumentException('non-nullable content_type cannot be null');
  348. }
  349. $allowedValues = $this->getContentTypeAllowableValues();
  350. if (!in_array($content_type, $allowedValues, true)) {
  351. throw new \InvalidArgumentException(
  352. sprintf(
  353. "Invalid value '%s' for 'content_type', must be one of '%s'",
  354. $content_type,
  355. implode("', '", $allowedValues)
  356. )
  357. );
  358. }
  359. $this->container['content_type'] = $content_type;
  360. return $this;
  361. }
  362. /**
  363. * Gets channels
  364. *
  365. * @return string[]|null
  366. */
  367. public function getChannels()
  368. {
  369. return $this->container['channels'];
  370. }
  371. /**
  372. * Sets channels
  373. *
  374. * @param string[]|null $channels 内容所属的 channel uid,最多 10 个
  375. *
  376. * @return self
  377. */
  378. public function setChannels($channels)
  379. {
  380. if (is_null($channels)) {
  381. throw new \InvalidArgumentException('non-nullable channels cannot be null');
  382. }
  383. $this->container['channels'] = $channels;
  384. return $this;
  385. }
  386. /**
  387. * Gets lang
  388. *
  389. * @return string|null
  390. */
  391. public function getLang()
  392. {
  393. return $this->container['lang'];
  394. }
  395. /**
  396. * Sets lang
  397. *
  398. * @param string|null $lang 没给 channel 时用的语言,如 zh-Hans。缺省用界面语言(Accept-Language 协商的结果)
  399. *
  400. * @return self
  401. */
  402. public function setLang($lang)
  403. {
  404. if (is_null($lang)) {
  405. throw new \InvalidArgumentException('non-nullable lang cannot be null');
  406. }
  407. $this->container['lang'] = $lang;
  408. return $this;
  409. }
  410. /**
  411. * Returns true if offset exists. False otherwise.
  412. *
  413. * @param integer|string $offset Offset
  414. *
  415. * @return boolean
  416. */
  417. public function offsetExists(mixed $offset): bool
  418. {
  419. return isset($this->container[$offset]);
  420. }
  421. /**
  422. * Gets offset.
  423. *
  424. * @param integer|string $offset Offset
  425. *
  426. * @return mixed|null
  427. */
  428. #[\ReturnTypeWillChange]
  429. public function offsetGet(mixed $offset)
  430. {
  431. return $this->container[$offset] ?? null;
  432. }
  433. /**
  434. * Sets value based on offset.
  435. *
  436. * @param int|null $offset Offset
  437. * @param mixed $value Value to be set
  438. *
  439. * @return void
  440. */
  441. public function offsetSet($offset, $value): void
  442. {
  443. if (is_null($offset)) {
  444. $this->container[] = $value;
  445. } else {
  446. $this->container[$offset] = $value;
  447. }
  448. }
  449. /**
  450. * Unsets offset.
  451. *
  452. * @param integer|string $offset Offset
  453. *
  454. * @return void
  455. */
  456. public function offsetUnset(mixed $offset): void
  457. {
  458. unset($this->container[$offset]);
  459. }
  460. /**
  461. * Serializes the object to a value that can be serialized natively by json_encode().
  462. * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
  463. *
  464. * @return mixed Returns data which can be serialized by json_encode(), which is a value
  465. * of any type other than a resource.
  466. */
  467. #[\ReturnTypeWillChange]
  468. public function jsonSerialize()
  469. {
  470. return ObjectSerializer::sanitizeForSerialization($this);
  471. }
  472. /**
  473. * Gets the string presentation of the object
  474. *
  475. * @return string
  476. */
  477. public function __toString()
  478. {
  479. return json_encode(
  480. ObjectSerializer::sanitizeForSerialization($this),
  481. JSON_PRETTY_PRINT
  482. );
  483. }
  484. /**
  485. * Gets a header-safe presentation of the object
  486. *
  487. * @return string
  488. */
  489. public function toHeaderValue()
  490. {
  491. return json_encode(ObjectSerializer::sanitizeForSerialization($this));
  492. }
  493. }