取消驱动配置的namespace参数

This commit is contained in:
thinkphp
2016-06-18 23:42:16 +08:00
parent 20eaa4f5b8
commit 30cec3abb1
11 changed files with 12 additions and 14 deletions

View File

@@ -41,7 +41,7 @@ class Cache
}
if (true === $name || !isset(self::$instance[$name])) {
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\cache\\driver\\') . ucwords($type);
$class = strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
// 记录初始化信息
App::$debug && Log::record('[ CACHE ] INIT ' . $type . ':' . var_export($options, true), 'info');

View File

@@ -42,7 +42,7 @@ class Config
if (empty($type)) {
$type = pathinfo($config, PATHINFO_EXTENSION);
}
$class = (false === strpos($type, '\\')) ? '\\think\\config\\driver\\' . ucwords($type) : $type;
$class = strpos($type, '\\') ? $type : '\\think\\config\\driver\\' . ucwords($type);
self::set((new $class())->parse($config), $name, $range);
}

View File

@@ -67,7 +67,7 @@ class Db
if (empty($options['type'])) {
throw new \InvalidArgumentException('Underfined db type');
}
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\db\\connector\\') . ucwords($options['type']);
$class = strpos($options['type'], '\\') ? $options['type'] : '\\think\\db\\connector\\' . ucwords($options['type']);
// 记录初始化信息
App::$debug && Log::record('[ DB ] INIT ' . $options['type'] . ':' . var_export($options, true), 'info');
if (true === $name) {

View File

@@ -42,7 +42,7 @@ class Log
public static function init($config = [])
{
$type = isset($config['type']) ? $config['type'] : 'File';
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\driver\\') . ucwords($type);
$class = strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
self::$config = $config;
unset($config['type']);
self::$driver = new $class($config);
@@ -57,7 +57,7 @@ class Log
public static function alarm($config = [])
{
$type = isset($config['type']) ? $config['type'] : 'Email';
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\log\\alarm\\') . ucwords($type);
$class = strpos($type, '\\') ? $type : '\\think\\log\\alarm\\' . ucwords($type);
unset($config['type']);
self::$alarm = new $class($config['alarm']);
// 记录初始化信息

View File

@@ -77,7 +77,7 @@ class Response
$type = empty($type) ? 'null' : strtolower($type);
if (!isset(self::$instance[$type])) {
$class = (isset($options['namespace']) ? $options['namespace'] : '\\think\\response\\') . ucfirst($type);
$class = strpos($type, '\\') ? $type : '\\think\\response\\' . ucfirst($type);
if (class_exists($class)) {
$response = new $class($data, $type, $options);
} else {

View File

@@ -89,7 +89,7 @@ class Session
}
if (!empty($config['type'])) {
// 读取session驱动
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\session\\driver\\') . ucwords($config['type']);
$class = strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
// 检查驱动类
if (!class_exists($class) || !session_set_save_handler(new $class($config))) {

View File

@@ -49,7 +49,6 @@ class Template
'cache_id' => '', // 模板缓存ID
'tpl_replace_string' => [],
'tpl_var_identify' => 'array', // .语法变量识别array|object|'', 为空时自动识别
'namespace' => '\\think\\template\\driver\\',
];
private $literal = [];
@@ -71,7 +70,7 @@ class Template
// 初始化模板编译存储器
$type = $this->config['compile_type'] ? $this->config['compile_type'] : 'File';
$class = $this->config['namespace'] . ucwords($type);
$class = strpos($type, '\\') ? $type : '\\think\\template\\driver\\' . ucwords($type);
$this->storage = new $class();
}

View File

@@ -83,7 +83,7 @@ class View
$type = !empty($options['type']) ? $options['type'] : 'Think';
}
$class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\view\\driver\\') . ucfirst($type);
$class = strpos($type, '\\') ? $type : '\\think\\view\\driver\\' . ucfirst($type);
if (isset($options['type'])) {
unset($options['type']);
}

View File

@@ -284,7 +284,7 @@ abstract class Connection
if ($this->linkID) {
return $this->linkID->getAttribute(PDO::ATTR_DRIVER_NAME);
} else {
return $this->config['type'];
return basename(str_replace('\\', '/', $this->config['type']));
}
}

View File

@@ -960,7 +960,7 @@ class Query
{
$config = array_merge(Config::get('paginate'), $config);
$listRows = $listRows ?: $config['list_rows'];
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
$class = strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([
$class,
'getCurrentPage',

View File

@@ -156,8 +156,7 @@ class sessionTest extends \PHPUnit_Framework_TestCase
'use_cookies' => '1',
'cache_limiter' => '60',
'cache_expire' => '60',
'type' => 'memcache', //
'namespace' => '\\think\\session\\driver\\', // ?
'type' => '\\think\\session\\driver\\Memcache', //
'auto_start' => '1',
];