From 362be0ae3e2358b84f6e985a0a7ec16b7cb1db84 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Dec 2015 21:27:42 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E4=BF=AE=E6=AD=A3URL=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=AF=B9=E5=AD=90=E5=9F=9F=E5=90=8D=E9=83=A8=E7=BD=B2=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 13 ++++++++----- library/think/url.php | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index b6a7ced8..8cd37249 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -251,7 +251,10 @@ class App // 检测域名部署 if (!IS_CLI && !empty($config['url_domain_deploy'])) { - if ($match = Route::checkDomain($config['url_domain_rules'])) { + if ($config['url_domain_rules']) { + Route::domain($config['url_domain_rules']); + } + if ($match = Route::checkDomain()) { (!defined('BIND_MODULE') && !empty($match[0])) && define('BIND_MODULE', $match[0]); (!defined('BIND_CONTROLLER') && !empty($match[1])) && define('BIND_CONTROLLER', $match[1]); (!defined('BIND_ACTION') && !empty($match[2])) && define('BIND_ACTION', $match[2]); @@ -292,10 +295,10 @@ class App $depr = $config['pathinfo_depr']; // 还原劫持后真实pathinfo $path_info = - (defined('BIND_MODULE') ? BIND_MODULE . $depr : '') . - (defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') . - (defined('BIND_ACTION') ? BIND_ACTION . $depr : '') . - $_SERVER['PATH_INFO']; + (defined('BIND_MODULE') ? BIND_MODULE . $depr : '') . + (defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') . + (defined('BIND_ACTION') ? BIND_ACTION . $depr : '') . + $_SERVER['PATH_INFO']; // 路由检测 if (!empty($config['url_route_on'])) { diff --git a/library/think/url.php b/library/think/url.php index 1157bc9b..fe8e38a4 100644 --- a/library/think/url.php +++ b/library/think/url.php @@ -139,9 +139,10 @@ class Url $domain = 'localhost' == $domain ? 'localhost' : 'www' . strstr($_SERVER['HTTP_HOST'], '.'); // '子域名'=>array('项目[/分组]'); foreach (Config::get('url_domain_rules') as $key => $rule) { - if (false === strpos($key, '*') && 0 === strpos($url, $rule[0])) { + $rule = is_array($rule) ? $rule[0] : $rule; + if (false === strpos($key, '*') && 0 === strpos($url, $rule)) { $domain = $key . strstr($domain, '.'); // 生成对应子域名 - $url = substr_replace($url, '', 0, strlen($rule[0])); + $url = substr_replace($url, '', 0, strlen($rule)); break; } } From 2c0240cd42aeedfbbce3de0e2b08a5f8a881e5ba Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Dec 2015 21:50:31 +0800 Subject: [PATCH 02/25] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/url.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/url.php b/library/think/url.php index fe8e38a4..56b70b3f 100644 --- a/library/think/url.php +++ b/library/think/url.php @@ -134,7 +134,7 @@ class Url $domain = $host . (strpos($host, '.') ? '' : strstr($_SERVER['HTTP_HOST'], '.')); } elseif (true === $domain) { $domain = $_SERVER['HTTP_HOST']; - if (Config::get('url_domain_deplay')) { + if (Config::get('url_domain_deploy')) { // 开启子域名部署 $domain = 'localhost' == $domain ? 'localhost' : 'www' . strstr($_SERVER['HTTP_HOST'], '.'); // '子域名'=>array('项目[/分组]'); From 6b42f979efaf247c0207fe7177bf60b9838df6e8 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Dec 2015 22:02:36 +0800 Subject: [PATCH 03/25] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=AD=90=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/route.php | 12 +++++++----- library/think/url.php | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/library/think/route.php b/library/think/route.php index e84b0ffc..497ab878 100644 --- a/library/think/route.php +++ b/library/think/route.php @@ -34,32 +34,34 @@ class Route // 添加URL映射规则 public static function map($map, $route = '') { - self::setting('map', $map, $route); + return self::setting('map', $map, $route); } // 添加变量规则 public static function pattern($name, $rule = '') { - self::setting('pattern', $name, $rule); + return self::setting('pattern', $name, $rule); } // 添加路由别名 public static function alias($name, $rule = '') { - self::setting('alias', $name, $rule); + return self::setting('alias', $name, $rule); } // 添加子域名部署规则 public static function domain($domain, $rule = '') { - self::setting('domain', $domain, $rule); + return self::setting('domain', $domain, $rule); } // 属性设置 - private static function setting($var, $name, $value = '') + private static function setting($var, $name = '', $value = '') { if (is_array($name)) { self::${$var} = array_merge(self::${$var}, $name); + } elseif (empty($name)) { + return self::${$var}; } else { self::${$var}[$name] = $value; } diff --git a/library/think/url.php b/library/think/url.php index 56b70b3f..ad71f311 100644 --- a/library/think/url.php +++ b/library/think/url.php @@ -137,8 +137,8 @@ class Url if (Config::get('url_domain_deploy')) { // 开启子域名部署 $domain = 'localhost' == $domain ? 'localhost' : 'www' . strstr($_SERVER['HTTP_HOST'], '.'); - // '子域名'=>array('项目[/分组]'); - foreach (Config::get('url_domain_rules') as $key => $rule) { + // '子域名'=>['模块[/控制器/操作]']; + foreach (Route::domain() as $key => $rule) { $rule = is_array($rule) ? $rule[0] : $rule; if (false === strpos($key, '*') && 0 === strpos($url, $rule)) { $domain = $key . strstr($domain, '.'); // 生成对应子域名 From 247b76d9c023ba0f9a177f605c205e2b83582878 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 21 Dec 2015 23:35:59 +0800 Subject: [PATCH 04/25] =?UTF-8?q?=E7=82=B9=E8=AF=AD=E6=B3=95=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E8=87=AA=E5=8A=A8=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/template.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/template.php b/library/think/template.php index 1aa3cce8..82d420a4 100644 --- a/library/think/template.php +++ b/library/think/template.php @@ -615,10 +615,14 @@ class Template $vars = explode('.', $var); $var = array_shift($vars); $name = '$' . $var; - foreach ($vars as $key => $val) { - $name .= '["' . $val . '"]'; + if (count($vars) > 1) { + foreach ($vars as $key => $val) { + $name .= '["' . $val . '"]'; + } + } else { + // 一维自动识别对象和数组 + $name = 'is_array($' . $var . ')?$' . $var . '["' . $vars[0] . '"]:$' . $var . '->' . $vars[0]; } - } elseif (false !== strpos($var, '[')) { //支持 {$var['key']} 方式输出数组 $name = "$" . $var; From 0e6afef0bee86105389c759f81360dbc80ac7185 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 08:05:34 +0800 Subject: [PATCH 05/25] =?UTF-8?q?=E5=8E=BB=E6=8E=89get=5Fclient=5Fip?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/org/oauth/driver/tencent.php | 2 +- library/traits/model/auto.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/org/oauth/driver/tencent.php b/library/org/oauth/driver/tencent.php index 2afa2d2c..d72df952 100644 --- a/library/org/oauth/driver/tencent.php +++ b/library/org/oauth/driver/tencent.php @@ -47,7 +47,7 @@ class Tencent extends Driver 'oauth_consumer_key' => $this->AppKey, 'access_token' => $this->token['access_token'], 'openid' => $this->openid(), - 'clientip' => get_client_ip(), + 'clientip' => $_SERVER['REMOTE_ADDR'], 'oauth_version' => '2.a', 'scope' => 'all', 'format' => 'json', diff --git a/library/traits/model/auto.php b/library/traits/model/auto.php index dabc85c7..a52038ab 100644 --- a/library/traits/model/auto.php +++ b/library/traits/model/auto.php @@ -361,9 +361,9 @@ trait Auto } return NOW_TIME >= $start && NOW_TIME <= $end; case 'ip_allow': // IP 操作许可验证 - return in_array(get_client_ip(), explode(',', $rule)); + return in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule)); case 'ip_deny': // IP 操作禁止验证 - return !in_array(get_client_ip(), explode(',', $rule)); + return !in_array($_SERVER['REMOTE_ADDR'], explode(',', $rule)); case 'filter': // 使用filter_var验证 $result = filter_var($value, is_int($rule) ? $rule : filter_id($rule)); return false === $result ? false : true; From 5b75506aa7fcef690306558286197a2abb8d06b6 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 11:59:02 +0800 Subject: [PATCH 06/25] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=87=A0=E5=A4=84Notic?= =?UTF-8?q?e=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 2 +- library/think/db/driver.php | 2 +- library/think/db/driver/mongo.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index 8cd37249..de6519f3 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -303,7 +303,7 @@ class App // 路由检测 if (!empty($config['url_route_on'])) { // 开启路由 则检测路由配置 - Route::register($config['route']); + Route::register(!empty($config['route'])?$config['route']:null); $result = Route::check($path_info, $depr); if (false === $result) { // 路由无效 diff --git a/library/think/db/driver.php b/library/think/db/driver.php index 1be594a9..66d71ff1 100644 --- a/library/think/db/driver.php +++ b/library/think/db/driver.php @@ -1148,7 +1148,7 @@ abstract class Driver */ protected function debug($start) { - if ($this->config['debug']) { + if (!empty($this->config['debug'])) { // 开启数据库调试模式 if ($start) { Debug::remark('queryStartTime', 'time'); diff --git a/library/think/db/driver/mongo.php b/library/think/db/driver/mongo.php index 53f83c14..78962a57 100644 --- a/library/think/db/driver/mongo.php +++ b/library/think/db/driver/mongo.php @@ -70,7 +70,7 @@ class Mongo extends Driver $host = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . '/' . ($config['database'] ? "{$config['database']}" : ''); try { - $this->linkID[$linkNum] = new \mongoClient($host, $this->config['params']); + $this->linkID[$linkNum] = new \mongoClient($host, !empty($this->config['params'])?$this->config['params']:array()); } catch (\MongoConnectionException $e) { throw new Exception($e->getmessage()); } @@ -105,7 +105,7 @@ class Mongo extends Driver $this->_mongo = $this->_linkID->selectDb($db); } // 当前MongoCollection对象 - if ($this->config['debug']) { + if (!empty($this->config['debug'])) { $this->queryStr = $this->_dbName . '.getCollection(' . $collection . ')'; } if ($this->_collectionName != $collection) { @@ -519,7 +519,7 @@ class Mongo extends Driver $this->model = $options['model']; $this->queryTimes++; $query = $this->parseWhere($options['where']); - if ($this->config['debug']) { + if (!empty($this->config['debug'])) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName; $this->queryStr .= $query ? '.find(' . json_encode($query) . ')' : ''; $this->queryStr .= '.count()'; From 743bffb381b2c7e6b9c9e5600e7c7f86e3af1a22 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 13:22:49 +0800 Subject: [PATCH 07/25] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E5=A4=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E7=9A=84Notice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/route.php b/library/think/route.php index 497ab878..88d3cc94 100644 --- a/library/think/route.php +++ b/library/think/route.php @@ -311,7 +311,7 @@ class Route $rule = array_shift($val); } // 单项路由 - $route = $val['route']; + $route = !empty($val['route'])?$val['route']:''; if (0 === strpos($rule, '/') && preg_match($rule, $url, $matches)) { return self::checkRegex($route, $url, $matches); } else { From bbf8c03b514847f2ae8b9871c9a5fd59c67e057b Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 13:29:37 +0800 Subject: [PATCH 08/25] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=87=A0=E5=A4=84?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E5=87=BD=E6=95=B0=E9=87=8D=E8=BD=BD=E6=97=B6?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=8E=E7=88=B6=E7=B1=BB=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E8=80=8C=E5=87=BA=E7=8E=B0=E7=9A=84warn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/driver/mongo.php | 4 ++-- library/think/model/mongo.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/think/db/driver/mongo.php b/library/think/db/driver/mongo.php index 78962a57..7efd1002 100644 --- a/library/think/db/driver/mongo.php +++ b/library/think/db/driver/mongo.php @@ -61,7 +61,7 @@ class Mongo extends Driver * @return * @throws Exception */ - public function connect($config = '', $linkNum = 0) + public function connect($config = '', $linkNum = 0, $autoConnection = false) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { @@ -249,7 +249,7 @@ class Mongo extends Driver * @return bool * @throws Exception */ - public function insertAll($dataList, $options = []) + public function insertAll($dataList, $options = [], $replace = false) { if (isset($options['table'])) { $this->switchCollection($options['table']); diff --git a/library/think/model/mongo.php b/library/think/model/mongo.php index ab599481..6764cf90 100644 --- a/library/think/model/mongo.php +++ b/library/think/model/mongo.php @@ -101,7 +101,7 @@ class Mongo extends \Think\Model } // 插入数据前的回调方法 - protected function _before_insert(&$data, $options) + protected function _before_insert(&$data, $options = []) { // 写入数据到数据库 if ($this->_autoInc && self::TYPE_INT == $this->_idType) { @@ -119,7 +119,7 @@ class Mongo extends \Think\Model } // 查询成功后的回调方法 - protected function _after_select(&$resultSet, $options) + protected function _after_select(&$resultSet, $options = []) { array_walk($resultSet, [$this, 'checkMongoId']); } @@ -185,7 +185,7 @@ class Mongo extends \Think\Model * @param integer $step 增长值 * @return boolean */ - public function setInc($field, $step = 1) + public function setInc($field, $step = 1, $lazyTime = 0) { return $this->setField($field, ['inc', $step]); } @@ -197,7 +197,7 @@ class Mongo extends \Think\Model * @param integer $step 减少值 * @return boolean */ - public function setDec($field, $step = 1) + public function setDec($field, $step = 1, $lazyTime = 0) { return $this->setField($field, ['inc', '-' . $step]); } From 92be99e35f3e0cfb117a39924d32add2f2175674 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 13:32:04 +0800 Subject: [PATCH 09/25] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=A4=E5=A4=84warn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/driver/mongo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/db/driver/mongo.php b/library/think/db/driver/mongo.php index 7efd1002..1cc52cc0 100644 --- a/library/think/db/driver/mongo.php +++ b/library/think/db/driver/mongo.php @@ -483,9 +483,9 @@ class Mongo extends Driver } $this->model = $options['model']; $this->queryTimes++; - $query = $this->parseWhere($options['where']); - $fields = $this->parseField($options['field']); - if ($this->config['debug']) { + $query = $this->parseWhere(!empty($options['where'])?$options['where']:''); + $fields = $this->parseField(!empty($options['field'])?$options['field']:''); + if (!empty($this->config['debug'])) { $this->queryStr = $this->_dbName . '.' . $this->_collectionName . '.findOne('; $this->queryStr .= $query ? json_encode($query) : '{}'; $this->queryStr .= $fields ? ',' . json_encode($fields) : ''; From 429af2f86b221e987b011e6f68b3798a6bd74180 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 14:16:50 +0800 Subject: [PATCH 10/25] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E8=BF=9E=E6=93=8D=E4=BD=9C=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=EF=BC=9A=20return=20View::getInstance(Config::get())-?= =?UTF-8?q?>assign($vars)->fetch();?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/think/view.php b/library/think/view.php index d831c8ee..dc81dfc0 100644 --- a/library/think/view.php +++ b/library/think/view.php @@ -40,6 +40,14 @@ class View $this->config($config); $this->engine($this->config['engine_type']); } + /** + * 初始化视图 + * @access public + * @param array $config 配置参数 + */ + static public function getInstance(array $config = []){ + return self($config); + } /** * 模板变量赋值 @@ -55,6 +63,7 @@ class View } else { $this->data[$name] = $value; } + return $this; } /** From f6acdd1578ee3953774736c4bbf06482897d1bb0 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 14:18:35 +0800 Subject: [PATCH 11/25] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E8=BF=9E=E6=93=8D=E4=BD=9C=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=EF=BC=9A=20return=20View::getInstance(Config::get())-?= =?UTF-8?q?>assign($vars)->fetch();?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/view.php b/library/think/view.php index dc81dfc0..5122b749 100644 --- a/library/think/view.php +++ b/library/think/view.php @@ -46,7 +46,7 @@ class View * @param array $config 配置参数 */ static public function getInstance(array $config = []){ - return self($config); + return new self($config); } /** From d28dbf644eab3a6adf659cc120261654703a200f Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 15:18:25 +0800 Subject: [PATCH 12/25] =?UTF-8?q?=E7=AE=80=E5=8C=96=E4=B8=A4=E5=A4=84?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index de6519f3..039e6a04 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -110,12 +110,10 @@ class App } // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); - // 返回数据 - if (IN_UNIT_TEST) { - return $data; - } else { - Response::returnData($data, Config::get('default_return_type'), Config::get('response_exit')); - } + // 单元测试模式下返回数据 + if (IN_UNIT_TEST) { return $data; } + // 输出数据 + Response::returnData($data, Config::get('default_return_type'), Config::get('response_exit')); } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); @@ -127,12 +125,10 @@ class App $data = $method->invokeArgs($instance, [$action, '']); // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); - // 返回数据 - if (IN_UNIT_TEST) { - return $data; - } else { - Response::returnData($data, Config::get('default_return_type'), Config::get('response_exit')); - } + // 单元测试模式下返回数据 + if (IN_UNIT_TEST) { return $data; } + // 输出数据 + Response::returnData($data, Config::get('default_return_type'), Config::get('response_exit')); } else { throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ', 10002); } From a71ed560de85bc3a9a8da8037f3634d7d1e081f8 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 15:25:38 +0800 Subject: [PATCH 13/25] =?UTF-8?q?=E7=AE=80=E5=8C=96App::run()=EF=BC=8C?= =?UTF-8?q?=E7=9C=81=E5=8E=BB=E5=8F=82=E6=95=B0$config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 4 ++-- start.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index 039e6a04..74518c31 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -23,10 +23,10 @@ class App * @access public * @return void */ - public static function run(array $config = []) + public static function run() { // 初始化公共模块 - self::initModule(COMMON_MODULE, $config); + self::initModule(COMMON_MODULE, Config::get()); // 获取配置参数 $config = Config::get(); diff --git a/start.php b/start.php index 6dbd55e2..491ba596 100644 --- a/start.php +++ b/start.php @@ -48,4 +48,4 @@ if ('sae' != APP_MODE && is_file(APP_PATH . 'build.php')) { } // 执行应用 -!IN_UNIT_TEST && App::run(Config::get()); +!IN_UNIT_TEST && App::run(); From f726fbf6d260d8c1c1ecb8768b9228e64e5adff1 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 21 Dec 2015 01:26:35 -0800 Subject: [PATCH 14/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E7=AD=89?= =?UTF-8?q?=20=20Changes=20to=20be=20committed:=20=09modified:=20=20=20tes?= =?UTF-8?q?ts/framework/application/index/controller/indexTest.php=20=09mo?= =?UTF-8?q?dified:=20=20=20tests/framework/thinkphp/library/think/cache/dr?= =?UTF-8?q?iver/apcTest.php=20=09new=20file:=20=20=20tests/framework/think?= =?UTF-8?q?php/library/think/cache/driver/cache=5Ftest=5Fcase.php=20=09mod?= =?UTF-8?q?ified:=20=20=20tests/mock.php=20=09modified:=20=20=20thinkphp/l?= =?UTF-8?q?ibrary/think/cache/driver/apc.php=20=09modified:=20=20=20thinkp?= =?UTF-8?q?hp/start.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/apc.php | 4 +++- start.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/apc.php b/library/think/cache/driver/apc.php index 522b01c5..eb4a7a38 100644 --- a/library/think/cache/driver/apc.php +++ b/library/think/cache/driver/apc.php @@ -25,7 +25,9 @@ class Apc 'prefix' => '', 'length' => 0, ]; - + /***************************** + 需要支持apc_cli模式 + ******************************/ /** * 架构函数 * diff --git a/start.php b/start.php index 491ba596..1d73987b 100644 --- a/start.php +++ b/start.php @@ -46,6 +46,6 @@ if (APP_HOOK && isset($mode['tags'])) { if ('sae' != APP_MODE && is_file(APP_PATH . 'build.php')) { Create::build(include APP_PATH . 'build.php'); } - +Loader::addNamespace('tests',TEST_PATH); // 执行应用 !IN_UNIT_TEST && App::run(); From 9ed8ca5e1785892c05db5e8a71fa769dc18850a3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 15:41:16 +0800 Subject: [PATCH 15/25] =?UTF-8?q?=E6=94=B9=E8=BF=9Bresponse=E7=B1=BB?= =?UTF-8?q?=E7=9A=84returnData=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 9 +++++---- convention.php | 4 ++-- library/think/app.php | 10 +++------- library/think/response.php | 19 ++++++++++++------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/base.php b/base.php index 41002257..edba57ed 100644 --- a/base.php +++ b/base.php @@ -39,6 +39,7 @@ defined('APP_HOOK') or define('APP_HOOK', false); // 是否开启HOOK defined('ENV_PREFIX') or define('ENV_PREFIX', 'T_'); // 环境变量的配置前缀 defined('IS_API') or define('IS_API', false); // 是否API接口 defined('IN_UNIT_TEST') or define('IN_UNIT_TEST', false); // 是否为单元测试 +defined('APP_AUTO_BUILD') or define('APP_AUTO_BUILD', false); // 是否自动生成应用模块 // 应用模式 默认为普通模式 defined('APP_MODE') or define('APP_MODE', function_exists('saeAutoLoader') ? 'sae' : 'common'); @@ -311,11 +312,11 @@ function S($name, $value = '', $options = null) * @param string $level 日志级别 * @return void|array */ -function trace($log='[think]', $level = 'log') +function trace($log = '[think]', $level = 'log') { - if('[think]'==$log){ + if ('[think]' == $log) { return \think\Log::getLog(); - }else{ - \think\Log::record($log,$level); + } else { + \think\Log::record($log, $level); } } diff --git a/convention.php b/convention.php index dffdb4c0..dcf4a58e 100644 --- a/convention.php +++ b/convention.php @@ -13,8 +13,8 @@ return [ 'default_return_type' => 'html', // 默认语言 'default_lang' => 'zh-cn', - // response输出终止执行 - 'response_exit' => true, + // response输出方式 0 echo 1 return 2 exit + 'response_type' => 0, // 默认AJAX 数据返回格式,可选JSON XML ... 'default_ajax_return' => 'JSON', // 默认JSONP格式返回的处理方法 diff --git a/library/think/app.php b/library/think/app.php index 74518c31..4583dae0 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -110,10 +110,8 @@ class App } // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); - // 单元测试模式下返回数据 - if (IN_UNIT_TEST) { return $data; } // 输出数据 - Response::returnData($data, Config::get('default_return_type'), Config::get('response_exit')); + return Response::returnData($data, Config::get('default_return_type'), Config::get('response_type')); } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); @@ -125,10 +123,8 @@ class App $data = $method->invokeArgs($instance, [$action, '']); // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); - // 单元测试模式下返回数据 - if (IN_UNIT_TEST) { return $data; } // 输出数据 - Response::returnData($data, Config::get('default_return_type'), Config::get('response_exit')); + return Response::returnData($data, Config::get('default_return_type'), Config::get('response_type')); } else { throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ', 10002); } @@ -299,7 +295,7 @@ class App // 路由检测 if (!empty($config['url_route_on'])) { // 开启路由 则检测路由配置 - Route::register(!empty($config['route'])?$config['route']:null); + Route::register(!empty($config['route']) ? $config['route'] : null); $result = Route::check($path_info, $depr); if (false === $result) { // 路由无效 diff --git a/library/think/response.php b/library/think/response.php index 7f688193..2f8034fd 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -19,10 +19,10 @@ class Response * @access protected * @param mixed $data 要返回的数据 * @param String $type 返回数据格式 - * @param bool $exit 是否终止执行 + * @param integer $return 是否返回数据 0 echo 1 return 2 exit * @return void */ - public static function returnData($data, $type = '', $exit = true) + public static function returnData($data, $type = '', $return = 0) { $headers = [ 'json' => 'application/json', @@ -52,12 +52,17 @@ class Response $data = $handler . '(' . \org\Transform::jsonEncode($data) . ');'; break; } - //header('Content-Length:' . strlen($data)); - if ($exit) { - exit($data); - } else { - echo $data; + + switch ($return) { + case 1: + return $data; + case 2: + exit($data); + case 0: + default: + echo $data; } + } /** From 4d53e9bc19a685db5a082c5d339eb3433115b8c6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 15:43:37 +0800 Subject: [PATCH 16/25] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B8=B8=E9=87=8F=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.php b/start.php index 1d73987b..8aa7a11a 100644 --- a/start.php +++ b/start.php @@ -43,9 +43,9 @@ if (APP_HOOK && isset($mode['tags'])) { } // 自动生成 -if ('sae' != APP_MODE && is_file(APP_PATH . 'build.php')) { +if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) { Create::build(include APP_PATH . 'build.php'); } -Loader::addNamespace('tests',TEST_PATH); +Loader::addNamespace('tests', TEST_PATH); // 执行应用 !IN_UNIT_TEST && App::run(); From c37aba27d7134fbe048877d2fb71ea02a8e2c11a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 15:55:52 +0800 Subject: [PATCH 17/25] =?UTF-8?q?Create=E7=B1=BB=E6=9B=B4=E5=90=8D?= =?UTF-8?q?=E4=B8=BABuild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/{create.php => build.php} | 7 +++---- mode/common.php | 2 +- start.php | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) rename library/think/{create.php => build.php} (98%) diff --git a/library/think/create.php b/library/think/build.php similarity index 98% rename from library/think/create.php rename to library/think/build.php index bc9e2c8d..0cde3d20 100644 --- a/library/think/create.php +++ b/library/think/build.php @@ -8,15 +8,14 @@ // +---------------------------------------------------------------------- // | Author: liu21st // +---------------------------------------------------------------------- - namespace think; -class Create +class Build { - public static function build($build) + public static function run($build) { // 锁定 - $lockfile = APP_PATH . 'create.lock'; + $lockfile = APP_PATH . 'build.lock'; if (is_writable($lockfile)) { return; } else { diff --git a/mode/common.php b/mode/common.php index 26075e41..5fe4b218 100644 --- a/mode/common.php +++ b/mode/common.php @@ -20,11 +20,11 @@ return [ // 别名定义 'alias' => [ 'think\App' => CORE_PATH . 'app' . EXT, + 'think\Build' => CORE_PATH . 'build' . EXT, 'think\Cache' => CORE_PATH . 'cache' . EXT, 'think\Config' => CORE_PATH . 'config' . EXT, 'think\Controller' => CORE_PATH . 'controller' . EXT, 'think\Cookie' => CORE_PATH . 'cookie' . EXT, - 'think\Create' => CORE_PATH . 'create' . EXT, 'think\Db' => CORE_PATH . 'db' . EXT, 'think\Debug' => CORE_PATH . 'debug' . EXT, 'think\Error' => CORE_PATH . 'error' . EXT, diff --git a/start.php b/start.php index 8aa7a11a..765aa00e 100644 --- a/start.php +++ b/start.php @@ -44,7 +44,7 @@ if (APP_HOOK && isset($mode['tags'])) { // 自动生成 if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) { - Create::build(include APP_PATH . 'build.php'); + Build::run(include APP_PATH . 'build.php'); } Loader::addNamespace('tests', TEST_PATH); // 执行应用 From 0e097113271251e1ea092a1c905aad28d6e96e0d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 16:37:40 +0800 Subject: [PATCH 18/25] =?UTF-8?q?response=E7=B1=BB=E6=B7=BB=E5=8A=A0transf?= =?UTF-8?q?orm=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BD=AC=E6=8D=A2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response.php | 43 +++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/library/think/response.php b/library/think/response.php index 2f8034fd..7496d7ef 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -13,6 +13,8 @@ namespace think; class Response { + // 输出数据的转换方法 + protected static $tramsform = null; /** * 返回数据到客户端 @@ -37,20 +39,23 @@ class Response header('Content-Type:' . $headers[$type] . '; charset=utf-8'); } - switch ($type) { - case 'json': - // 返回JSON数据格式到客户端 包含状态信息 - $data = json_encode($data, JSON_UNESCAPED_UNICODE); - break; - case 'xml': - // 返回xml格式数据 - $data = \org\Transform::xmlEncode($data); - break; - case 'jsonp': - // 返回JSON数据格式到客户端 包含状态信息 - $handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler'); - $data = $handler . '(' . \org\Transform::jsonEncode($data) . ');'; - break; + if (is_callable(self::$tramsform)) { + $data = call_user_func_array(self::$tramsform, [$data]); + } else { + switch ($type) { + case 'json': + // 返回JSON数据格式到客户端 包含状态信息 + $data = json_encode($data, JSON_UNESCAPED_UNICODE); + break; + case 'jsonp': + // 返回JSON数据格式到客户端 包含状态信息 + $handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler'); + $data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');'; + break; + default: + // 用于扩展其他返回格式数据 + Hook::listen('return_data', $data); + } } switch ($return) { @@ -62,7 +67,17 @@ class Response default: echo $data; } + } + /** + * 转换控制器输出的数据 + * @access public + * @param mixed $callback 调用的转换方法 + * @return void + */ + public static function tramsform($callback) + { + self::$tramsform = $callback; } /** From 435ad7bc759f08cdc82d04fdcde1bc80b0f94442 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 16:41:34 +0800 Subject: [PATCH 19/25] =?UTF-8?q?rest=E6=8E=A7=E5=88=B6=E5=99=A8=E6=89=A9?= =?UTF-8?q?=E5=B1=95response=E6=96=B9=E6=B3=95=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/controller/rest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/controller/rest.php b/library/think/controller/rest.php index 64bed282..380606e0 100644 --- a/library/think/controller/rest.php +++ b/library/think/controller/rest.php @@ -93,7 +93,7 @@ abstract class Rest protected function response($data, $type = '', $code = 200) { Response::sendHttpStatus($code); - Response::returnData($data, strtolower($type)); + return Response::returnData($data, $type, 1); } /** @@ -131,7 +131,7 @@ abstract class Rest } } } - + return false; } } From 6b48bb5b9f65be649f24bc10721d0b3bd7f7a583 Mon Sep 17 00:00:00 2001 From: pwf0112 Date: Tue, 22 Dec 2015 16:59:05 +0800 Subject: [PATCH 20/25] =?UTF-8?q?route.php=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=87=AA=E5=8A=A8=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index 4583dae0..82689ffb 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -28,15 +28,15 @@ class App // 初始化公共模块 self::initModule(COMMON_MODULE, Config::get()); - // 获取配置参数 - $config = Config::get(); - // 读取扩展配置文件 - if ($config['extra_config_list']) { - foreach ($config['extra_config_list'] as $file) { + if (Config::get('extra_config_list')) { + foreach (Config::get('extra_config_list') as $file) { Config::load($file, $file); } } + + // 获取配置参数 + $config = Config::get(); // 日志初始化 Log::init($config['log']); From 2c6b984438508cb3f61dc23dda4d48e908ad7018 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 17:42:00 +0800 Subject: [PATCH 21/25] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.php | 66 ++++++++++++++-------------- library/think/controller/hprose.php | 2 +- library/think/controller/jsonrpc.php | 2 +- library/think/controller/rpc.php | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/base.php b/base.php index edba57ed..32e55f3c 100644 --- a/base.php +++ b/base.php @@ -59,16 +59,16 @@ define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); // 获取多语言变量 function L($name, $vars = [], $lang = '') { - return think\Lang::get($name, $vars, $lang); + return \think\Lang::get($name, $vars, $lang); } // 获取配置参数 function C($name = '', $value = null, $range = '') { if (is_null($value) && is_string($name)) { - return think\Config::get($name, $range); + return \think\Config::get($name, $range); } else { - return think\Config::set($name, $value, $range); + return \think\Config::set($name, $value, $range); } } @@ -82,7 +82,7 @@ function I($key, $default = null, $filter = '') // 默认为自动判断 $method = 'param'; } - return think\Input::$method($key, $default, $filter); + return \think\Input::$method($key, $default, $filter); } /** @@ -95,9 +95,9 @@ function I($key, $default = null, $filter = '') function G($start, $end = '', $dec = 6) { if ('' == $end) { - think\Debug::remark($start); + \think\Debug::remark($start); } else { - return 'm' == $dec ? think\Debug::getRangeMem($start, $end) : think\Debug::getRangeTime($start, $end, $dec); + return 'm' == $dec ? \think\Debug::getRangeMem($start, $end) : \think\Debug::getRangeTime($start, $end, $dec); } } @@ -110,7 +110,7 @@ function G($start, $end = '', $dec = 6) */ function M($name = '', $tablePrefix = '', $connection = '') { - return think\Loader::table($name, ['prefix' => $tablePrefix, 'connection' => $connection]); + return \think\Loader::table($name, ['prefix' => $tablePrefix, 'connection' => $connection]); } /** @@ -121,7 +121,7 @@ function M($name = '', $tablePrefix = '', $connection = '') */ function D($name = '', $layer = MODEL_LAYER) { - return think\Loader::model($name, $layer); + return \think\Loader::model($name, $layer); } /** @@ -132,7 +132,7 @@ function D($name = '', $layer = MODEL_LAYER) */ function db($config = [], $lite = false) { - return think\Db::instance($config, $lite); + return \think\Db::instance($config, $lite); } /** @@ -143,7 +143,7 @@ function db($config = [], $lite = false) */ function A($name, $layer = CONTROLLER_LAYER) { - return think\Loader::controller($name, $layer); + return \think\Loader::controller($name, $layer); } /** @@ -155,7 +155,7 @@ function A($name, $layer = CONTROLLER_LAYER) */ function R($url, $vars = [], $layer = CONTROLLER_LAYER) { - return think\Loader::action($url, $vars, $layer); + return \think\Loader::action($url, $vars, $layer); } /** @@ -167,7 +167,7 @@ function R($url, $vars = [], $layer = CONTROLLER_LAYER) */ function import($class, $baseUrl = '', $ext = EXT) { - return think\Loader::import($class, $baseUrl, $ext); + return \think\Loader::import($class, $baseUrl, $ext); } /** @@ -178,7 +178,7 @@ function import($class, $baseUrl = '', $ext = EXT) */ function vendor($class, $ext = EXT) { - return think\Loader::import($class, VENDOR_PATH, $ext); + return \think\Loader::import($class, VENDOR_PATH, $ext); } /** @@ -189,7 +189,7 @@ function vendor($class, $ext = EXT) */ function T($class, $ext = EXT) { - return think\Loader::import($class, TRAIT_PATH, $ext); + return \think\Loader::import($class, TRAIT_PATH, $ext); } /** @@ -202,7 +202,7 @@ function T($class, $ext = EXT) */ function E($msg, $code = 0) { - throw new think\Exception($msg, $code); + throw new \think\Exception($msg, $code); } /** @@ -214,7 +214,7 @@ function E($msg, $code = 0) */ function dump($var, $echo = true, $label = null) { - return think\Debug::dump($var, $echo, $label); + return \think\Debug::dump($var, $echo, $label); } /** @@ -225,31 +225,31 @@ function dump($var, $echo = true, $label = null) */ function W($name, $data = []) { - return think\Loader::action($name, $data, 'Widget'); + return \think\Loader::action($name, $data, 'Widget'); } function U($url, $vars = '', $suffix = true, $domain = false) { - return think\Url::build($url, $vars, $suffix, $domain); + return \think\Url::build($url, $vars, $suffix, $domain); } function session($name, $value = '') { if (is_array($name)) { // 初始化 - think\Session::init($name); + \think\Session::init($name); } elseif (is_null($name)) { // 清除 - think\Session::clear($value); + \think\Session::clear($value); } elseif ('' === $value) { // 获取 - return think\Session::get($name); + return \think\Session::get($name); } elseif (is_null($value)) { // 删除session - return think\Session::delete($name); + return \think\Session::delete($name); } else { // 设置session - return think\Session::set($name, $value); + return \think\Session::set($name, $value); } } @@ -257,19 +257,19 @@ function cookie($name, $value = '') { if (is_array($name)) { // 初始化 - think\Cookie::init($name); + \think\Cookie::init($name); } elseif (is_null($name)) { // 清除 - think\Cookie::clear($value); + \think\Cookie::clear($value); } elseif ('' === $value) { // 获取 - return think\Cookie::get($name); + return \think\Cookie::get($name); } elseif (is_null($value)) { // 删除session - return think\Cookie::delete($name); + return \think\Cookie::delete($name); } else { // 设置session - return think\Cookie::set($name, $value); + return \think\Cookie::set($name, $value); } } @@ -284,17 +284,17 @@ function S($name, $value = '', $options = null) { if (is_array($options)) { // 缓存操作的同时初始化 - think\Cache::connect($options); + \think\Cache::connect($options); } elseif (is_array($name)) { // 缓存初始化 - return think\Cache::connect($name); + return \think\Cache::connect($name); } if ('' === $value) { // 获取缓存 - return think\Cache::get($name); + return \think\Cache::get($name); } elseif (is_null($value)) { // 删除缓存 - return think\Cache::rm($name); + return \think\Cache::rm($name); } else { // 缓存数据 if (is_array($options)) { @@ -302,7 +302,7 @@ function S($name, $value = '', $options = null) } else { $expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间 } - return think\Cache::set($name, $value, $expire); + return \think\Cache::set($name, $value, $expire); } } diff --git a/library/think/controller/hprose.php b/library/think/controller/hprose.php index d86dd03c..cf0711e7 100644 --- a/library/think/controller/hprose.php +++ b/library/think/controller/hprose.php @@ -34,7 +34,7 @@ abstract class Hprose } //导入类库 - think\Loader::import('vendor.Hprose.HproseHttpServer'); + \think\Loader::import('vendor.Hprose.HproseHttpServer'); //实例化HproseHttpServer $server = new \HproseHttpServer(); if ($this->allowMethodList) { diff --git a/library/think/controller/jsonrpc.php b/library/think/controller/jsonrpc.php index d8713708..e93d80a1 100644 --- a/library/think/controller/jsonrpc.php +++ b/library/think/controller/jsonrpc.php @@ -28,7 +28,7 @@ abstract class Jsonrpc } //导入类库 - think\Loader::import('vendor.jsonrpc.jsonRPCServer'); + \think\Loader::import('vendor.jsonrpc.jsonRPCServer'); // 启动server \jsonRPCServer::handle($this); } diff --git a/library/think/controller/rpc.php b/library/think/controller/rpc.php index 0c87f08a..7e2fe0bd 100644 --- a/library/think/controller/rpc.php +++ b/library/think/controller/rpc.php @@ -31,7 +31,7 @@ abstract class Rpc } //导入类库 - think\Loader::import('vendor.phprpc.phprpc_server'); + \think\Loader::import('vendor.phprpc.phprpc_server'); //实例化phprpc $server = new \PHPRPC_Server(); if ($this->allowMethodList) { From 38f7e25c82c0a6aaea695efaec766f4239ecdfb7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 17:42:53 +0800 Subject: [PATCH 22/25] =?UTF-8?q?returnData=E5=A6=82=E6=9E=9Ctype=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=BA=E7=A9=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/think/response.php b/library/think/response.php index 7496d7ef..d1e3026e 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -52,6 +52,8 @@ class Response $handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler'); $data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');'; break; + case '': + break default: // 用于扩展其他返回格式数据 Hook::listen('return_data', $data); From e5ecdde9dcfb82a40bfa2130c6d89764f7845a46 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Tue, 22 Dec 2015 18:39:10 +0800 Subject: [PATCH 23/25] =?UTF-8?q?=E5=90=8C=E6=AD=A5Response::success()?= =?UTF-8?q?=E5=92=8CResponse::error()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/response.php b/library/think/response.php index 7496d7ef..cc49738b 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -97,7 +97,7 @@ class Response 'time' => NOW_TIME, 'data' => $data, ]; - self::returnData($result, $type, true); + return self::returnData($result, $type, true); } /** @@ -123,7 +123,7 @@ class Response $view = new \think\View(); $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); } - self::returnData($result, $type, true); + return self::returnData($result, $type, true); } /** @@ -149,7 +149,7 @@ class Response $view = new \think\View(); $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); } - self::returnData($result, $type, true); + return self::returnData($result, $type, true); } /** From 633a086950e82f82da73a62ce60b4ff93e3a5e02 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Dec 2015 23:40:45 +0800 Subject: [PATCH 24/25] =?UTF-8?q?response=E7=B1=BB=E8=B0=83=E6=95=B4=20dat?= =?UTF-8?q?a=20type=20=E5=8F=AF=E4=BB=A5=E5=8D=95=E7=8B=AC=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 4 +- library/think/app.php | 6 +-- library/think/controller/rest.php | 5 +- library/think/response.php | 84 +++++++++++++++++++++++++------ 4 files changed, 77 insertions(+), 22 deletions(-) diff --git a/convention.php b/convention.php index dcf4a58e..977b2ce7 100644 --- a/convention.php +++ b/convention.php @@ -13,8 +13,8 @@ return [ 'default_return_type' => 'html', // 默认语言 'default_lang' => 'zh-cn', - // response输出方式 0 echo 1 return 2 exit - 'response_type' => 0, + // response是否返回方式 + 'response_return' => false, // 默认AJAX 数据返回格式,可选JSON XML ... 'default_ajax_return' => 'JSON', // 默认JSONP格式返回的处理方法 diff --git a/library/think/app.php b/library/think/app.php index 82689ffb..e403b31e 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -34,7 +34,7 @@ class App Config::load($file, $file); } } - + // 获取配置参数 $config = Config::get(); @@ -111,7 +111,7 @@ class App // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); // 输出数据 - return Response::returnData($data, Config::get('default_return_type'), Config::get('response_type')); + return Response::send($data, '', Config::get('response_return')); } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); @@ -124,7 +124,7 @@ class App // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); // 输出数据 - return Response::returnData($data, Config::get('default_return_type'), Config::get('response_type')); + return Response::send($data, '', Config::get('response_return')); } else { throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ', 10002); } diff --git a/library/think/controller/rest.php b/library/think/controller/rest.php index 380606e0..aa09b34b 100644 --- a/library/think/controller/rest.php +++ b/library/think/controller/rest.php @@ -93,7 +93,10 @@ abstract class Rest protected function response($data, $type = '', $code = 200) { Response::sendHttpStatus($code); - return Response::returnData($data, $type, 1); + Response::data($data); + if ($type) { + Response::type($type); + } } /** diff --git a/library/think/response.php b/library/think/response.php index e54407fb..1eed337f 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -15,17 +15,25 @@ class Response { // 输出数据的转换方法 protected static $tramsform = null; + // 输出数据的类型 + protected static $type = 'json'; + // 输出数据 + protected static $data = ''; + // 是否exit + protected static $isExit = false; /** - * 返回数据到客户端 + * 发送数据到客户端 * @access protected * @param mixed $data 要返回的数据 * @param String $type 返回数据格式 - * @param integer $return 是否返回数据 0 echo 1 return 2 exit + * @param bool $return 是否返回数据 * @return void */ - public static function returnData($data, $type = '', $return = 0) + public static function send($data = '', $type = '', $return = false) { + $type = strtolower($type ?: self::$type); + $headers = [ 'json' => 'application/json', 'xml' => 'text/xml', @@ -34,11 +42,12 @@ class Response 'script' => 'application/javascript', 'text' => 'text/plain', ]; - $type = strtolower($type); + if (!headers_sent() && isset($headers[$type])) { header('Content-Type:' . $headers[$type] . '; charset=utf-8'); } + $data = $data ?: self::$data; if (is_callable(self::$tramsform)) { $data = call_user_func_array(self::$tramsform, [$data]); } else { @@ -53,21 +62,21 @@ class Response $data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');'; break; case '': - break + // 类型为空不做处理 + break; default: // 用于扩展其他返回格式数据 Hook::listen('return_data', $data); } } - switch ($return) { - case 1: - return $data; - case 2: - exit($data); - case 0: - default: - echo $data; + if ($return) { + return $data; + } else { + echo $data; + } + if (self::$isExit) { + exit; } } @@ -82,6 +91,39 @@ class Response self::$tramsform = $callback; } + /** + * 输出类型设置 + * @access public + * @param string $type 输出内容的格式类型 + * @return void + */ + public static function type($type) + { + self::$type = $type; + } + + /** + * 输出数据设置 + * @access public + * @param mixed $data 输出数据 + * @return void + */ + public static function data($data) + { + self::$data = $data; + } + + /** + * 输出是否exit设置 + * @access public + * @param bool $exit 是否退出 + * @return void + */ + public static function isExit($exit = false) + { + self::$isExit = $exit; + } + /** * 返回封装后的API数据到客户端 * @access public @@ -99,7 +141,11 @@ class Response 'time' => NOW_TIME, 'data' => $data, ]; - return self::returnData($result, $type, true); + + self::$data = $result; + if ($type) { + self::$type = $type; + } } /** @@ -125,7 +171,10 @@ class Response $view = new \think\View(); $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); } - return self::returnData($result, $type, true); + self::$data = $result; + if ($type) { + self::$type = $type; + } } /** @@ -151,7 +200,10 @@ class Response $view = new \think\View(); $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); } - return self::returnData($result, $type, true); + self::$data = $result; + if ($type) { + self::$type = $type; + } } /** From 61a52319e290703332fc30696e6ac9b42ac24897 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 23 Dec 2015 00:01:35 +0800 Subject: [PATCH 25/25] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/response.php b/library/think/response.php index 1eed337f..8c252fcb 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -16,7 +16,7 @@ class Response // 输出数据的转换方法 protected static $tramsform = null; // 输出数据的类型 - protected static $type = 'json'; + protected static $type = 'html'; // 输出数据 protected static $data = ''; // 是否exit