diff --git a/library/think/Cache.php b/library/think/Cache.php index fd011d5d..3695cd12 100644 --- a/library/think/Cache.php +++ b/library/think/Cache.php @@ -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'); diff --git a/library/think/Config.php b/library/think/Config.php index c998e4d6..ecae1378 100644 --- a/library/think/Config.php +++ b/library/think/Config.php @@ -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); } diff --git a/library/think/Db.php b/library/think/Db.php index be219898..0acae8f5 100644 --- a/library/think/Db.php +++ b/library/think/Db.php @@ -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) { diff --git a/library/think/Log.php b/library/think/Log.php index 709da31e..9404f614 100644 --- a/library/think/Log.php +++ b/library/think/Log.php @@ -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']); // 记录初始化信息 diff --git a/library/think/Response.php b/library/think/Response.php index 9507b698..72218758 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -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 { diff --git a/library/think/Session.php b/library/think/Session.php index ade2a917..c2d8fab0 100644 --- a/library/think/Session.php +++ b/library/think/Session.php @@ -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))) { diff --git a/library/think/Template.php b/library/think/Template.php index 36654aeb..55ae8649 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -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(); } diff --git a/library/think/View.php b/library/think/View.php index 84f2e428..e72e77c2 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -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']); } diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index 6fc5b777..089027c0 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -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'])); } } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index ae315771..17cafea9 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -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', diff --git a/tests/thinkphp/library/think/sessionTest.php b/tests/thinkphp/library/think/sessionTest.php index 8c3c2d53..76c18ef0 100644 --- a/tests/thinkphp/library/think/sessionTest.php +++ b/tests/thinkphp/library/think/sessionTest.php @@ -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', ];