diff --git a/base.php b/base.php index 333f81b5..64ed27a3 100644 --- a/base.php +++ b/base.php @@ -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); diff --git a/library/think/Model.php b/library/think/Model.php index 47ff150c..e1f9a7a0 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -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 { // 检测修改器 diff --git a/library/think/Response.php b/library/think/Response.php index 5e817368..91ab6d8b 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -207,7 +207,7 @@ class Response $result = [ 'code' => $code, 'msg' => $msg, - 'time' => NOW_TIME, + 'time' => $_SERVER['REQUEST_TIME'], 'data' => $data, ]; return $this->data($result); diff --git a/library/think/Validate.php b/library/think/Validate.php index 2b732dd9..a83a3134 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -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; } /** diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 99b4ebe9..f2625335 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -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; } } diff --git a/tests/thinkphp/baseTest.php b/tests/thinkphp/baseTest.php index 43ea2a62..b61ad444 100644 --- a/tests/thinkphp/baseTest.php +++ b/tests/thinkphp/baseTest.php @@ -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)); } diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index 8a9ac863..12ff815f 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -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));