1 | <?php |
||
16 | class JsonPrimitive extends JsonElement |
||
17 | { |
||
18 | /** |
||
19 | * The value of the primitive |
||
20 | * |
||
21 | * @var mixed |
||
22 | */ |
||
23 | private $value; |
||
24 | |||
25 | /** |
||
26 | * Constructor |
||
27 | * |
||
28 | * @param mixed $value |
||
29 | */ |
||
30 | 6 | protected function __construct($value) |
|
34 | |||
35 | /** |
||
36 | * Factory constructor that handles nulls |
||
37 | * |
||
38 | * @param mixed $value |
||
39 | * @return JsonNull|JsonPrimitive |
||
40 | */ |
||
41 | 7 | public static function create($value) |
|
49 | |||
50 | /** |
||
51 | * Returns true if the value is a string |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | 5 | public function isString(): bool |
|
59 | |||
60 | /** |
||
61 | * Returns true if the value is an integer |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | 5 | public function isInteger(): bool |
|
69 | |||
70 | /** |
||
71 | * Returns true if the value is a float |
||
72 | * |
||
73 | * @return bool |
||
74 | */ |
||
75 | 5 | public function isFloat(): bool |
|
79 | |||
80 | /** |
||
81 | * Returns true if the value is an integer or float |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | 5 | public function isNumber(): bool |
|
89 | |||
90 | /** |
||
91 | * Returns true if the value is a boolean |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | 5 | public function isBoolean(): bool |
|
99 | |||
100 | /** |
||
101 | * Cast the value to a string |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 1 | public function asString(): string |
|
109 | |||
110 | /** |
||
111 | * Cast the value to an integer |
||
112 | * |
||
113 | * @return int |
||
114 | */ |
||
115 | 1 | public function asInteger(): int |
|
119 | |||
120 | /** |
||
121 | * Cast the value to a float |
||
122 | * |
||
123 | * @return float |
||
124 | */ |
||
125 | 2 | public function asFloat(): float |
|
129 | |||
130 | /** |
||
131 | * Cast the value to a boolean |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | 2 | public function asBoolean(): bool |
|
139 | |||
140 | /** |
||
141 | * Return whatever the current value is |
||
142 | * |
||
143 | * @return mixed |
||
144 | */ |
||
145 | public function getValue() |
||
149 | |||
150 | /** |
||
151 | * Specify data which should be serialized to JSON |
||
152 | * |
||
153 | * @return mixed |
||
154 | */ |
||
155 | public function jsonSerialize() |
||
159 | } |
||
160 |