function catchFatalError() { $error = error_get_last(); if (empty($error)) { return; } $ignore = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED; if (($error['type'] & $ignore) == 0) { // handle the error - but DO NOT THROW ANY EXCEPTION HERE. Wk::logger()->err('Fatal error: ' . print_r($error, true)); die; } }
private function authWeb() { try { Wk_Request::startSession(WAKA_DOMAIN); if (isset($_SESSION['appParam'])) { $token = $_SESSION['appParam']['token']; $retUser = WkUserService::getInstance()->getUserByToken($token); $this->curUser = $retUser; } else { $token = ''; } $this->curToken = $token; if (isset($this->curUser)) { WkUserService::getInstance()->setLoginCookie($this->curUser); } else { unset($_COOKIE['WAKAUID']); setcookie('WAKAUID', '', time() - 3600, '/', WAKA_DOMAIN); } } catch (Exception $e) { Wk::logger()->err($e); throw new Wk_Exception('', -1); } }
public static function redis($redis = "default") { $hash = 'wk_redis_' . $redis; if (!isset(self::$componentStack[$hash])) { if (empty(self::$config['redis']) || empty(self::$config['redis'][$redis])) { return new Wk_Redis(); } $host = self::$config['redis'][$redis]['host']; $port = self::$config['redis'][$redis]['port']; $_redis = new Wk_Redis(); try { $success = $_redis->pconnect($host, $port); } catch (Exception $e) { Wk::logger()->err($e); return $_redis; } if (!$success) { Wk::logger()->err("connect to redis {$host}:{$port} return false: " . $_redis->getLastError()); return $_redis; } self::$componentStack[$hash] = $_redis; } return self::$componentStack[$hash]; }
public function stop() { Wk::logger()->s(); die; }
/** * @param $function * @return bool */ private function _wrapBoolReturn($function) { try { $success = $function(); if (!$success) { $errMsg = self::getLastError(); if (!isset($errMsg)) { $errMsg = 'unknown redis error'; } try { throw new Exception($errMsg); } catch (Exception $e) { Wk::logger()->err($e); } } return $success; } catch (Exception $e) { Wk::logger()->err($e); } return false; }
public function rollback() { if (!$this->_db->rollback()) { Wk::logger()->err($this->error); } $this->_db->autocommit(true); }
private static function printTransferCertainCustomerService($fromUsername, $toUsername, $createTime, $kfAccount) { $textTpl = "<xml>\n <ToUserName><![CDATA[%s]]></ToUserName>\n <FromUserName><![CDATA[%s]]></FromUserName>\n <CreateTime>%s</CreateTime>\n <MsgType><![CDATA[transfer_customer_service]]></MsgType>\n <TransInfo>\n <KfAccount>%s</KfAccount>\n </TransInfo>\n </xml>"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $createTime, $kfAccount); Wk::logger()->log($resultStr); return $resultStr; }
/** * @throws Wk_Exception */ public final function delete() { if (!isset($this->id)) { Wk::logger()->err('obj not inserted'); throw new Wk_Exception('', -1); } if (property_exists($this, 'isDeleted')) { $this->isDeleted = 1; $this->save(); } else { $sql = 'delete from ' . $this->getTableName() . ' where id=?'; if (Wk::db()->execute($sql, 'i', $this->id)) { unset($this->id); } else { Wk::logger()->err('db error'); throw new Wk_Exception('', -1); } } }
/** * (PHP 5 >= 5.0.0)<br/> * Offset to set * @link http://php.net/manual/en/arrayaccess.offsetset.php * @param mixed $offset <p> * The offset to assign the value to. * </p> * @param mixed $value <p> * The value to set. * </p> * @throws Wk_Exception */ public function offsetSet($offset, $value) { if ($this->offsetExists($offset)) { $this->{$offset} = $value; } Wk::logger()->err("property {$offset} not exists in " . get_called_class()); throw new Wk_Exception("property {$offset} not exists in " . get_called_class(), -1); }
/** * 返回错误信息 * * @param string $errorMsg * @param int $errorCode * @param int $httpStatus */ public function returnError($errorMsg = '', $errorCode = -1, $httpStatus = 200) { if ($httpStatus !== 200) { switch ($httpStatus) { case 404: header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); echo '404 Not Found'; break; case 403: header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); echo '403 Forbidden'; break; case 500: header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); echo '500 Internal Server Error'; break; default: header($_SERVER['SERVER_PROTOCOL'] . ' ' . $httpStatus . ' Http Error'); echo $httpStatus . ' Http Error'; break; } } elseif (Wk_Request::isAjax()) { header('Content-Type: application/json; charset=utf-8'); if (!empty($errorMsg)) { echo json_encode(['ok' => 0, 'msg' => $errorMsg, 'code' => $errorCode], JSON_UNESCAPED_UNICODE); } else { echo json_encode(['ok' => 0, 'msg' => TErrorConstants::getErrorMsg($errorCode), 'code' => $errorCode], JSON_UNESCAPED_UNICODE); } } else { if (empty($errorMsg)) { $errorMsg = TErrorConstants::getErrorMsg($errorCode); } Wk::logger()->err('page error:' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')')); // $this->renderView('/layouts/404'); echo 'error: ' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')'); } Wk::app()->stop(); }