目录结构调整

This commit is contained in:
2016-06-30 16:53:58 +08:00
parent 7eaa319115
commit 52f669abec
107 changed files with 4600 additions and 476 deletions

View File

@@ -1,41 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\log\alarm;
/**
* 邮件通知驱动
*/
class Email
{
protected $config = [
'address' => '',
];
// 实例化并传入参数
public function __construct($config = [])
{
$this->config = array_merge($this->config, $config);
}
/**
* 通知发送接口
* @access public
* @param string $msg 日志信息
* @return bool
*/
public function send($msg = '')
{
return error_log($msg, 1, $this->config['address']);
}
}

View File

@@ -1,150 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com>
// +----------------------------------------------------------------------
namespace think\log\driver;
use think\Cache;
use think\Config;
use think\Db;
use think\Debug;
use think\Request;
/**
* 浏览器调试输出
*/
class Browser
{
protected $config = [
'trace_tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'],
];
// 实例化并传入参数
public function __construct($config = [])
{
if (is_array($config)) {
$this->config = array_merge($this->config, $config);
}
}
/**
* 日志写入接口
* @access public
* @param array $log 日志信息
* @return bool
*/
public function save(array $log = [])
{
if (IS_CLI || IS_API || Request::instance()->isAjax() || (defined('RESPONSE_TYPE') && !in_array(RESPONSE_TYPE, ['html', 'view']))) {
// ajax cli api方式下不输出
return false;
}
// 获取基本信息
$runtime = microtime(true) - START_TIME;
$reqs = number_format(1 / number_format($runtime, 8), 2);
$runtime = number_format($runtime, 6);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
// 页面Trace信息
$base = [
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
'配置加载' => count(Config::get()),
];
if (session_id()) {
$base['会话信息'] = 'SESSION_ID=' . session_id();
}
$info = Debug::getFile(true);
// 页面Trace信息
$trace = [];
foreach ($this->config['trace_tabs'] as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base': // 基本信息
$trace[$title] = $base;
break;
case 'file': // 文件信息
$trace[$title] = $info;
break;
default: // 调试信息
if (strpos($name, '|')) {
// 多组信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($log[$name]) ? $log[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($log[$name]) ? $log[$name] : '';
}
}
}
//输出到控制台
$lines = '';
foreach ($trace as $type => $msg) {
$lines .= $this->output($type, $msg);
}
$js = <<<JS
<script>
{$lines}
</script>
JS;
echo $js;
return true;
}
public function output($type, $msg)
{
$type = strtolower($type);
$trace_tabs = array_values($this->config['trace_tabs']);
$line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误'== $type)
? "console.group('{$type}');"
: "console.groupCollapsed('{$type}');";
foreach ((array)$msg as $key => $m) {
switch ($type) {
case '调试':
$var_type = gettype($m);
if(in_array($var_type, ['array', 'string'])){
$line[] = "console.log(".json_encode($m).");";
}else{
$line[] = "console.log(".json_encode(var_export($m, 1)).");";
}
break;
case '错误':
$msg = str_replace(PHP_EOL, '\n', $m);
$style = 'color:#F4006B;font-size:14px;';
$line[] = "console.error(\"%c{$msg}\", \"{$style}\");";
break;
case 'sql':
$msg = str_replace(PHP_EOL, '\n', $m);
$style = "color:#009bb4;";
$line[] = "console.log(\"%c{$msg}\", \"{$style}\");";
break;
default:
$m = is_string($key)? $key . ' ' . $m : $key+1 . ' ' . $m;
$msg = json_encode($m);
$line[] = "console.log({$msg});";
break;
}
}
$line[]= "console.groupEnd();";
return implode(PHP_EOL, $line);
}
}

View File

@@ -54,9 +54,8 @@ class File
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = microtime(true) - START_TIME;
$reqs = number_format(1 / number_format($runtime, 8), 2);
$runtime = number_format($runtime, 6);
$runtime = number_format(microtime(true), 8, '.', '') - 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_str = " [内存消耗:{$memory_use}kb]";
@@ -67,7 +66,7 @@ class File
foreach ($val as $msg) {
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
}
$info .= '[ ' . $type . ' ] ' . $msg . "\r\n";
}
}

View File

@@ -33,9 +33,8 @@ class Sae
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = microtime(true) - START_TIME;
$reqs = number_format(1 / number_format($runtime, 8), 2);
$runtime = number_format($runtime, 6);
$runtime = number_format(microtime(true), 8, '.', '') - 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_str = " [内存消耗:{$memory_use}kb]";
@@ -46,7 +45,7 @@ class Sae
foreach ($val as $msg) {
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
}
$info .= '[ ' . $type . ' ] ' . $msg . "\r\n";
}
}

View File

@@ -65,9 +65,8 @@ class Socket
if (!$this->check()) {
return false;
}
$runtime = microtime(true) - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$reqs = number_format(1 / number_format($runtime, 8), 2);
$runtime = number_format($runtime, 6);
$time_str = " [运行时间:{$runtime}s][吞吐率:{$reqs}req/s]";
$memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2);
$memory_str = " [内存消耗:{$memory_use}kb]";

View File

@@ -1,103 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\log\driver;
use think\Cache;
use think\Config;
use think\Db;
use think\Debug;
use think\Request;
/**
* 页面Trace调试
*/
class Trace
{
protected $config = [
'trace_file' => '',
'trace_tabs' => ['base' => '基本', 'file' => '文件', 'info' => '流程', 'notice|error' => '错误', 'sql' => 'SQL', 'debug|log' => '调试'],
];
// 实例化并传入参数
public function __construct(array $config = [])
{
$this->config['trace_file'] = THINK_PATH . 'tpl/page_trace.tpl';
$this->config = array_merge($this->config, $config);
}
/**
* 日志写入接口
* @access public
* @param array $log 日志信息
* @return bool
*/
public function save(array $log = [])
{
if (IS_CLI || IS_API || Request::instance()->isAjax() || (defined('RESPONSE_TYPE') && !in_array(RESPONSE_TYPE, ['html', 'view']))) {
// ajax cli api方式下不输出
return false;
}
// 获取基本信息
$runtime = microtime(true) - START_TIME;
$reqs = number_format(1 / number_format($runtime, 8), 2);
$runtime = number_format($runtime, 6);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
// 页面Trace信息
$base = [
'请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'运行时间' => "{$runtime}s [ 吞吐率:{$reqs}req/s ] 内存消耗:{$mem}kb 文件加载:" . count(get_included_files()),
'查询信息' => Db::$queryTimes . ' queries ' . Db::$executeTimes . ' writes ',
'缓存信息' => Cache::$readTimes . ' reads,' . Cache::$writeTimes . ' writes',
'配置加载' => count(Config::get()),
];
if (session_id()) {
$base['会话信息'] = 'SESSION_ID=' . session_id();
}
$info = Debug::getFile(true);
// 页面Trace信息
$trace = [];
foreach ($this->config['trace_tabs'] as $name => $title) {
$name = strtolower($name);
switch ($name) {
case 'base': // 基本信息
$trace[$title] = $base;
break;
case 'file': // 文件信息
$trace[$title] = $info;
break;
default: // 调试信息
if (strpos($name, '|')) {
// 多组信息
$names = explode('|', $name);
$result = [];
foreach ($names as $name) {
$result = array_merge($result, isset($log[$name]) ? $log[$name] : []);
}
$trace[$title] = $result;
} else {
$trace[$title] = isset($log[$name]) ? $log[$name] : '';
}
}
}
// 调用Trace页面模板
ob_start();
include $this->config['trace_file'];
echo ob_get_clean();
return true;
}
}