$instance
$instance :
session.php 缓存工厂类
<?php
namespace ticky;
/**
* session.php 缓存工厂类
*
* @author 罗敏贵
* @license https://www.cnblogs.com/luomingui
* @lastmodify 2019-02-20
*/
class session {
public static $instance = null;
public static $driver = null;
public static $config = null;
public static $expire = 24 * 3600;
private static function getconfig() {
self::$expire = config::get('session', 'expire');
self::$driver = config::get('session', 'driver');
self::$config = config::get('session', self::$driver);
$active = session_status() == PHP_SESSION_ACTIVE ? true : false;
if (!$active) {
session_start();
}
}
/**
* 返回当前终级类对象的实例
* @return object
*/
public static function instance($name = false) {
self::getconfig();
$type = !empty(self::$driver) ? self::$driver : 'file';
if (false === $name) {
$name = md5(serialize(self::$config));
}
if (true === $name || !isset(self::$instance[$name])) {
$class = false === strpos($type, '\\') ? '\\ticky\\session\\driver\\' . $type : $type;
if (true === $name) {
return new $class(self::$config);
}
self::$instance[$name] = new $class(self::$config);
}
return self::$instance[$name];
}
}