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