code = $code; $this->message = empty($message) ? ResultCode::getMessage($code) : $message; $this->data = $data; } public function getCode(): int { return $this->code; } public function setCode(int $code) { return $this->code = $code; } public function getMessage(): string { return $this->message; } public function setMessage(string $message) { return $this->message = empty($message) ? ResultCode::getMessage($this->code) : $message; } public function getData(): array { return $this->data; } public function setData(array $data) { return $this->data = $data; } public function toArray(): array { return [ 'code' => $this->code, 'message' => $this->message, 'data' => new \ArrayObject($this->data), ]; } public function __toString() { return json_encode($this->toArray(), JSON_UNESCAPED_UNICODE); } }