function session($name, $value = '') { if (is_array($name)) { // 初始化 \think\Session::init($name); } elseif (is_null($name)) { // 清除 \think\Session::clear($value); } elseif ('' === $value) { // 获取 return \think\Session::get($name); } elseif (is_null($value)) { // 删除session return \think\Session::delete($name); } else { // 设置session return \think\Session::set($name, $value); } }
/** * Session管理 * @param string|array $name session名称,如果为数组表示进行session设置 * @param mixed $value session值 * @param string $prefix 前缀 * @return mixed */ function session($name, $value = '', $prefix = null) { if (is_array($name)) { // 初始化 Session::init($name); } elseif (is_null($name)) { // 清除 Session::clear('' === $value ? null : $value); } elseif ('' === $value) { // 判断或获取 return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); } elseif (is_null($value)) { // 删除 return Session::delete($name, $prefix); } else { // 设置 return Session::set($name, $value, $prefix); } }
/** * @covers think\Session::clear * * @todo Implement testClear(). */ public function testClear() { \think\Session::prefix(null); \think\Session::set('sessionnameclsper', 'sessionvalue1', 'think_'); \think\Session::clear('think_'); $this->assertNull($_SESSION['think_']); \think\Session::set('sessionnameclsper', 'sessionvalue1', 'think_'); \think\Session::clear(); $this->assertEmpty($_SESSION); }
function session($name, $value = '', $prefix = null) { if (is_array($name)) { // 初始化 \think\Session::init($name); } elseif (is_null($name)) { // 清除 \think\Session::clear($value); } elseif ('' === $value) { // 判断或获取 return 0 === strpos($name, '?') ? \think\Session::has(substr($name, 1), $prefix) : \think\Session::get($name, $prefix); } elseif (is_null($value)) { // 删除session return \think\Session::delete($name, $prefix); } else { // 设置session return \think\Session::set($name, $value, $prefix); } }