mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进Session类 去除active属性判断
This commit is contained in:
@@ -16,9 +16,7 @@ use think\exception\ClassNotFoundException;
|
|||||||
|
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static $prefix = '';
|
protected static $prefix = '';
|
||||||
protected static $active = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置或者获取session作用域(前缀)
|
* 设置或者获取session作用域(前缀)
|
||||||
@@ -100,7 +98,6 @@ class Session
|
|||||||
}
|
}
|
||||||
if ($isDoStart) {
|
if ($isDoStart) {
|
||||||
session_start();
|
session_start();
|
||||||
self::$active = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +110,7 @@ class Session
|
|||||||
*/
|
*/
|
||||||
public static function set($name, $value = '', $prefix = null)
|
public static function set($name, $value = '', $prefix = null)
|
||||||
{
|
{
|
||||||
!self::$active && self::init();
|
!isset($_SESSION) && self::init();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
// 二维数组赋值
|
// 二维数组赋值
|
||||||
@@ -138,7 +135,7 @@ class Session
|
|||||||
*/
|
*/
|
||||||
public static function get($name = '', $prefix = null)
|
public static function get($name = '', $prefix = null)
|
||||||
{
|
{
|
||||||
!self::$active && self::init();
|
!isset($_SESSION) && self::init();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if ('' == $name) {
|
if ('' == $name) {
|
||||||
// 获取全部的session
|
// 获取全部的session
|
||||||
@@ -170,7 +167,7 @@ class Session
|
|||||||
*/
|
*/
|
||||||
public static function delete($name, $prefix = null)
|
public static function delete($name, $prefix = null)
|
||||||
{
|
{
|
||||||
!self::$active && self::init();
|
!isset($_SESSION) && self::init();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
list($name1, $name2) = explode('.', $name);
|
list($name1, $name2) = explode('.', $name);
|
||||||
@@ -195,7 +192,7 @@ class Session
|
|||||||
*/
|
*/
|
||||||
public static function clear($prefix = null)
|
public static function clear($prefix = null)
|
||||||
{
|
{
|
||||||
!self::$active && self::init();
|
!isset($_SESSION) && self::init();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if ($prefix) {
|
if ($prefix) {
|
||||||
unset($_SESSION[$prefix]);
|
unset($_SESSION[$prefix]);
|
||||||
@@ -212,7 +209,7 @@ class Session
|
|||||||
*/
|
*/
|
||||||
public static function has($name, $prefix = null)
|
public static function has($name, $prefix = null)
|
||||||
{
|
{
|
||||||
!self::$active && self::init();
|
!isset($_SESSION) && self::init();
|
||||||
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
$prefix = !is_null($prefix) ? $prefix : self::$prefix;
|
||||||
if (strpos($name, '.')) {
|
if (strpos($name, '.')) {
|
||||||
// 支持数组
|
// 支持数组
|
||||||
@@ -230,7 +227,6 @@ class Session
|
|||||||
public static function start()
|
public static function start()
|
||||||
{
|
{
|
||||||
session_start();
|
session_start();
|
||||||
self::$active = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user