内核更新
This commit is contained in:
@@ -38,18 +38,20 @@ define('IS_WIN', strpos(PHP_OS, 'WIN') !== false);
|
|||||||
require CORE_PATH . 'Loader.php';
|
require CORE_PATH . 'Loader.php';
|
||||||
|
|
||||||
// 加载环境变量配置文件
|
// 加载环境变量配置文件
|
||||||
if (is_file(ROOT_PATH . 'env' . EXT)) {
|
if (is_file(ROOT_PATH . '.env')) {
|
||||||
$env = include ROOT_PATH . 'env' . EXT;
|
$env = parse_ini_file(ROOT_PATH . '.env', true);
|
||||||
foreach ($env as $key => $val) {
|
foreach ($env as $key => $val) {
|
||||||
$name = ENV_PREFIX . strtoupper($key);
|
$name = ENV_PREFIX . strtoupper($key);
|
||||||
if (is_bool($val)) {
|
if (is_array($val)) {
|
||||||
$val = $val ? 1 : 0;
|
foreach ($val as $k => $v) {
|
||||||
} elseif (!is_scalar($val)) {
|
$item = $name . '_' . strtoupper($k);
|
||||||
continue;
|
putenv("$item=$v");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
putenv("$name=$val");
|
putenv("$name=$val");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 注册自动加载
|
// 注册自动加载
|
||||||
\think\Loader::register();
|
\think\Loader::register();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ if (!function_exists('config')) {
|
|||||||
function config($name = '', $value = null, $range = '')
|
function config($name = '', $value = null, $range = '')
|
||||||
{
|
{
|
||||||
if (is_null($value) && is_string($name)) {
|
if (is_null($value) && is_string($name)) {
|
||||||
return Config::get($name, $range);
|
return 0 === strpos($name, '?') ? Config::has(substr($name, 1), $range) : Config::get($name, $range);
|
||||||
} else {
|
} else {
|
||||||
return Config::set($name, $value, $range);
|
return Config::set($name, $value, $range);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
return [
|
return [
|
||||||
// 系统错误提示
|
// 系统错误提示
|
||||||
'Undefined variable' => '未定义变量',
|
'Undefined variable' => '未定义变量',
|
||||||
'Undefined index' => '未定义索引',
|
'Undefined index' => '未定义数组索引',
|
||||||
|
'Undefined offset' => '未定义数组下标',
|
||||||
'Parse error' => '语法解析错误',
|
'Parse error' => '语法解析错误',
|
||||||
'Type error' => '类型错误',
|
'Type error' => '类型错误',
|
||||||
'Fatal error' => '致命错误',
|
'Fatal error' => '致命错误',
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
use think\Config;
|
use think\Config;
|
||||||
|
use think\Env;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\exception\HttpException;
|
use think\exception\HttpException;
|
||||||
use think\exception\HttpResponseException;
|
use think\exception\HttpResponseException;
|
||||||
@@ -371,7 +372,7 @@ class App
|
|||||||
self::$suffix = $config['class_suffix'];
|
self::$suffix = $config['class_suffix'];
|
||||||
|
|
||||||
// 应用调试模式
|
// 应用调试模式
|
||||||
self::$debug = Config::get('app_debug');
|
self::$debug = Env::get('app_debug', Config::get('app_debug'));
|
||||||
if (!self::$debug) {
|
if (!self::$debug) {
|
||||||
ini_set('display_errors', 'Off');
|
ini_set('display_errors', 'Off');
|
||||||
} elseif (!IS_CLI) {
|
} elseif (!IS_CLI) {
|
||||||
@@ -448,11 +449,6 @@ class App
|
|||||||
$config = Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
|
$config = Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载别名文件
|
|
||||||
if (is_file(CONF_PATH . $module . 'alias' . EXT)) {
|
|
||||||
Loader::addClassMap(include CONF_PATH . $module . 'alias' . EXT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载行为扩展文件
|
// 加载行为扩展文件
|
||||||
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
|
if (is_file(CONF_PATH . $module . 'tags' . EXT)) {
|
||||||
Hook::import(include CONF_PATH . $module . 'tags' . EXT);
|
Hook::import(include CONF_PATH . $module . 'tags' . EXT);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Cache
|
|||||||
{
|
{
|
||||||
$type = !empty($options['type']) ? $options['type'] : 'File';
|
$type = !empty($options['type']) ? $options['type'] : 'File';
|
||||||
if (false === $name) {
|
if (false === $name) {
|
||||||
$name = $type;
|
$name = md5(serialize($options));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true === $name || !isset(self::$instance[$name])) {
|
if (true === $name || !isset(self::$instance[$name])) {
|
||||||
|
|||||||
@@ -81,20 +81,10 @@ class Config
|
|||||||
$range = $range ?: self::$range;
|
$range = $range ?: self::$range;
|
||||||
|
|
||||||
if (!strpos($name, '.')) {
|
if (!strpos($name, '.')) {
|
||||||
// 判断环境变量
|
|
||||||
$result = getenv(ENV_PREFIX . strtoupper($name));
|
|
||||||
if (false !== $result) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
return isset(self::$config[$range][strtolower($name)]);
|
return isset(self::$config[$range][strtolower($name)]);
|
||||||
} else {
|
} else {
|
||||||
// 二维数组设置和获取支持
|
// 二维数组设置和获取支持
|
||||||
$name = explode('.', $name);
|
$name = explode('.', $name);
|
||||||
$result = getenv(ENV_PREFIX . strtoupper($name[0] . '_' . $name[1]));
|
|
||||||
// 判断环境变量
|
|
||||||
if (false !== $result) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
return isset(self::$config[$range][strtolower($name[0])][$name[1]]);
|
return isset(self::$config[$range][strtolower($name[0])][$name[1]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,20 +104,11 @@ class Config
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!strpos($name, '.')) {
|
if (!strpos($name, '.')) {
|
||||||
$result = getenv(ENV_PREFIX . strtoupper($name));
|
|
||||||
if (false !== $result) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
$name = strtolower($name);
|
$name = strtolower($name);
|
||||||
return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null;
|
return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null;
|
||||||
} else {
|
} else {
|
||||||
// 二维数组设置和获取支持
|
// 二维数组设置和获取支持
|
||||||
$name = explode('.', $name);
|
$name = explode('.', $name);
|
||||||
$result = getenv(ENV_PREFIX . strtoupper($name[0] . '_' . $name[1]));
|
|
||||||
// 判断环境变量
|
|
||||||
if (false !== $result) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
$name[0] = strtolower($name[0]);
|
$name[0] = strtolower($name[0]);
|
||||||
return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null;
|
return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null;
|
||||||
}
|
}
|
||||||
|
|||||||
31
core/library/think/Env.php
Normal file
31
core/library/think/Env.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 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;
|
||||||
|
|
||||||
|
class Env
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取环境变量值
|
||||||
|
* @param string $name 环境变量名(支持二级 .号分割)
|
||||||
|
* @param string $default 默认值
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function get($name, $default = null)
|
||||||
|
{
|
||||||
|
$result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name)));
|
||||||
|
if (false !== $result) {
|
||||||
|
return $result;
|
||||||
|
} else {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -238,6 +238,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (is_string($data)) {
|
if (is_string($data)) {
|
||||||
$this->data[$data] = $value;
|
$this->data[$data] = $value;
|
||||||
} else {
|
} else {
|
||||||
|
// 清空数据
|
||||||
|
$this->data = [];
|
||||||
if (is_object($data)) {
|
if (is_object($data)) {
|
||||||
$data = get_object_vars($data);
|
$data = get_object_vars($data);
|
||||||
}
|
}
|
||||||
|
|||||||
3
core/library/think/cache/driver/File.php
vendored
3
core/library/think/cache/driver/File.php
vendored
@@ -90,8 +90,7 @@ class File extends Driver
|
|||||||
*/
|
*/
|
||||||
public function has($name)
|
public function has($name)
|
||||||
{
|
{
|
||||||
$filename = $this->getCacheKey($name);
|
return $this->get($name) ? true : false;
|
||||||
return is_file($filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
3
core/library/think/cache/driver/Lite.php
vendored
3
core/library/think/cache/driver/Lite.php
vendored
@@ -61,8 +61,7 @@ class Lite extends Driver
|
|||||||
*/
|
*/
|
||||||
public function has($name)
|
public function has($name)
|
||||||
{
|
{
|
||||||
$filename = $this->getCacheKey($name);
|
return $this->get($name) ? true : false;
|
||||||
return is_file($filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Memcached extends Driver
|
|||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'username' => '', //账号
|
'username' => '', //账号
|
||||||
'password' => '', //密码
|
'password' => '', //密码
|
||||||
|
'option' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,6 +41,9 @@ class Memcached extends Driver
|
|||||||
$this->options = array_merge($this->options, $options);
|
$this->options = array_merge($this->options, $options);
|
||||||
}
|
}
|
||||||
$this->handler = new \Memcached;
|
$this->handler = new \Memcached;
|
||||||
|
if (!empty($this->options['option'])) {
|
||||||
|
$this->handler->setOptions($this->options['option']);
|
||||||
|
}
|
||||||
// 设置连接超时时间(单位:毫秒)
|
// 设置连接超时时间(单位:毫秒)
|
||||||
if ($this->options['timeout'] > 0) {
|
if ($this->options['timeout'] > 0) {
|
||||||
$this->handler->setOption(\Memcached::OPT_CONNECT_TIMEOUT, $this->options['timeout']);
|
$this->handler->setOption(\Memcached::OPT_CONNECT_TIMEOUT, $this->options['timeout']);
|
||||||
|
|||||||
@@ -908,9 +908,11 @@ class Query
|
|||||||
$where = $field;
|
$where = $field;
|
||||||
} elseif ($field) {
|
} elseif ($field) {
|
||||||
// 字符串查询
|
// 字符串查询
|
||||||
|
if (is_numeric($field)) {
|
||||||
$where[] = ['exp', $field];
|
$where[] = ['exp', $field];
|
||||||
} else {
|
} else {
|
||||||
$where = '';
|
$where[$field] = ['null', ''];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} elseif (is_array($op)) {
|
} elseif (is_array($op)) {
|
||||||
$where[$field] = $param;
|
$where[$field] = $param;
|
||||||
@@ -1227,7 +1229,7 @@ class Query
|
|||||||
/**
|
/**
|
||||||
* 设置查询数据不存在是否抛出异常
|
* 设置查询数据不存在是否抛出异常
|
||||||
* @access public
|
* @access public
|
||||||
* @param bool $fail 是否严格检查字段
|
* @param bool $fail 数据不存在是否抛出异常
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function failException($fail = true)
|
public function failException($fail = true)
|
||||||
@@ -1856,6 +1858,7 @@ class Query
|
|||||||
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
|
if (empty($options['fetch_sql']) && !empty($options['cache'])) {
|
||||||
// 判断查询缓存
|
// 判断查询缓存
|
||||||
$cache = $options['cache'];
|
$cache = $options['cache'];
|
||||||
|
unset($options['cache']);
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
||||||
$resultSet = Cache::get($key);
|
$resultSet = Cache::get($key);
|
||||||
}
|
}
|
||||||
@@ -1883,7 +1886,7 @@ class Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 返回结果处理
|
// 返回结果处理
|
||||||
if ($this->connection->getNumRows()) {
|
if (count($resultSet) > 0) {
|
||||||
// 数据列表读取后的处理
|
// 数据列表读取后的处理
|
||||||
if (!empty($this->model)) {
|
if (!empty($this->model)) {
|
||||||
// 生成模型对象
|
// 生成模型对象
|
||||||
|
|||||||
@@ -31,6 +31,22 @@ class Sqlsrv extends Builder
|
|||||||
*/
|
*/
|
||||||
protected function parseOrder($order)
|
protected function parseOrder($order)
|
||||||
{
|
{
|
||||||
|
if (is_array($order)) {
|
||||||
|
$array = [];
|
||||||
|
foreach ($order as $key => $val) {
|
||||||
|
if (is_numeric($key)) {
|
||||||
|
if (false === strpos($val, '(')) {
|
||||||
|
$array[] = $this->parseKey($val);
|
||||||
|
} elseif ('[rand]' == $val) {
|
||||||
|
$array[] = $this->parseRand();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
|
||||||
|
$array[] = $this->parseKey($key) . ' ' . $sort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$order = implode(',', $array);
|
||||||
|
}
|
||||||
return !empty($order) ? ' ORDER BY ' . $order : ' ORDER BY rand()';
|
return !empty($order) ? ' ORDER BY ' . $order : ' ORDER BY rand()';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Console
|
|||||||
}
|
}
|
||||||
// 获取基本信息
|
// 获取基本信息
|
||||||
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
|
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
|
||||||
$reqs = number_format(1 / $runtime, 2);
|
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
|
||||||
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
|
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_HOST'])) {
|
if (isset($_SERVER['HTTP_HOST'])) {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Html
|
|||||||
}
|
}
|
||||||
// 获取基本信息
|
// 获取基本信息
|
||||||
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
|
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
|
||||||
$reqs = number_format(1 / $runtime, 2);
|
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
|
||||||
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
|
$mem = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
|
||||||
|
|
||||||
// 页面Trace信息
|
// 页面Trace信息
|
||||||
|
|||||||
Reference in New Issue
Block a user