mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
Merge branch 'master' of https://github.com/top-think/framework
This commit is contained in:
@@ -41,7 +41,7 @@ class Cache
|
||||
}
|
||||
|
||||
if (true === $name || !isset(self::$instance[$name])) {
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type);
|
||||
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ CACHE ] INIT ' . $type . ':' . var_export($options, true), 'info');
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
namespace think;
|
||||
|
||||
use think\App;
|
||||
|
||||
class Config
|
||||
{
|
||||
// 配置参数
|
||||
@@ -42,7 +40,7 @@ class Config
|
||||
if (empty($type)) {
|
||||
$type = pathinfo($config, PATHINFO_EXTENSION);
|
||||
}
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\config\\driver\\' . ucwords($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\config\\driver\\' . ucwords($type);
|
||||
self::set((new $class())->parse($config), $name, $range);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class Db
|
||||
if (empty($options['type'])) {
|
||||
throw new \InvalidArgumentException('Underfined db type');
|
||||
}
|
||||
$class = strpos($options['type'], '\\') ? $options['type'] : '\\think\\db\\connector\\' . ucwords($options['type']);
|
||||
$class = false !== strpos($options['type'], '\\') ? $options['type'] : '\\think\\db\\connector\\' . ucwords($options['type']);
|
||||
// 记录初始化信息
|
||||
App::$debug && Log::record('[ DB ] INIT ' . $options['type'] . ':' . var_export($options, true), 'info');
|
||||
if (true === $name) {
|
||||
|
||||
@@ -42,7 +42,7 @@ class Log
|
||||
public static function init($config = [])
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : 'File';
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
||||
self::$config = $config;
|
||||
unset($config['type']);
|
||||
self::$driver = new $class($config);
|
||||
@@ -57,7 +57,7 @@ class Log
|
||||
public static function alarm($config = [])
|
||||
{
|
||||
$type = isset($config['type']) ? $config['type'] : 'Email';
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\log\\alarm\\' . ucwords($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\alarm\\' . ucwords($type);
|
||||
unset($config['type']);
|
||||
self::$alarm = new $class($config['alarm']);
|
||||
// 记录初始化信息
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
namespace think;
|
||||
|
||||
use think\Hook;
|
||||
use think\Request;
|
||||
|
||||
class Response
|
||||
{
|
||||
@@ -77,7 +76,7 @@ class Response
|
||||
$type = empty($type) ? 'null' : strtolower($type);
|
||||
|
||||
if (!isset(self::$instance[$type])) {
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\response\\' . ucfirst($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\response\\' . ucfirst($type);
|
||||
if (class_exists($class)) {
|
||||
$response = new $class($data, $type, $options);
|
||||
} else {
|
||||
@@ -302,7 +301,7 @@ class Response
|
||||
{
|
||||
if (is_callable($this->transform)) {
|
||||
$data = call_user_func_array($this->transform, [$this->data]);
|
||||
}else{
|
||||
} else {
|
||||
$data = $this->data;
|
||||
}
|
||||
return $this->output($data);
|
||||
@@ -324,5 +323,5 @@ class Response
|
||||
public function getCode()
|
||||
{
|
||||
return isset($this->header['status']) ? $this->header['status'] : 200;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class Session
|
||||
}
|
||||
if (!empty($config['type'])) {
|
||||
// 读取session驱动
|
||||
$class = strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
|
||||
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\session\\driver\\' . ucwords($config['type']);
|
||||
|
||||
// 检查驱动类
|
||||
if (!class_exists($class) || !session_set_save_handler(new $class($config))) {
|
||||
|
||||
@@ -70,7 +70,7 @@ class Template
|
||||
|
||||
// 初始化模板编译存储器
|
||||
$type = $this->config['compile_type'] ? $this->config['compile_type'] : 'File';
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\template\\driver\\' . ucwords($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\template\\driver\\' . ucwords($type);
|
||||
$this->storage = new $class();
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class Url
|
||||
// 添加参数
|
||||
if (Config::get('url_common_param')) {
|
||||
$vars = urldecode(http_build_query($vars));
|
||||
$url .= $suffix . $anchor . '?' . $vars;
|
||||
$url .= $suffix . '?' . $vars . $anchor;
|
||||
} else {
|
||||
foreach ($vars as $var => $val) {
|
||||
if ('' !== trim($val)) {
|
||||
|
||||
@@ -83,7 +83,7 @@ class View
|
||||
$type = !empty($options['type']) ? $options['type'] : 'Think';
|
||||
}
|
||||
|
||||
$class = strpos($type, '\\') ? $type : '\\think\\view\\driver\\' . ucfirst($type);
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\view\\driver\\' . ucfirst($type);
|
||||
if (isset($options['type'])) {
|
||||
unset($options['type']);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ use think\Config;
|
||||
use think\Db;
|
||||
use think\db\Builder;
|
||||
use think\db\Connection;
|
||||
use think\db\exception\BindParamException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\db\exception\BindParamException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\Loader;
|
||||
use think\Model;
|
||||
use think\model\Relation;
|
||||
@@ -381,10 +381,10 @@ class Query
|
||||
$result = null;
|
||||
if (!empty($this->options['cache'])) {
|
||||
// 判断查询缓存
|
||||
$cache = $this->options['cache'];
|
||||
$cache = $this->options['cache'];
|
||||
if (empty($this->options['table'])) {
|
||||
$this->options['table'] = $this->getTable();
|
||||
}
|
||||
}
|
||||
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
||||
$result = Cache::get($key);
|
||||
}
|
||||
@@ -417,10 +417,10 @@ class Query
|
||||
$result = false;
|
||||
if (!empty($this->options['cache'])) {
|
||||
// 判断查询缓存
|
||||
$cache = $this->options['cache'];
|
||||
$cache = $this->options['cache'];
|
||||
if (empty($this->options['table'])) {
|
||||
$this->options['table'] = $this->getTable();
|
||||
}
|
||||
}
|
||||
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
||||
$result = Cache::get($guid);
|
||||
}
|
||||
@@ -962,7 +962,7 @@ class Query
|
||||
{
|
||||
$config = array_merge(Config::get('paginate'), $config);
|
||||
$listRows = $listRows ?: $config['list_rows'];
|
||||
$class = strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
|
||||
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
|
||||
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([
|
||||
$class,
|
||||
'getCurrentPage',
|
||||
@@ -1238,10 +1238,10 @@ class Query
|
||||
*/
|
||||
public function whereTime($field, $op, $range = null)
|
||||
{
|
||||
if(is_null($range)){
|
||||
if (is_null($range)) {
|
||||
// 使用日期表达式
|
||||
$date = getdate();
|
||||
switch(strtolower($op)){
|
||||
switch (strtolower($op)) {
|
||||
case 'today':
|
||||
case 'd':
|
||||
$range = 'today';
|
||||
@@ -1259,19 +1259,19 @@ class Query
|
||||
$range = mktime(0, 0, 0, 1, 1, $date['year']);
|
||||
break;
|
||||
case 'yesterday':
|
||||
$range = ['yesterday','today'];
|
||||
$range = ['yesterday', 'today'];
|
||||
break;
|
||||
case 'last week':
|
||||
$range = ['last week 00:00:00','this week 00:00:00'];
|
||||
$range = ['last week 00:00:00', 'this week 00:00:00'];
|
||||
break;
|
||||
case 'last month':
|
||||
$range = [date('y-m-01',strtotime('-1 month')),mktime(0, 0, 0, $date['mon'], 1, $date['year'])];
|
||||
$range = [date('y-m-01', strtotime('-1 month')), mktime(0, 0, 0, $date['mon'], 1, $date['year'])];
|
||||
break;
|
||||
case 'last year':
|
||||
$range = [mktime(0, 0, 0, 1, 1, $date['year']-1),mktime(0, 0, 0, 1, 1, $date['year'])];
|
||||
break;
|
||||
$range = [mktime(0, 0, 0, 1, 1, $date['year'] - 1), mktime(0, 0, 0, 1, 1, $date['year'])];
|
||||
break;
|
||||
}
|
||||
$op = is_array($range)? 'between' : '>';
|
||||
$op = is_array($range) ? 'between' : '>';
|
||||
}
|
||||
$this->where($field, strtolower($op) . ' time', $range);
|
||||
return $this;
|
||||
@@ -1325,7 +1325,7 @@ class Query
|
||||
} else {
|
||||
$pk = null;
|
||||
}
|
||||
$this->info[$guid] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk];
|
||||
$this->info[$guid] = ['fields' => $fields, 'type' => $type, 'bind' => $bind, 'pk' => $pk];
|
||||
}
|
||||
return $fetch ? $this->info[$guid][$fetch] : $this->info[$guid];
|
||||
}
|
||||
@@ -1449,9 +1449,9 @@ class Query
|
||||
$joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $joinName;
|
||||
$this->via($joinAlias);
|
||||
|
||||
if(Relation::HAS_ONE == $info['type']){
|
||||
if (Relation::HAS_ONE == $info['type']) {
|
||||
$this->join($joinTable . ' ' . $joinAlias, $alias . '.' . $info['localKey'] . '=' . $joinAlias . '.' . $info['foreignKey'], $info['joinType']);
|
||||
}else{
|
||||
} else {
|
||||
$this->join($joinTable . ' ' . $joinAlias, $alias . '.' . $info['foreignKey'] . '=' . $joinAlias . '.' . $info['localKey'], $info['joinType']);
|
||||
}
|
||||
|
||||
@@ -1576,10 +1576,10 @@ class Query
|
||||
// 分析查询表达式
|
||||
$options = $this->parseExpress();
|
||||
// 生成SQL语句
|
||||
$sql = $this->builder()->insert($data, $options, $replace);
|
||||
if($options['fetch_sql']){
|
||||
$sql = $this->builder()->insert($data, $options, $replace);
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql,$this->bind);
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
}
|
||||
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
||||
// 执行操作
|
||||
@@ -1614,10 +1614,10 @@ class Query
|
||||
}
|
||||
// 生成SQL语句
|
||||
$sql = $this->builder()->insertAll($dataSet, $options);
|
||||
if($options['fetch_sql']){
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql,$this->bind);
|
||||
}else{
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
} else {
|
||||
// 执行操作
|
||||
return $this->execute($sql, $this->getBind());
|
||||
}
|
||||
@@ -1636,12 +1636,12 @@ class Query
|
||||
// 分析查询表达式
|
||||
$options = $this->parseExpress();
|
||||
// 生成SQL语句
|
||||
$table = $this->parseSqlTable($table);
|
||||
$sql = $this->builder()->selectInsert($fields, $table, $options);
|
||||
if($options['fetch_sql']){
|
||||
$table = $this->parseSqlTable($table);
|
||||
$sql = $this->builder()->selectInsert($fields, $table, $options);
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql,$this->bind);
|
||||
}else{
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
} else {
|
||||
// 执行操作
|
||||
return $this->execute($sql, $this->getBind());
|
||||
}
|
||||
@@ -1685,12 +1685,12 @@ class Query
|
||||
}
|
||||
// 生成UPDATE SQL语句
|
||||
$sql = $this->builder()->update($data, $options);
|
||||
if($options['fetch_sql']){
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql,$this->bind);
|
||||
}else{
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
} else {
|
||||
// 执行操作
|
||||
return '' == $sql ? 0 : $this->execute($sql, $this->getBind());
|
||||
return '' == $sql ? 0 : $this->execute($sql, $this->getBind());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1732,10 +1732,10 @@ class Query
|
||||
if (!$resultSet) {
|
||||
// 生成查询SQL
|
||||
$sql = $this->builder()->select($options);
|
||||
if($options['fetch_sql']){
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
}
|
||||
}
|
||||
// 执行查询操作
|
||||
$resultSet = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']);
|
||||
|
||||
@@ -1772,9 +1772,9 @@ class Query
|
||||
}
|
||||
}
|
||||
} elseif (!empty($options['fail'])) {
|
||||
if(!empty($this->model)){
|
||||
throw new ModelNotFoundException('model data Not Found:' . $this->model , $this->model, $options);
|
||||
}else{
|
||||
if (!empty($this->model)) {
|
||||
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
|
||||
} else {
|
||||
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
|
||||
}
|
||||
}
|
||||
@@ -1817,10 +1817,10 @@ class Query
|
||||
if (!$result) {
|
||||
// 生成查询SQL
|
||||
$sql = $this->builder()->select($options);
|
||||
if($options['fetch_sql']){
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
}
|
||||
}
|
||||
// 执行查询
|
||||
$result = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']);
|
||||
|
||||
@@ -1853,9 +1853,9 @@ class Query
|
||||
}
|
||||
}
|
||||
} elseif (!empty($options['fail'])) {
|
||||
if(!empty($this->model)){
|
||||
throw new ModelNotFoundException('model data Not Found:' . $this->model , $this->model, $options);
|
||||
}else{
|
||||
if (!empty($this->model)) {
|
||||
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
|
||||
} else {
|
||||
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
|
||||
}
|
||||
} else {
|
||||
@@ -1873,7 +1873,7 @@ class Query
|
||||
* @throws Exception
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function selectOrFail($data=[])
|
||||
public function selectOrFail($data = [])
|
||||
{
|
||||
return $this->failException(true)->select($data);
|
||||
}
|
||||
@@ -1887,7 +1887,7 @@ class Query
|
||||
* @throws Exception
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function findOrFail($data=[])
|
||||
public function findOrFail($data = [])
|
||||
{
|
||||
return $this->failException(true)->find($data);
|
||||
}
|
||||
@@ -1971,10 +1971,10 @@ class Query
|
||||
}
|
||||
// 生成删除SQL语句
|
||||
$sql = $this->builder()->delete($options);
|
||||
if($options['fetch_sql']){
|
||||
if ($options['fetch_sql']) {
|
||||
// 获取实际执行的SQL语句
|
||||
return $this->connection->getRealSql($sql,$this->bind);
|
||||
}
|
||||
return $this->connection->getRealSql($sql, $this->bind);
|
||||
}
|
||||
// 执行操作
|
||||
return $this->execute($sql, $this->getBind());
|
||||
}
|
||||
|
||||
@@ -72,5 +72,8 @@ class urlTest extends \PHPUnit_Framework_TestCase
|
||||
Route::get('blog/:id', 'index/blog');
|
||||
Config::set('url_html_suffix', 'shtml');
|
||||
$this->assertEquals('/blog/10.shtml#detail', Url::build('/blog/10#detail'));
|
||||
|
||||
Config::set('url_common_param', true);
|
||||
$this->assertEquals('/blog/10.shtml?foo=bar#detail', Url::build('/blog/10#detail', "foo=bar"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user