diff --git a/Think/Cache.php b/Think/Cache.php index 930307fa..95549205 100644 --- a/Think/Cache.php +++ b/Think/Cache.php @@ -27,12 +27,8 @@ class Cache { static public function connect($options=[]) { $type = !empty($options['type'])?$options['type']:'File'; $class = 'Think\\Cache\\Driver\\'.ucwords($type); - if(class_exists($class)) { - self::$handler = new $class($options); - return self::$handler; - }else{ - E('_CACHE_TYPE_INVALID_:'.$type); - } + self::$handler = new $class($options); + return self::$handler; } static public function __callStatic($method, $params){ diff --git a/Think/Config.php b/Think/Config.php index 511e65ae..42b66eb7 100644 --- a/Think/Config.php +++ b/Think/Config.php @@ -21,11 +21,7 @@ class Config { // 解析其他格式的配置参数 static public function parse($config,$type,$range=''){ $class = '\Think\Config\Driver\\'.ucwords($type); - if(class_exists($class)) { - self::set((new $class())->parse($config),'',$range); - }else{ - E('class not exists: ' . $class); - } + self::set((new $class())->parse($config),'',$range); } // 加载配置文件 diff --git a/Think/Db.php b/Think/Db.php index f3561ee0..7aacd44f 100644 --- a/Think/Db.php +++ b/Think/Db.php @@ -33,11 +33,7 @@ class Db { $options = self::parseConfig($config); // 如果采用lite方式 仅支持原生SQL 包括query和execute方法 $class = $lite? 'Think\Db\Lite' : 'Think\\Db\\Driver\\'.ucwords($options['dbms']); - if(class_exists($class)) { - self::$instance[$md5] = new $class($options); - }else{ - E('_DB_TYPE_INVALID_:'.$options['dbms']); - } + self::$instance[$md5] = new $class($options); } self::$_instance = self::$instance[$md5]; return self::$_instance; diff --git a/Think/Error.php b/Think/Error.php index 40e03c08..0c7884a8 100644 --- a/Think/Error.php +++ b/Think/Error.php @@ -41,7 +41,7 @@ class Error { case E_PARSE: case E_CORE_ERROR: case E_COMPILE_ERROR: - case E_USER_ERROR: + case E_USER_ERROR:echo ("2"); $errorStr = "[$errno] $errstr ".$errfile." 第 $errline 行."; Log::write($errorStr,'ERROR'); self::halt($errorStr); diff --git a/Think/Image.php b/Think/Image.php index 45f92c86..bfb0b0a5 100644 --- a/Think/Image.php +++ b/Think/Image.php @@ -51,12 +51,8 @@ class Image { public function init($type = 'Gd', $imgname = null){ /* 引入处理库,实例化图片处理对象 */ $class = '\Think\Image\Driver\\'.ucwords($type); - if(class_exists($class)) { - self::$im = new $class($imgname); - return self::$im; - }else{ - throw new Exception('不支持的图片处理库类型'); - } + self::$im = new $class($imgname); + return self::$im; } // 调用驱动类的方法 diff --git a/Think/Log.php b/Think/Log.php index 5de3eff3..27770ccd 100644 --- a/Think/Log.php +++ b/Think/Log.php @@ -19,14 +19,9 @@ class Log { if(!empty($config['type'])) { // 读取log驱动 $class = 'Think\\Log\\Driver\\'. ucwords(strtolower($config['type'])); // 检查驱动类 - if(class_exists($class)) { - unset($config['type']); - self::$handler = new $class($config); - return self::$handler; - }else { - // 类没有定义 - E(L('_CLASS_NOT_EXIST_').': ' . $class); - } + unset($config['type']); + self::$handler = new $class($config); + return self::$handler; } } diff --git a/Think/Oauth.php b/Think/Oauth.php index a39563ca..a2e73bb5 100644 --- a/Think/Oauth.php +++ b/Think/Oauth.php @@ -34,12 +34,8 @@ class Oauth { */ static public function connect($type,$options=[]) { $class = 'Think\\Oauth\\Driver\\'.ucwords($type); - if(class_exists($class)) { - self::$handler = new $class($options); - return self::$handler; - }else{ - E('_OAUTH_TYPE_INVALID_:'.$type); - } + self::$handler = new $class($options); + return self::$handler; } // 跳转到授权登录页面 diff --git a/Think/Parser.php b/Think/Parser.php index 63e8bb32..0091fef8 100644 --- a/Think/Parser.php +++ b/Think/Parser.php @@ -16,13 +16,9 @@ class Parser { // 解析内容 static public function parse($content,$type){ - $class = '\Think\Parser\Driver\\'.ucwords($type); - if(class_exists($class)) { - $parse = new $class(); - return $parse->parse($content); - }else{ - E(L('_CLASS_NOT_EXIST_').': ' . $class); - } + $class = '\\Think\\Parser\\Driver\\'.ucwords($type); + $parse = new $class(); + return $parse->parse($content); } // 调用驱动类的方法 diff --git a/Think/Template.php b/Think/Template.php index 44cafb1d..6d741b21 100644 --- a/Think/Template.php +++ b/Think/Template.php @@ -426,7 +426,7 @@ class Template { protected function parseTagLib($tagLib,&$content,$hide=false) { $begin = $this->config['taglib_begin']; $end = $this->config['taglib_end']; - $className = 'Think\\Template\\Taglib\\'.ucwords($tagLib); + $className = '\\Think\\Template\\Taglib\\'.ucwords($tagLib); $tLib = new $className; foreach ($tLib->getTags() as $name=>$val){ $tags = [$name]; @@ -682,7 +682,9 @@ class Template { $parseStr = $this->parseTemplateName($tmplPublicName); // 替换变量 foreach ($vars as $key=>$val) { - $parseStr = str_replace('['.$key.']',$val,$parseStr); + if(strpos($val,'['.$key.']')) { + $parseStr = str_replace('['.$key.']',$val,$parseStr); + } } // 再次对包含文件进行模板分析 return $this->parseInclude($parseStr); diff --git a/Think/View.php b/Think/View.php index 165c4a7a..a0fbc3f2 100644 --- a/Think/View.php +++ b/Think/View.php @@ -12,8 +12,7 @@ namespace Think; class View { - public $engine = null; // 模板引擎 - protected $template = null; // 模板文件 + protected $engine = null; // 模板引擎实例 protected $data = []; // 模板变量 protected $config = []; // 视图参数 @@ -38,7 +37,7 @@ class View { * @param mixed $name * @param mixed $value */ - public function __set($name,$value){ + public function __set($name,$value=''){ $this->config[$name] = $value; } @@ -50,7 +49,7 @@ class View { } public function engine($engine,$config=[]){ - $class = '\Think\View\Driver\\'.ucwords($engine); + $class = '\\Think\\View\\Driver\\'.ucwords($engine); $this->engine = new $class($config); return $this; } @@ -59,13 +58,15 @@ class View { * 加载模板和页面输出 可以返回输出内容 * @access public * @param string $template 模板文件名 + * @param array $vars 模板输出变量 + * @param string $cacheId 模板缓存标识 * @param boolean $return 是否返回 * @return mixed */ - public function display($template='',$vars=[],$return=false) { + public function display($template='',$vars=[],$cacheId,$return=false) { Tag::listen('view_begin',$template); // 解析并获取模板内容 - $content = $this->fetch($template,$vars); + $content = $this->fetch($template,$vars,$cacheId); // 输出模板内容 if($return) { return $content; @@ -79,23 +80,24 @@ class View { * @access protected * @param string $template 模板文件名或者内容 * @param array $vars 模板输出变量 + * @param string $cacheId 模板缓存标识 * @return string */ - protected function fetch($template,$vars=[]) { + protected function fetch($template,$vars=[],$cacheId='') { Tag::listen('view_template',$template); $vars = $vars?$vars:$this->data; // 页面缓存 ob_start(); ob_implicit_flush(0); if($this->engine) { // 指定模板引擎 - $this->engine->fetch($template,$vars); - }else{ + $this->engine->fetch($template,$vars,$cacheId); + }else{ // 原生PHP解析 extract($vars, EXTR_OVERWRITE); is_file($template)?include $template:eval('?>'.$template); } // 获取并清空缓存 $content = ob_get_clean(); - Tag::listen('content_filter',$content); + Tag::listen('view_filter',$content); // 输出模板文件 return $content; } diff --git a/Think/View/Driver/Think.php b/Think/View/Driver/Think.php index c442cc7d..0f1929d2 100644 --- a/Think/View/Driver/Think.php +++ b/Think/View/Driver/Think.php @@ -17,8 +17,12 @@ class Think { $this->template = new Template($config); } - public function fetch($template,$data=[]){ - $this->template->display($template,$data); + public function fetch($template,$data=[],$cacheId=''){ + if(is_file($template)) { + $this->template->display($template,$data,$cacheId); + }else{ + $this->template->fetch($template,$data); + } } } \ No newline at end of file