* @copyright walkor * @link http://www.workerman.net/ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace GatewayWorker\Lib; /** * 上下文 包含当前用户uid, 内部通信local_ip local_port socket_id ,以及客户端client_ip client_port */ class Context { /** * 内部通讯id * @var string */ public static $local_ip; /** * 内部通讯端口 * @var int */ public static $local_port; /** * 客户端ip * @var string */ public static $client_ip; /** * 客户端端口 * @var int */ public static $client_port; /** * 用户id * @var int */ public static $client_id; /** * 编码session * @param mixed $session_data * @return string */ public static function sessionEncode($session_data = '') { if($session_data !== '') { return serialize($session_data); } return ''; } /** * 解码session * @param string $session_buffer * @return mixed */ public static function sessionDecode($session_buffer) { return unserialize($session_buffer); } /** * 清除上下文 * @return void */ public static function clear() { self::$local_ip = self::$local_port = self::$client_ip = self::$client_port = self::$client_id = null; } }