From a746982703f4bbc598cc03cb6454380275b5c13e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 26 Dec 2015 17:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E8=AE=BE=E8=AE=A1=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BD=BF=E7=94=A8=20namespace=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E9=BB=98=E8=AE=A4=E5=91=BD=E5=90=8D=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache.php | 9 +++++---- library/think/config.php | 2 +- library/think/db.php | 2 +- library/think/log.php | 4 ++-- library/think/session.php | 2 +- library/think/template.php | 8 +++++++- library/think/view.php | 3 ++- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/library/think/cache.php b/library/think/cache.php index abacae0e..4a67ebf3 100644 --- a/library/think/cache.php +++ b/library/think/cache.php @@ -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; } diff --git a/library/think/config.php b/library/think/config.php index 4ad4b38c..f2b770ba 100644 --- a/library/think/config.php +++ b/library/think/config.php @@ -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); } diff --git a/library/think/db.php b/library/think/db.php index 5459f236..d05e0c42 100644 --- a/library/think/db.php +++ b/library/think/db.php @@ -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]; diff --git a/library/think/log.php b/library/think/log.php index c23d349d..55d73faf 100644 --- a/library/think/log.php +++ b/library/think/log.php @@ -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']); } diff --git a/library/think/session.php b/library/think/session.php index 70f6c1ba..ecaed5c1 100644 --- a/library/think/session.php +++ b/library/think/session.php @@ -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); diff --git a/library/think/template.php b/library/think/template.php index 98eb7be6..faf130d4 100644 --- a/library/think/template.php +++ b/library/think/template.php @@ -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 { diff --git a/library/think/view.php b/library/think/view.php index 17b31b0a..d3503fc9 100644 --- a/library/think/view.php +++ b/library/think/view.php @@ -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;