public static function run($exception) { $log = 'File: ' . $exception->getFile() . ' '; $log .= 'Line: ' . $exception->getLine() . ' '; $log .= 'Message: ' . $exception->getMessage(); Vera_Log::addErr($log); return true; }
/** * 设置模板 * @param string $template 模板文件名 */ public function setTemplate($template = 'text') { //构成完整文件路径 $file = SERVER_ROOT . 'app/wechat/view/template/' . $template . '.php'; if (file_exists($file)) { self::$_tpl = $file; } else { Vera_Log::addErr('cannot find template ' . $file); exit; } }
/** * 获取某App配置 * @param string $name 配置文件名 * @param string $app App名称 * @return array 配置内容 */ public static function getAppConf($name, $app = NULL) { if ($app === NULL) { $app = $GLOBALS['APP_NAME']; } $path = SERVER_ROOT . 'conf/' . $app . '/' . $name . '.conf'; $ret = self::_getFile($path); if (!$ret) { Vera_Log::addErr('prase conf ' . $path . ' error'); return false; } return $ret; }
public static function run() { return true; //暂时无法解决signature校验不一致的问题 $conf = Vera_Conf::getConf('global'); $conf = $conf['wechat']; if (!isset($conf['token']) || empty($conf['token'])) { Vera_Log::addErr('cannot find token'); exit; } $token = $conf['token']; return self::_checkSignature($token); }
/** * 根据名称和参数创建一个类 * @param string $className action类的名称 * @param mixed $arg 参数 * @return class 返回一个类实例 */ private function _createClass($className, $arg = NULL) { $className = "Action_" . $className; if (class_exists($className)) { $class = new $className($arg); } else { Vera_Log::addNotice('cannot find class ' . $className); exit; //如果类不存在,说明访问了一个无效链接,终止进程 } if ($class == NULL) { Vera_Log::addErr('cannot create class ' . $className); exit; } return $class; }
public static function run($exception) { $log = 'file[' . $exception->getFile() . '] '; $log .= 'line[' . $exception->getLine() . '] '; $log .= 'message[' . $exception->getMessage() . '] '; Vera_Log::addErr($log); $resource = parent::getResource(); if ($resource === NULL) { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $resource = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); } $msg = $exception->getMessage(); $errMsg = empty($msg) ? parent::$commonConf['errMsg'] : $msg; $ret = "<xml>\n \t\t <ToUserName><![CDATA[" . $resource['FromUserName'] . "]]></ToUserName>\n \t\t <FromUserName><![CDATA[" . $resource['ToUserName'] . "]]></FromUserName>\n \t\t <CreateTime>" . time() . "</CreateTime>\n \t\t <MsgType><![CDATA[text]]></MsgType>\n \t\t <Content><![CDATA[" . $errMsg . "]]></Content>\n \t\t</xml>"; echo $ret; exit; }
private static function _loadClass($className) { $appRoot = SERVER_ROOT . "app/" . $GLOBALS['APP_NAME']; $filePath = explode('_', $className); switch (array_shift($filePath)) { case 'Action': $nextDir = '/action/'; break; case 'Data': $nextDir = '/model/data/'; break; case 'Service': $nextDir = '/model/service/'; break; case 'Vera': $appRoot = SERVER_ROOT; $nextDir = '/tools/'; break; case 'Smarty': return smartyAutoload($className); //使用Smarty自带的Autoload函数加载Smarty引擎相关的类 break; case 'View': $nextDir = '/view/'; break; case 'Library': $nextDir = '/library/'; break; default: Vera_Log::addErr('unknown classname ' . $className); exit; } $classPath = $appRoot . $nextDir; $file = array_pop($filePath); if (count($filePath) != 0) { foreach ($filePath as $each) { $classPath .= strtolower($each) . "/"; } } $classPath .= $file . ".php"; if (file_exists($classPath)) { include_once $classPath; } else { Vera_Log::addErr($className . ' not found'); Vera_Log::addNotice('classPath', $classPath); return false; } }
public static function run($exception) { $log = 'Message: ' . $exception->getMessage(); Vera_Log::addErr($log); return true; }
/** * 写入文件 * @param string $level 日志文件名 * @param string $log 日志内容 * @return bool 写入状态 */ private static function _writeLog($level = '', $log = '') { if (!Vera_Router::isApp()) { //检查是否为合法的App return false; } $logDir = SERVER_ROOT . 'log/' . $GLOBALS['APP_NAME']; if (!is_dir($logDir)) { mkdir($logDir); } $file = $logDir . "/" . strtolower($level) . ".log"; $fp = fopen($file, 'a'); if (!$fp) { return false; } if (flock($fp, LOCK_EX)) { fwrite($fp, $log . PHP_EOL); flock($fp, LOCK_UN); //释放锁定 } else { Vera_Log::addErr('can`t lock file!'); } fclose($fp); return true; }
private function _connect($conf = NULL) { if ($conf == NULL) { return false; } $this->isConnected = $this->mysql->real_connect($conf['host'], $conf['username'], $conf['password'], $conf['dbname'], $conf['port']); if (!$this->isConnected) { Vera_Log::addErr('connect to MySQL failed'); exit; } return $this->isConnected; }