修正taglib类的一处配置调用错误 增加 traits\controller\response

This commit is contained in:
thinkphp
2015-12-24 11:16:16 +08:00
parent 1bf0b2361c
commit 1b61dab806
4 changed files with 127 additions and 50 deletions

View File

@@ -70,7 +70,10 @@ class Response
}
}
if ($return) return $data;
if ($return) {
return $data;
}
echo $data;
self::isExit() && exit();
}
@@ -94,7 +97,10 @@ class Response
*/
public static function type($type = null)
{
if(is_null($type)) return self::$type;
if (is_null($type)) {
return self::$type;
}
self::$type = $type;
}
@@ -117,7 +123,10 @@ class Response
*/
public static function isExit($exit = null)
{
if(is_null($exit)) return self::$isExit;
if (is_null($exit)) {
return self::$isExit;
}
self::$isExit = (boolean) $exit;
}
@@ -138,17 +147,20 @@ class Response
'time' => NOW_TIME,
'data' => $data,
];
if($type) self::type($type);
if ($type) {
self::type($type);
}
return $result;
}
/**
* 返回封装后的API数据到客户端
* 操作成功跳转的快捷方法
* @access public
* @param mixed $msg 要返回的数据
* @param mixed $data 返回的code
* @param mixed $url 提示信息
* @param mixed $wait 返回数据格式
* @param mixed $msg 提示信息
* @param mixed $data 返回的数据
* @param mixed $url 跳转的URL地址
* @param mixed $wait 跳转等待时间
* @return void
*/
public static function success($msg = '', $data = '', $url = '', $wait = 3)
@@ -172,12 +184,12 @@ class Response
}
/**
* 返回封装后的API数据到客户端
* 操作错误跳转的快捷方法
* @access public
* @param mixed $msg 要返回的数据
* @param mixed $data 返回的code
* @param mixed $url 提示信息
* @param mixed $wait 返回数据格式
* @param mixed $msg 提示信息
* @param mixed $data 返回的数据
* @param mixed $url 跳转的URL地址
* @param mixed $wait 跳转等待时间
* @return void
*/
public static function error($msg = '', $data = '', $url = '', $wait = 3)

View File

@@ -118,6 +118,8 @@ class Template
{
if (is_array($config)) {
$this->config = array_merge($this->config, $config);
} elseif (isset($this->config[$config])) {
return $this->config[$config];
}
}
@@ -653,7 +655,7 @@ class Template
break;
case '/': // 注释标签
$flag2 = substr($str, 1, 1);
if ($flag2 == '/' || ($flag2 == '*' && substr(rtrim($str), -2) == '*/')) {
if ('/' == $flag2 || ('*' == $flag2 && substr(rtrim($str), -2) == '*/')) {
$str = '';
}
break;
@@ -690,7 +692,7 @@ class Template
if (strpos($match[0], '.')) {
$vars = explode('.', $match[0]);
$first = array_shift($vars);
if ($first == '$Think') {
if ('$Think' == $first) {
// 所有以Think.打头的以特殊变量对待 无需模板赋值就可以输出
$parseStr = $this->parseThinkVar($vars);
} else {

View File

@@ -108,7 +108,7 @@ class TagLib
if (preg_match_all($regex, $content, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
$right = [];
foreach ($matches as $match) {
if ($match[1][0] == '') {
if ('' == $match[1][0]) {
$name = $match[2][0];
// 如果有没闭合的标签头则取出最后一个
if (!empty($right[$name])) {
@@ -116,7 +116,7 @@ class TagLib
$nodes[$match[0][1]] = [
'name' => $name,
'begin' => array_pop($right[$name]), // 标签开始符
'end' => $match[0] // 标签结束符
'end' => $match[0], // 标签结束符
];
} else {
continue;
@@ -193,8 +193,8 @@ class TagLib
*/
private function getRegex($tags, $close)
{
$begin = $this->tpl->config['taglib_begin'];
$end = $this->tpl->config['taglib_end'];
$begin = $this->tpl->config('taglib_begin');
$end = $this->tpl->config('taglib_end');
$single = strlen(ltrim($begin, '\\')) == 1 && strlen(ltrim($end, '\\')) == 1 ? true : false;
if (is_array($tags)) {
$tagName = implode('|', $tags);
@@ -322,8 +322,8 @@ class TagLib
if (!empty($this->tags[$tag]['expression'])) {
static $_taglibs;
if (!isset($_taglibs[$tag])) {
$_taglibs[$tag][0] = strlen($this->tpl->config['taglib_begin'] . $tag);
$_taglibs[$tag][1] = strlen($this->tpl->config['taglib_end']);
$_taglibs[$tag][0] = strlen($this->tpl->config('taglib_begin') . $tag);
$_taglibs[$tag][1] = strlen($this->tpl->config('taglib_end'));
}
$str = substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1]);
$result['expression'] = trim($str);
@@ -360,7 +360,8 @@ class TagLib
if (':' == $flag) {
// 以:开头为函数调用,解析前去掉:
$name = substr($name, 1);
} elseif ('$' != $flag && preg_match('/[a-zA-Z_]/', $flag)) { // XXX: 这句的写法可能还需要改进
} elseif ('$' != $flag && preg_match('/[a-zA-Z_]/', $flag)) {
// XXX: 这句的写法可能还需要改进
// 常量不需要解析
if (defined($name)) {
return $name;

View File

@@ -0,0 +1,62 @@
<?php
/**
* 用法:
* T('controller/response');
* class index
* {
* use \traits\controller\response;
* public function index(){
* $this->error();
* $this->redirect();
* }
* }
*/
namespace traits\controller;
trait Response
{
// 视图类实例
protected $view = null;
/**
* 操作错误跳转的快捷方法
* @access public
* @param mixed $msg 提示信息
* @param mixed $data 返回的数据
* @param mixed $url 跳转的URL地址
* @param mixed $wait 跳转等待时间
* @return void
*/
public function error($msg = '', $data = '', $url = '', $wait = 3)
{
return Response::error($msg, $data, $url, $wait);
}
/**
* 操作成功跳转的快捷方法
* @access public
* @param mixed $msg 提示信息
* @param mixed $data 返回的数据
* @param mixed $url 跳转的URL地址
* @param mixed $wait 跳转等待时间
* @return void
*/
public function success($msg = '', $data = '', $url = '', $wait = 3)
{
return Response::success($msg, $data, $url, $wait);
}
/**
* URL重定向
* @access protected
* @param string $url 跳转的URL表达式
* @param array|int $params 其它URL参数或http code
* @return void
*/
public function redirect($url, $params = [])
{
return Response::redirect($url, $params);
}
}