内核更新,多余文件清理

This commit is contained in:
2016-07-01 18:04:46 +08:00
parent a595f3a13e
commit 0398e5bd80
31 changed files with 426 additions and 551 deletions

View File

@@ -12,7 +12,6 @@
namespace think;
use think\Config;
use think\debug\Trace;
use think\Exception;
use think\exception\HttpException;
use think\exception\HttpResponseException;
@@ -145,19 +144,18 @@ class App
$response = $data;
} elseif (!is_null($data)) {
// 默认自动识别响应输出类型
$isAjax = $request->isAjax();
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
$isAjax = $request->isAjax();
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
$response = Response::create($data, $type);
} else {
$response = Response::create();
}
// 监听app_end
Hook::listen('app_end', $response);
//注入Trace
self::$debug && Trace::inject($response);
// Trace调试注入
Debug::inject($response);
return $response;
}

View File

@@ -11,6 +11,13 @@
namespace think;
use think\Config;
use think\exception\ClassNotFoundException;
use think\Log;
use think\Request;
use think\Response;
use think\response\Redirect;
class Debug
{
// 区间时间信息
@@ -56,7 +63,7 @@ class Debug
*/
public static function getUseTime($dec = 6)
{
return number_format((microtime(true) - START_TIME), $dec);
return number_format((microtime(true) - THINK_START_TIME), $dec);
}
/**
@@ -97,7 +104,7 @@ class Debug
*/
public static function getUseMem($dec = 2)
{
$size = memory_get_usage() - START_MEM;
$size = memory_get_usage() - THINK_START_MEM;
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
$pos = 0;
while ($size >= 1024) {
@@ -177,4 +184,43 @@ class Debug
}
}
public static function inject(Response $response)
{
$config = Config::get('trace');
$type = isset($config['type']) ? $config['type'] : 'Html';
if (false !== $type) {
$request = Request::instance();
$accept = $request->header('accept');
$contentType = $response->getHeader('Content-Type');
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
unset($config['type']);
if (class_exists($class)) {
$trace = new $class($config);
} else {
throw new ClassNotFoundException('class not exists:' . $class, $class);
}
if ($response instanceof Redirect) {
//TODO 记录
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
//TODO 记录
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
//TODO 记录
} else {
$output = $trace->output(Log::getLog());
if (is_string($output)) {
// trace调试信息注入
$content = $response->getContent();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
} else {
$content = $content . $output;
}
$response->content($content);
}
}
}
}
}

View File

@@ -1820,7 +1820,7 @@ class Query
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
// 判断查询缓存
$cache = $options['cache'];
if (true === $cache['key'] && !is_array($data)) {
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
$key = 'think:' . $options['table'] . '|' . $data;
} else {
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));

View File

@@ -18,6 +18,7 @@ use think\db\Builder;
*/
class Mysql extends Builder
{
protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
/**
* 字段和表名处理

View File

@@ -47,7 +47,7 @@ class Oracle extends Connection
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param boolean $getLastInsID 是否获取自增ID
* @param string $sequence 序列名
* @param string $sequence 序列名
* @return integer
* @throws \Exception
* @throws \think\Exception
@@ -60,16 +60,16 @@ class Oracle extends Connection
}
// 根据参数绑定组装最终的SQL语句
$this->queryStr = $this->getBindSql($sql, $bind);
$this->queryStr = $this->getRealSql($sql, $bind);
$flag = false;
if (preg_match("/^\s*(INSERT\s+INTO)\s+(\w+)\s+/i", $sql, $match)) {
if(is_null($sequence)){
if (is_null($sequence)) {
$sequence = Config::get("db_sequence_prefix") . str_ireplace(Config::get("database.prefix"), "", $match[2]);
}
$flag = (boolean) $this->query("SELECT * FROM all_sequences WHERE sequence_name='" . strtoupper($sequence) . "'");
$flag = (boolean) $this->query("SELECT * FROM all_sequences WHERE sequence_name='" . strtoupper($sequence) . "'");
}
//释放前次的查询结果
if (!empty($this->PDOStatement)) {
$this->free();
@@ -89,7 +89,7 @@ class Oracle extends Connection
$this->lastInsID = $this->linkID->lastInsertId();
if ($getLastInsID) {
return $this->lastInsID;
}
}
}
return $this->numRows;
} catch (\PDOException $e) {
@@ -130,7 +130,7 @@ class Oracle extends Connection
/**
* 取得数据库的表信息(暂时实现取得用户表信息)
* @access public
* @param string $dbName
* @param string $dbName
* @return array
*/
public function getTables($dbName = '')
@@ -155,7 +155,8 @@ class Oracle extends Connection
return [];
}
protected function supportSavepoint(){
protected function supportSavepoint()
{
return true;
}
}

View File

@@ -9,7 +9,7 @@
// | Author: yangweijie <yangweijiester@gmail.com>
// +----------------------------------------------------------------------
namespace think\debug\trace;
namespace think\debug;
use think\Cache;
use think\Config;
@@ -34,7 +34,7 @@ class Console
}
/**
* 日志写入接口
* 调试输出接口
* @access public
* @param array $log 日志信息
* @return bool
@@ -42,9 +42,9 @@ class Console
public function output(array $log = [])
{
// 获取基本信息
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
if (isset($_SERVER['HTTP_HOST'])) {
$uri = $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
@@ -126,12 +126,12 @@ JS;
}
break;
case '错误':
$msg = str_replace(PHP_EOL, '\n', $m);
$msg = str_replace("\n", '\n', $m);
$style = 'color:#F4006B;font-size:14px;';
$line[] = "console.error(\"%c{$msg}\", \"{$style}\");";
break;
case 'sql':
$msg = str_replace(PHP_EOL, '\n', $m);
$msg = str_replace("\n", '\n', $m);
$style = "color:#009bb4;";
$line[] = "console.log(\"%c{$msg}\", \"{$style}\");";
break;

View File

@@ -9,7 +9,7 @@
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\debug\trace;
namespace think\debug;
use think\Cache;
use think\Config;
@@ -34,7 +34,7 @@ class Html
}
/**
* 日志写入接口
* 调试输出接口
* @access public
* @param array $log 日志信息
* @return bool
@@ -43,9 +43,9 @@ class Html
{
// 获取基本信息
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
// 页面Trace信息
if (isset($_SERVER['HTTP_HOST'])) {

View File

@@ -9,7 +9,7 @@
// | Author: luofei614 <weibo.com/luofei614>
// +----------------------------------------------------------------------
namespace think\log\driver;
namespace think\debug;
/**
* github: https://github.com/luofei614/SocketLog
@@ -55,20 +55,20 @@ class Socket
}
/**
* 日志写入接口
* 调试输出接口
* @access public
* @param array $logs 日志信息
* @return bool
*/
public function save(array $logs = [])
public function output(array $logs = [])
{
if (!$this->check()) {
return false;
}
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / number_format($runtime, 8), 2);
$time_str = " [运行时间:{$runtime}s][吞吐率:{$reqs}req/s]";
$memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";

View File

@@ -1,63 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\debug;
use think\Config;
use think\exception\ClassNotFoundException;
use think\Log;
use think\Request;
use think\Response;
use think\response\Redirect;
class Trace
{
public static function inject(Response $response)
{
$config = Config::get('trace');
$type = isset($config['type']) ? $config['type'] : 'Html';
if ($type !== false) {
$request = Request::instance();
$accept = $request->header('accept');
$contentType = $response->getHeader('Content-Type');
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\trace\\' . ucwords($type);
unset($config['type']);
if(class_exists($class)) {
$trace = new $class($config);
} else {
throw new ClassNotFoundException('class not exists:' . $class, $class);
}
if ($response instanceof Redirect) {
//TODO 记录
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
//TODO 记录
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
//TODO 记录
} else {
$output = $trace->output(Log::getLog());
$content = $response->getContent();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
} else {
$content = $content . $output;
}
$response->content($content);
}
}
}
}

View File

@@ -54,10 +54,10 @@ class File
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]";
$memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";

View File

@@ -33,10 +33,10 @@ class Sae
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME;
$reqs = number_format(1 / $runtime, 2);
$time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]";
$memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";
$file_load = " [文件加载:" . count(get_included_files()) . "]";