beforeInit($code, $msg, $data , $error, $single); $this->zskkInit($code, $msg, $data , $error, $single ); $this->afterInit($code, $msg, $data , $error, $single); } protected function beforeInit(int $code = 0,string $msg = '', $data = null, $error = null,bool $single = true) { } protected function afterInit(int $code = 0,string $msg = '', $data = null, $error = null,bool $single = true) { } protected function zskkInit(int $code, string $msg, $data, $error, bool $single) { if($single) { $this->defaultInit(); } else { $this->customInit($code, $msg, $data , $error); } } private function defaultInit() { $this->setResponse($this->code, $this->msg, $this->data , $this->error); } private function customInit(int $code, string $msg, $data, $error) { $this->setResponse($code, $msg, $data , $error); } public function setResponse($code = 0, $msg = '', $data = null, $error = null) { $this->setCode($code); $this->setMsg($msg); $this->setData($data); $this->setError($error); } public function getResponse() { return [ "code" => $this->getCode(), "msg" => $this->getMsg(), "data" => $this->getData(), "error" => $this->getError(), "timestamp" => $this->getTimestamp() ]; } private function getTimestamp() { return time(); } /** * @return int */ public function getCode(): int { return $this->code; } /** * @param int $code */ public function setCode(int $code) { $this->code = $code; return $this; } /** * @return string */ public function getMsg(): string { return $this->msg; } /** * @param string $msg */ public function setMsg(string $msg) { $this->msg = $msg; return $this; } /** * @return null */ public function getError() { return $this->error; } /** * @param null $error */ public function setError($error) { $this->error = $error; return $this; } /** * @return null */ public function getData() { return $this->data; } /** * @param null $data */ public function setData($data) { $this->data = $data; return $this; } }