Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
textnode.php
1<?
3
4class TextNode implements \JsonSerializable
5{
6 protected ?string $text = null;
7 protected ?string $type = null;
8
9 public function __construct($options)
10 {
11 if (is_array($options))
12 {
13 if (isset($options['text']) && (is_string($options['text']) || is_int($options['text'])))
14 {
15 $this->text = (string)$options['text'];
16 }
17
18 if (isset($options['type']) && TextNodeType::isValid($options['type']))
19 {
20 $this->type = $options['type'];
21 }
22 }
23 else if (is_string($options) || is_int($options))
24 {
25 $this->text = (string)$options;
26 }
27 }
28
29 public static function isValidText($text): bool
30 {
31 return is_string($text) || is_int($text) || is_array($text);
32 }
33
34 public function getType(): ?string
35 {
36 return $this->type;
37 }
38
39 public function getText(): ?string
40 {
41 return $this->text;
42 }
43
44 public function isNullable(): bool
45 {
46 return $this->getText() === null;
47 }
48
49 public function jsonSerialize()
50 {
51 if ($this->getType() === null)
52 {
53 return $this->getText();
54 }
55 else
56 {
57 return [
58 'text' => $this->getText(),
59 'type' => $this->getType()
60 ];
61 }
62 }
63}