mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
驱动设计支持使用 namespace配置改变默认命名空间位置
This commit is contained in:
@@ -13,8 +13,8 @@ namespace think;
|
||||
|
||||
class Cache
|
||||
{
|
||||
public static $readTimes = 0;
|
||||
public static $writeTimes = 0;
|
||||
public static $readTimes = 0;
|
||||
public static $writeTimes = 0;
|
||||
|
||||
/**
|
||||
* 操作句柄
|
||||
@@ -31,8 +31,9 @@ class Cache
|
||||
*/
|
||||
public static function connect($options = [])
|
||||
{
|
||||
$type = !empty($options['type']) ? $options['type'] : 'File';
|
||||
$class = '\\think\\cache\\driver\\' . ucwords($type);
|
||||
$type = !empty($options['type']) ? $options['type'] : 'File';
|
||||
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type);
|
||||
unset($options['type']);
|
||||
self::$handler = new $class($options);
|
||||
return self::$handler;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class Config
|
||||
if (empty($type)) {
|
||||
$type = pathinfo($config, PATHINFO_EXTENSION);
|
||||
}
|
||||
$class = '\\think\\config\\driver\\' . ucwords($type);
|
||||
$class = (false === strpos($type, '\\')) ? '\\think\\config\\driver\\' . ucwords($type) : $type;
|
||||
self::set((new $class())->parse($config), '', $range);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class Db
|
||||
// 解析连接参数 支持数组和字符串
|
||||
$options = self::parseConfig($config);
|
||||
// 如果采用lite方式 仅支持原生SQL 包括query和execute方法
|
||||
$class = $lite ? '\\think\\db\\Lite' : '\\think\\db\\driver\\' . ucwords($options['type']);
|
||||
$class = $lite ? '\\think\\db\\Lite' : (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\driver\\') . ucwords($options['type']);
|
||||
self::$instances[$md5] = new $class($options);
|
||||
}
|
||||
self::$instance = self::$instances[$md5];
|
||||
|
||||
@@ -33,7 +33,7 @@ class Log
|
||||
public static function init($config = [])
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : 'File';
|
||||
$class = '\\think\\log\\driver\\' . ucwords($type);
|
||||
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type);
|
||||
unset($config['type']);
|
||||
self::$driver = new $class($config);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class Log
|
||||
public static function alarm($config = [])
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : 'Email';
|
||||
$class = '\\think\\log\\alarm\\' . ucwords($config['type']);
|
||||
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\alarm\\') . ucwords($type);
|
||||
unset($config['type']);
|
||||
self::$alarm = new $class($config['alarm']);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class Session
|
||||
}
|
||||
if (!empty($config['type'])) {
|
||||
// 读取session驱动
|
||||
$class = '\\think\\session\\driver\\' . strtolower($config['type']);
|
||||
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\session\\driver\\') . strtolower($config['type']);
|
||||
// 检查驱动类
|
||||
if (!session_set_save_handler(new $class())) {
|
||||
throw new Exception('error session handler', 11700);
|
||||
|
||||
@@ -43,6 +43,7 @@ class Template
|
||||
'display_cache' => false, // 模板渲染缓存
|
||||
'cache_id' => '', // 模板缓存ID
|
||||
'tpl_replace_string' => [],
|
||||
'namespace' => '\\think\\template\\driver\\',
|
||||
];
|
||||
|
||||
private $literal = [];
|
||||
@@ -63,7 +64,7 @@ class Template
|
||||
|
||||
// 初始化模板编译存储器
|
||||
$type = $this->config['compile_type'] ? $this->config['compile_type'] : 'File';
|
||||
$class = '\\think\\template\\driver\\' . ucwords($type);
|
||||
$class = $this->config['namespace'] . ucwords($type);
|
||||
$this->storage = new $class();
|
||||
}
|
||||
|
||||
@@ -696,6 +697,11 @@ class Template
|
||||
$parseStr = $this->parseThinkVar($vars);
|
||||
} else {
|
||||
// 一维自动识别对象和数组
|
||||
if (is_array($first)) {
|
||||
$parseStr = $first . '[\'' . implode('\'][\'', $vars) . '\']';
|
||||
} else {
|
||||
$parseStr = $first . '->' . implode('->', $vars);
|
||||
}
|
||||
$parseStr = 'is_array(' . $first . ')?' . $first . '[\'' . implode('\'][\'', $vars) . '\']:' . $first . '->' . implode('->', $vars);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -35,6 +35,7 @@ class View
|
||||
'parse_str' => [],
|
||||
'engine_type' => 'think',
|
||||
'parse_var' => false,
|
||||
'namespace' => '\\think\\view\\driver\\',
|
||||
];
|
||||
|
||||
public function __construct(array $config = [])
|
||||
@@ -106,7 +107,7 @@ class View
|
||||
if ('php' == $engine) {
|
||||
$this->engine = 'php';
|
||||
} else {
|
||||
$class = '\\think\\view\\driver\\' . ucwords($engine);
|
||||
$class = $this->config['namespace'] . ucwords($engine);
|
||||
$this->engine = new $class($config);
|
||||
}
|
||||
return $this;
|
||||
|
||||
Reference in New Issue
Block a user