取消microtime_float函数 取消MODE_PATH IS_API常量

This commit is contained in:
thinkphp
2016-06-29 20:39:38 +08:00
parent 207a77420e
commit 1a91aaa882
7 changed files with 26 additions and 38 deletions

View File

@@ -8,20 +8,14 @@
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
function microtime_float()
{
list ($usec, $sec) = explode(" ", microtime());
return (( float )$usec + ( float )$sec);
}
define('THINK_VERSION', '5.0.0 RC3');
define('START_TIME', microtime_float());
define('START_TIME', number_format(microtime(true), 8, '.', ''));
define('START_MEM', memory_get_usage());
define('EXT', '.php');
define('DS', DIRECTORY_SEPARATOR);
defined('THINK_PATH') or define('THINK_PATH', __DIR__ . DS);
define('LIB_PATH', THINK_PATH . 'library' . DS);
define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录
define('CORE_PATH', LIB_PATH . 'think' . DS);
define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
@@ -35,8 +29,6 @@ defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录
defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
defined('ENV_PREFIX') or define('ENV_PREFIX', 'PHP_'); // 环境变量的配置前缀
defined('IS_API') or define('IS_API', false); // 是否API接口
defined('AUTO_SCAN_PACKAGE') or define('AUTO_SCAN_PACKAGE', false); // 是否自动扫描非Composer安装类库
// 环境常量
define('IS_CLI', PHP_SAPI == 'cli' ? true : false);

View File

@@ -15,7 +15,6 @@ use think\Cache;
use think\Config;
use think\Db;
use think\Debug;
use think\Request;
/**
* 浏览器调试输出
@@ -43,7 +42,7 @@ class Console
public function output(array $log = [])
{
// 获取基本信息
$runtime = microtime_float() - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);
@@ -106,38 +105,38 @@ JS;
{
$type = strtolower($type);
$trace_tabs = array_values($this->config['trace_tabs']);
$line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误'== $type)
? "console.group('{$type}');"
: "console.groupCollapsed('{$type}');";
$line[] = ($type == $trace_tabs[0] || '调试' == $type || '错误' == $type)
? "console.group('{$type}');"
: "console.groupCollapsed('{$type}');";
foreach ((array)$msg as $key => $m) {
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)).");";
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}\");";
$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}\");";
$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});";
$m = is_string($key) ? $key . ' ' . $m : $key + 1 . ' ' . $m;
$msg = json_encode($m);
$line[] = "console.log({$msg});";
break;
}
}
$line[]= "console.groupEnd();";
$line[] = "console.groupEnd();";
return implode(PHP_EOL, $line);
}

View File

@@ -15,7 +15,6 @@ use think\Cache;
use think\Config;
use think\Db;
use think\Debug;
use think\Request;
/**
* 页面Trace调试
@@ -44,7 +43,7 @@ class Html
{
// 获取基本信息
$runtime = microtime_float() - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - START_TIME;
$reqs = number_format(1 / $runtime, 2);
$mem = number_format((memory_get_usage() - START_MEM) / 1024, 2);

View File

@@ -54,7 +54,7 @@ class File
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = microtime_float() - START_TIME;
$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);
@@ -66,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,7 +33,7 @@ class Sae
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = microtime_float() - START_TIME;
$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);
@@ -45,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,7 +65,7 @@ class Socket
if (!$this->check()) {
return false;
}
$runtime = microtime_float() - START_TIME;
$runtime = number_format(microtime(true), 8, '.', '') - 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);

View File

@@ -23,7 +23,6 @@ class baseTest extends \PHPUnit_Framework_TestCase
$this->assertNotEmpty(THINK_PATH);
$this->assertNotEmpty(LIB_PATH);
$this->assertNotEmpty(EXTEND_PATH);
$this->assertNotEmpty(MODE_PATH);
$this->assertNotEmpty(CORE_PATH);
$this->assertNotEmpty(TRAIT_PATH);
$this->assertNotEmpty(APP_PATH);
@@ -34,7 +33,6 @@ class baseTest extends \PHPUnit_Framework_TestCase
$this->assertNotEmpty(VENDOR_PATH);
$this->assertNotEmpty(EXT);
$this->assertNotEmpty(ENV_PREFIX);
$this->assertTrue(is_bool(IS_API));
$this->assertTrue(!is_null(IS_WIN));
$this->assertTrue(!is_null(IS_CLI));
}