去除 IS_CGI IS_MAC NOW_TIME 常量

This commit is contained in:
thinkphp
2016-06-02 12:21:36 +08:00
parent 8099a001e2
commit d65882e20c
7 changed files with 11 additions and 15 deletions

View File

@@ -40,8 +40,5 @@ defined('CLASS_APPEND_SUFFIX') or define('CLASS_APPEND_SUFFIX', false); // 是
defined('APP_MODE') or define('APP_MODE', 'common'); // 应用模式 默认为普通模式
// 环境常量
define('IS_CGI', strpos(PHP_SAPI, 'cgi') === 0 ? 1 : 0);
define('IS_CLI', PHP_SAPI == 'cli' ? 1 : 0);
define('IS_WIN', strstr(PHP_OS, 'WIN') ? 1 : 0);
define('IS_MAC', strstr(PHP_OS, 'Darwin') ? 1 : 0);
define('NOW_TIME', $_SERVER['REQUEST_TIME']);
define('IS_CLI', PHP_SAPI == 'cli' ? true : false);
define('IS_WIN', strstr(PHP_OS, 'WIN') ? true : false);

View File

@@ -1017,16 +1017,16 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
switch ($type) {
case 'timestamp':
$format = !empty($param) ? $param : $this->dateFormat;
$value = date($format, NOW_TIME);
$value = date($format, $_SERVER['REQUEST_TIME']);
break;
case 'datetime':
$value = NOW_TIME;
$value = $_SERVER['REQUEST_TIME'];
break;
}
} elseif (isset($this->fieldType[$name]) && preg_match('/(datetime|timestamp)/is', $this->fieldType[$name])) {
$value = date($this->dateFormat, NOW_TIME);
$value = date($this->dateFormat, $_SERVER['REQUEST_TIME']);
} else {
$value = NOW_TIME;
$value = $_SERVER['REQUEST_TIME'];
}
} else {
// 检测修改器

View File

@@ -207,7 +207,7 @@ class Response
$result = [
'code' => $code,
'msg' => $msg,
'time' => NOW_TIME,
'time' => $_SERVER['REQUEST_TIME'],
'data' => $data,
];
return $this->data($result);

View File

@@ -976,7 +976,7 @@ class Validate
if (!is_numeric($end)) {
$end = strtotime($end);
}
return NOW_TIME >= $start && NOW_TIME <= $end;
return $_SERVER['REQUEST_TIME'] >= $start && $_SERVER['REQUEST_TIME'] <= $end;
}
/**

View File

@@ -586,7 +586,7 @@ class Query
{
if (false !== ($value = Cache::get($guid))) {
// 存在缓存写入数据
if (NOW_TIME > Cache::get($guid . '_time') + $lazyTime) {
if ($_SERVER['REQUEST_TIME'] > Cache::get($guid . '_time') + $lazyTime) {
// 延时更新时间到了,删除缓存数据 并实际写入数据库
Cache::rm($guid);
Cache::rm($guid . '_time');
@@ -600,7 +600,7 @@ class Query
// 没有缓存数据
Cache::set($guid, $step, 0);
// 计时开始
Cache::set($guid . '_time', NOW_TIME, 0);
Cache::set($guid . '_time', $_SERVER['REQUEST_TIME'], 0);
return false;
}
}

View File

@@ -38,7 +38,6 @@ class baseTest extends \PHPUnit_Framework_TestCase
$this->assertNotEmpty(ENV_PREFIX);
$this->assertTrue(is_bool(IS_API));
$this->assertNotEmpty(APP_MODE);
$this->assertTrue(!is_null(IS_CGI));
$this->assertTrue(!is_null(IS_WIN));
$this->assertTrue(!is_null(IS_CLI));
}

View File

@@ -170,7 +170,7 @@ class debugTest extends \PHPUnit_Framework_TestCase
$array = explode("array", json_encode($output));
if (IS_WIN) {
$this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array));
} else if (IS_MAC) {
} else if (strstr(PHP_OS, 'Darwin')) {
$this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
} else {
$this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));