改进Session类

This commit is contained in:
thinkphp
2016-02-23 12:27:48 +08:00
parent 341882c13f
commit 2dfd60d416

View File

@@ -109,9 +109,7 @@ class Session
*/ */
public static function set($name, $value = '', $prefix = null) public static function set($name, $value = '', $prefix = null)
{ {
if (!self::$active) { !self::$active) && self::init();
self::init();
}
$prefix = !is_null($prefix) ? $prefix : self::$prefix; $prefix = !is_null($prefix) ? $prefix : self::$prefix;
if (strpos($name, '.')) { if (strpos($name, '.')) {
// 二维数组赋值 // 二维数组赋值
@@ -136,9 +134,7 @@ class Session
*/ */
public static function get($name = '', $prefix = null) public static function get($name = '', $prefix = null)
{ {
if (!self::$active) { !self::$active) && self::init();
self::init();
}
$prefix = !is_null($prefix) ? $prefix : self::$prefix; $prefix = !is_null($prefix) ? $prefix : self::$prefix;
if ('' == $name) { if ('' == $name) {
// 获取全部的session // 获取全部的session
@@ -170,6 +166,7 @@ class Session
*/ */
public static function delete($name, $prefix = null) public static function delete($name, $prefix = null)
{ {
!self::$active) && 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);
@@ -194,6 +191,7 @@ class Session
*/ */
public static function clear($prefix = null) public static function clear($prefix = null)
{ {
!self::$active) && 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]);