/** * Method response * Return response in json, HTTP Status and exit system * @author Bruno Oliveira <*****@*****.**> * @access public * @return string */ public static function response($response, $httpStatus = null, $break = true) { if (!empty($httpStatus)) { header("HTTP/1.1 {$httpStatus}"); } echo Utils::jsonEncode($response); if ($break) { exit; } }
/** * Method stopSystem * Para a execução do sistema, envia status http e retorna json com mensagem de erro * @author Bruno Oliveira <*****@*****.**> * @param string $msg */ public function stopSystem($msg) { header('HTTP/1.1 401'); echo Utils::jsonEncode("Status => Error | Message => {$msg}"); die; }
/** * Method toJson * Transforma o retorno em json * @author Bruno Oliveira <*****@*****.**> * @access public * @return string */ public function toJson() { if (is_object(self::$result)) { $json = get_object_vars(self::$result); } elseif (is_array(self::$result)) { $json = array(); foreach (self::$result as $r) { $json[] = get_object_vars($r); } } return Utils::jsonEncode($json); }
/** * Send Message clients * * @param $message * @param null $client * @param bool|true $mask * @return bool */ public function sendMessage($message, $client = null, $mask = true) { if ($mask) { $dataMessage = Utils::jsonEncode($message); if (json_last_error() == JSON_ERROR_NONE) { $message = $dataMessage; } $message = $this->mask($message); } if (is_null($client)) { foreach ($this->clients as $changedSocket) { @socket_write($changedSocket, $message, strlen($message)); } } else { @socket_write($client, $message, strlen($message)); } return true; }