YULUserOptFormatter.class.php 2.71 KB
<?php

require_once 'YULMessageFormatter.class.php';

/**
 * 用户操作格式器. 用来格式化产生插入日志数据库中的用户操作消息.消息格式如下
 * 
 * 用户ID|模块|操作代码|ip地址|是否成功|错误代码|加密码
 * 
 * @author dan
 *
 */
class YULUserOptFormatter extends YULMessageFormatter {
	
	private $formatter = array(
	                         // 消息类型
	                         'type'=>self::USER_OPT_TYPE,
	                         //用户ID
	                         'userID'=>0,
	                         //模块
	                         'module'=>null,
		                     //操作代码
	                         'operation'=>null,
		                     //ip地址
	                         'ip'=>null,
		                     //是否成功
	                         'isSuccess'=>0,
		                     //错误代码
	                         'errorCode'=>0,
		                     //加密码
	                         'skey'=>null,
	                     );

	public function __construct($userID=NULL, $module=NULL, $operation=NULL, 
	                            $ip=NULL, $isSuccess=0, $errorCode=0, $skey=NULL)
	{
	    $this->formatter['userID'] = $userID;
	    $this->formatter['module'] = $module;
	    $this->formatter['operation'] = $operation;
	    $this->formatter['ip'] = $ip;
	    $this->formatter['isSuccess'] = $isSuccess;
	    $this->formatter['errorCode'] = $errorCode;
	    $this->formatter['skey'] = $skey;
	    
	}
	
	public function setUserID($userID)
	{
	    if (isset($userID))
	    {
	        $this->formatter['userID'] = $userID;
	    }
	}
	
    public function setModule($module)
	{
	    if (isset($module))
	    {
	        $this->formatter['module'] = $module;
	    }
	}
	
    public function setOperation($operation)
	{
	    if (isset($operation))
	    {
	        $this->formatter['operation'] = $operation;
	    }
	}
	
    public function setIp($ip)
	{
	    if (isset($ip))
	    {
	        $this->formatter['ip'] = $ip;
	    }
	}
	
    public function setIsSuccess($isSuccess)
	{
	    if (isset($isSuccess))
	    {
	        $this->formatter['isSuccess'] = $isSuccess;
	    }
	}
	
    public function setErrorCode($errorCode)
	{
	    if (isset($errorCode))
	    {
	        $this->formatter['errorCode'] = $errorCode;
	    }
	}
	
    public function setSkey($skey)
	{
	    if (isset($skey))
	    {
	        $this->formatter['skey'] = $skey;
	    }
	}
	
	/*
	 * 返回最终的格式化数据
	 */
	public function toString() {
	    
	    $result = '';
	    
	    $separator = $this->getSeparator();
	    
	    foreach ($this->formatter as $format)
	    {
	        $result .= $format;
	        $result .= $separator;
	    }
	    
	    return trim($result, $separator);
	
	}
}

?>