MarkupNode.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. /**
  3. * MarkupNode
  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. * MarkupNode Class Doc Comment
  31. *
  32. * @category Class
  33. * @description 正文(markdown + 模板)渲染后的节点树,由 App\\Services\\Markup 生成。 三种节点:text 纯文本(前端作为 React 文本节点,自动转义);el HTML 元素(tag 与 attrs 已过白名单); tpl 模板(name 是前端组件名,props 随模板而定,props 里嵌套的内容也是节点数组)。
  34. * @package WikipaliApi
  35. * @author OpenAPI Generator team
  36. * @link https://openapi-generator.tech
  37. * @implements \ArrayAccess<string, mixed>
  38. */
  39. class MarkupNode 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 = 'MarkupNode';
  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. 'value' => 'string',
  56. 'tag' => 'string',
  57. 'attrs' => 'array<string,string>',
  58. 'children' => '\WikipaliApi\Model\MarkupNode[]',
  59. 'name' => 'string',
  60. 'props' => 'array<string,mixed>'
  61. ];
  62. /**
  63. * Array of property to format mappings. Used for (de)serialization
  64. *
  65. * @var string[]
  66. * @phpstan-var array<string, string|null>
  67. * @psalm-var array<string, string|null>
  68. */
  69. protected static $openAPIFormats = [
  70. 'type' => null,
  71. 'value' => null,
  72. 'tag' => null,
  73. 'attrs' => null,
  74. 'children' => null,
  75. 'name' => null,
  76. 'props' => null
  77. ];
  78. /**
  79. * Array of nullable properties. Used for (de)serialization
  80. *
  81. * @var boolean[]
  82. */
  83. protected static array $openAPINullables = [
  84. 'type' => false,
  85. 'value' => false,
  86. 'tag' => false,
  87. 'attrs' => false,
  88. 'children' => false,
  89. 'name' => false,
  90. 'props' => false
  91. ];
  92. /**
  93. * If a nullable field gets set to null, insert it here
  94. *
  95. * @var boolean[]
  96. */
  97. protected array $openAPINullablesSetToNull = [];
  98. /**
  99. * Array of property to type mappings. Used for (de)serialization
  100. *
  101. * @return array
  102. */
  103. public static function openAPITypes()
  104. {
  105. return self::$openAPITypes;
  106. }
  107. /**
  108. * Array of property to format mappings. Used for (de)serialization
  109. *
  110. * @return array
  111. */
  112. public static function openAPIFormats()
  113. {
  114. return self::$openAPIFormats;
  115. }
  116. /**
  117. * Array of nullable properties
  118. *
  119. * @return array
  120. */
  121. protected static function openAPINullables(): array
  122. {
  123. return self::$openAPINullables;
  124. }
  125. /**
  126. * Array of nullable field names deliberately set to null
  127. *
  128. * @return boolean[]
  129. */
  130. private function getOpenAPINullablesSetToNull(): array
  131. {
  132. return $this->openAPINullablesSetToNull;
  133. }
  134. /**
  135. * Setter - Array of nullable field names deliberately set to null
  136. *
  137. * @param boolean[] $openAPINullablesSetToNull
  138. */
  139. private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
  140. {
  141. $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
  142. }
  143. /**
  144. * Checks if a property is nullable
  145. *
  146. * @param string $property
  147. * @return bool
  148. */
  149. public static function isNullable(string $property): bool
  150. {
  151. return self::openAPINullables()[$property] ?? false;
  152. }
  153. /**
  154. * Checks if a nullable property is set to null.
  155. *
  156. * @param string $property
  157. * @return bool
  158. */
  159. public function isNullableSetToNull(string $property): bool
  160. {
  161. return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
  162. }
  163. /**
  164. * Array of attributes where the key is the local name,
  165. * and the value is the original name
  166. *
  167. * @var string[]
  168. */
  169. protected static $attributeMap = [
  170. 'type' => 'type',
  171. 'value' => 'value',
  172. 'tag' => 'tag',
  173. 'attrs' => 'attrs',
  174. 'children' => 'children',
  175. 'name' => 'name',
  176. 'props' => 'props'
  177. ];
  178. /**
  179. * Array of attributes to setter functions (for deserialization of responses)
  180. *
  181. * @var string[]
  182. */
  183. protected static $setters = [
  184. 'type' => 'setType',
  185. 'value' => 'setValue',
  186. 'tag' => 'setTag',
  187. 'attrs' => 'setAttrs',
  188. 'children' => 'setChildren',
  189. 'name' => 'setName',
  190. 'props' => 'setProps'
  191. ];
  192. /**
  193. * Array of attributes to getter functions (for serialization of requests)
  194. *
  195. * @var string[]
  196. */
  197. protected static $getters = [
  198. 'type' => 'getType',
  199. 'value' => 'getValue',
  200. 'tag' => 'getTag',
  201. 'attrs' => 'getAttrs',
  202. 'children' => 'getChildren',
  203. 'name' => 'getName',
  204. 'props' => 'getProps'
  205. ];
  206. /**
  207. * Array of attributes where the key is the local name,
  208. * and the value is the original name
  209. *
  210. * @return array
  211. */
  212. public static function attributeMap()
  213. {
  214. return self::$attributeMap;
  215. }
  216. /**
  217. * Array of attributes to setter functions (for deserialization of responses)
  218. *
  219. * @return array
  220. */
  221. public static function setters()
  222. {
  223. return self::$setters;
  224. }
  225. /**
  226. * Array of attributes to getter functions (for serialization of requests)
  227. *
  228. * @return array
  229. */
  230. public static function getters()
  231. {
  232. return self::$getters;
  233. }
  234. /**
  235. * The original name of the model.
  236. *
  237. * @return string
  238. */
  239. public function getModelName()
  240. {
  241. return self::$openAPIModelName;
  242. }
  243. public const TYPE_TEXT = 'text';
  244. public const TYPE_EL = 'el';
  245. public const TYPE_TPL = 'tpl';
  246. /**
  247. * Gets allowable values of the enum
  248. *
  249. * @return string[]
  250. */
  251. public function getTypeAllowableValues()
  252. {
  253. return [
  254. self::TYPE_TEXT,
  255. self::TYPE_EL,
  256. self::TYPE_TPL,
  257. ];
  258. }
  259. /**
  260. * Associative array for storing property values
  261. *
  262. * @var mixed[]
  263. */
  264. protected $container = [];
  265. /**
  266. * Constructor
  267. *
  268. * @param mixed[]|null $data Associated array of property values
  269. * initializing the model
  270. */
  271. public function __construct(?array $data = null)
  272. {
  273. $this->setIfExists('type', $data ?? [], null);
  274. $this->setIfExists('value', $data ?? [], null);
  275. $this->setIfExists('tag', $data ?? [], null);
  276. $this->setIfExists('attrs', $data ?? [], null);
  277. $this->setIfExists('children', $data ?? [], null);
  278. $this->setIfExists('name', $data ?? [], null);
  279. $this->setIfExists('props', $data ?? [], null);
  280. }
  281. /**
  282. * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
  283. * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
  284. * $this->openAPINullablesSetToNull array
  285. *
  286. * @param string $variableName
  287. * @param array $fields
  288. * @param mixed $defaultValue
  289. */
  290. private function setIfExists(string $variableName, array $fields, $defaultValue): void
  291. {
  292. if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
  293. $this->openAPINullablesSetToNull[] = $variableName;
  294. }
  295. $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
  296. }
  297. /**
  298. * Show all the invalid properties with reasons.
  299. *
  300. * @return array invalid properties with reasons
  301. */
  302. public function listInvalidProperties()
  303. {
  304. $invalidProperties = [];
  305. if ($this->container['type'] === null) {
  306. $invalidProperties[] = "'type' can't be null";
  307. }
  308. $allowedValues = $this->getTypeAllowableValues();
  309. if (!is_null($this->container['type']) && !in_array($this->container['type'], $allowedValues, true)) {
  310. $invalidProperties[] = sprintf(
  311. "invalid value '%s' for 'type', must be one of '%s'",
  312. $this->container['type'],
  313. implode("', '", $allowedValues)
  314. );
  315. }
  316. if ($this->container['value'] === null) {
  317. $invalidProperties[] = "'value' can't be null";
  318. }
  319. if ($this->container['tag'] === null) {
  320. $invalidProperties[] = "'tag' can't be null";
  321. }
  322. if ($this->container['children'] === null) {
  323. $invalidProperties[] = "'children' can't be null";
  324. }
  325. if ($this->container['name'] === null) {
  326. $invalidProperties[] = "'name' can't be null";
  327. }
  328. if ($this->container['props'] === null) {
  329. $invalidProperties[] = "'props' can't be null";
  330. }
  331. return $invalidProperties;
  332. }
  333. /**
  334. * Validate all the properties in the model
  335. * return true if all passed
  336. *
  337. * @return bool True if all properties are valid
  338. */
  339. public function valid()
  340. {
  341. return count($this->listInvalidProperties()) === 0;
  342. }
  343. /**
  344. * Gets type
  345. *
  346. * @return string
  347. */
  348. public function getType()
  349. {
  350. return $this->container['type'];
  351. }
  352. /**
  353. * Sets type
  354. *
  355. * @param string $type type
  356. *
  357. * @return self
  358. */
  359. public function setType($type)
  360. {
  361. if (is_null($type)) {
  362. throw new \InvalidArgumentException('non-nullable type cannot be null');
  363. }
  364. $allowedValues = $this->getTypeAllowableValues();
  365. if (!in_array($type, $allowedValues, true)) {
  366. throw new \InvalidArgumentException(
  367. sprintf(
  368. "Invalid value '%s' for 'type', must be one of '%s'",
  369. $type,
  370. implode("', '", $allowedValues)
  371. )
  372. );
  373. }
  374. $this->container['type'] = $type;
  375. return $this;
  376. }
  377. /**
  378. * Gets value
  379. *
  380. * @return string
  381. */
  382. public function getValue()
  383. {
  384. return $this->container['value'];
  385. }
  386. /**
  387. * Sets value
  388. *
  389. * @param string $value value
  390. *
  391. * @return self
  392. */
  393. public function setValue($value)
  394. {
  395. if (is_null($value)) {
  396. throw new \InvalidArgumentException('non-nullable value cannot be null');
  397. }
  398. $this->container['value'] = $value;
  399. return $this;
  400. }
  401. /**
  402. * Gets tag
  403. *
  404. * @return string
  405. */
  406. public function getTag()
  407. {
  408. return $this->container['tag'];
  409. }
  410. /**
  411. * Sets tag
  412. *
  413. * @param string $tag 白名单内的 HTML 标签名(小写)
  414. *
  415. * @return self
  416. */
  417. public function setTag($tag)
  418. {
  419. if (is_null($tag)) {
  420. throw new \InvalidArgumentException('non-nullable tag cannot be null');
  421. }
  422. $this->container['tag'] = $tag;
  423. return $this;
  424. }
  425. /**
  426. * Gets attrs
  427. *
  428. * @return array<string,string>|null
  429. */
  430. public function getAttrs()
  431. {
  432. return $this->container['attrs'];
  433. }
  434. /**
  435. * Sets attrs
  436. *
  437. * @param array<string,string>|null $attrs attrs
  438. *
  439. * @return self
  440. */
  441. public function setAttrs($attrs)
  442. {
  443. if (is_null($attrs)) {
  444. throw new \InvalidArgumentException('non-nullable attrs cannot be null');
  445. }
  446. $this->container['attrs'] = $attrs;
  447. return $this;
  448. }
  449. /**
  450. * Gets children
  451. *
  452. * @return \WikipaliApi\Model\MarkupNode[]
  453. */
  454. public function getChildren()
  455. {
  456. return $this->container['children'];
  457. }
  458. /**
  459. * Sets children
  460. *
  461. * @param \WikipaliApi\Model\MarkupNode[] $children children
  462. *
  463. * @return self
  464. */
  465. public function setChildren($children)
  466. {
  467. if (is_null($children)) {
  468. throw new \InvalidArgumentException('non-nullable children cannot be null');
  469. }
  470. $this->container['children'] = $children;
  471. return $this;
  472. }
  473. /**
  474. * Gets name
  475. *
  476. * @return string
  477. */
  478. public function getName()
  479. {
  480. return $this->container['name'];
  481. }
  482. /**
  483. * Sets name
  484. *
  485. * @param string $name 前端组件名:term、note、sentread、sentedit、quote、quote-link、mermaid…
  486. *
  487. * @return self
  488. */
  489. public function setName($name)
  490. {
  491. if (is_null($name)) {
  492. throw new \InvalidArgumentException('non-nullable name cannot be null');
  493. }
  494. $this->container['name'] = $name;
  495. return $this;
  496. }
  497. /**
  498. * Gets props
  499. *
  500. * @return array<string,mixed>
  501. */
  502. public function getProps()
  503. {
  504. return $this->container['props'];
  505. }
  506. /**
  507. * Sets props
  508. *
  509. * @param array<string,mixed> $props props
  510. *
  511. * @return self
  512. */
  513. public function setProps($props)
  514. {
  515. if (is_null($props)) {
  516. throw new \InvalidArgumentException('non-nullable props cannot be null');
  517. }
  518. $this->container['props'] = $props;
  519. return $this;
  520. }
  521. /**
  522. * Returns true if offset exists. False otherwise.
  523. *
  524. * @param integer|string $offset Offset
  525. *
  526. * @return boolean
  527. */
  528. public function offsetExists(mixed $offset): bool
  529. {
  530. return isset($this->container[$offset]);
  531. }
  532. /**
  533. * Gets offset.
  534. *
  535. * @param integer|string $offset Offset
  536. *
  537. * @return mixed|null
  538. */
  539. #[\ReturnTypeWillChange]
  540. public function offsetGet(mixed $offset)
  541. {
  542. return $this->container[$offset] ?? null;
  543. }
  544. /**
  545. * Sets value based on offset.
  546. *
  547. * @param int|null $offset Offset
  548. * @param mixed $value Value to be set
  549. *
  550. * @return void
  551. */
  552. public function offsetSet($offset, $value): void
  553. {
  554. if (is_null($offset)) {
  555. $this->container[] = $value;
  556. } else {
  557. $this->container[$offset] = $value;
  558. }
  559. }
  560. /**
  561. * Unsets offset.
  562. *
  563. * @param integer|string $offset Offset
  564. *
  565. * @return void
  566. */
  567. public function offsetUnset(mixed $offset): void
  568. {
  569. unset($this->container[$offset]);
  570. }
  571. /**
  572. * Serializes the object to a value that can be serialized natively by json_encode().
  573. * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
  574. *
  575. * @return mixed Returns data which can be serialized by json_encode(), which is a value
  576. * of any type other than a resource.
  577. */
  578. #[\ReturnTypeWillChange]
  579. public function jsonSerialize()
  580. {
  581. return ObjectSerializer::sanitizeForSerialization($this);
  582. }
  583. /**
  584. * Gets the string presentation of the object
  585. *
  586. * @return string
  587. */
  588. public function __toString()
  589. {
  590. return json_encode(
  591. ObjectSerializer::sanitizeForSerialization($this),
  592. JSON_PRETTY_PRINT
  593. );
  594. }
  595. /**
  596. * Gets a header-safe presentation of the object
  597. *
  598. * @return string
  599. */
  600. public function toHeaderValue()
  601. {
  602. return json_encode(ObjectSerializer::sanitizeForSerialization($this));
  603. }
  604. }