|
11 | 11 | use \DateTime; |
12 | 12 | use \DateTimeZone; |
13 | 13 | use \InvalidArgumentException; |
| 14 | +use \JsonSerializable; |
14 | 15 | use \PDO; |
15 | 16 | use \PDOException; |
16 | 17 | use \StdClass; |
17 | 18 |
|
18 | | -class Server { |
| 19 | +class Server implements JsonSerializable { |
19 | 20 |
|
20 | 21 | const STATUS_ONLINE = 0x00000001; |
21 | 22 | const STATUS_DISABLED = 0x00000002; |
@@ -168,6 +169,32 @@ public function getUserId() { |
168 | 169 | return $this->user_id; |
169 | 170 | } |
170 | 171 |
|
| 172 | + public function jsonSerialize() { |
| 173 | + $created_datetime = $this->getCreatedDateTime(); |
| 174 | + if (!is_null($created_datetime)) $created_datetime = [ |
| 175 | + "iso" => $created_datetime->format("r"), |
| 176 | + "unix" => $created_datetime->getTimestamp(), |
| 177 | + ]; |
| 178 | + |
| 179 | + $updated_datetime = $this->getUpdatedDateTime(); |
| 180 | + if (!is_null($updated_datetime)) $updated_datetime = [ |
| 181 | + "iso" => $updated_datetime->format("r"), |
| 182 | + "unix" => $updated_datetime->getTimestamp(), |
| 183 | + ]; |
| 184 | + |
| 185 | + return [ |
| 186 | + "address" => $this->getAddress(), |
| 187 | + "created_datetime" => $created_datetime, |
| 188 | + "id" => $this->getId(), |
| 189 | + "label" => $this->getLabel(), |
| 190 | + "port" => $this->getPort(), |
| 191 | + "status_bitmask" => $this->getStatusBitmask(), |
| 192 | + "type_id" => $this->getTypeId(), |
| 193 | + "updated_datetime" => $updated_datetime, |
| 194 | + "user" => $this->getUser() |
| 195 | + ]; |
| 196 | + } |
| 197 | + |
171 | 198 | protected static function normalize(StdClass &$data) { |
172 | 199 | $data->address = (string) $data->address; |
173 | 200 | $data->created_datetime = (string) $data->created_datetime; |
|
0 commit comments