提交 02f36421 编写于 作者: G gongfuxiang

类库更新

上级 921d28f9
...@@ -9,7 +9,7 @@ return array( ...@@ -9,7 +9,7 @@ return array(
'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'), 'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'),
'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'), 'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'),
'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'), 'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'),
'think\\' => array($vendorDir . '/topthink/framework/src/think', $vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/think-template/src'), 'think\\' => array($vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-template/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/framework/src/think'),
'app\\' => array($baseDir . '/app'), 'app\\' => array($baseDir . '/app'),
'ZipStream\\' => array($vendorDir . '/maennchen/zipstream-php/src'), 'ZipStream\\' => array($vendorDir . '/maennchen/zipstream-php/src'),
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'), 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
......
...@@ -81,10 +81,10 @@ class ComposerStaticInit1ed187777399b73a018d9a6af63a57d1 ...@@ -81,10 +81,10 @@ class ComposerStaticInit1ed187777399b73a018d9a6af63a57d1
), ),
'think\\' => 'think\\' =>
array ( array (
0 => __DIR__ . '/..' . '/topthink/framework/src/think', 0 => __DIR__ . '/..' . '/topthink/think-helper/src',
1 => __DIR__ . '/..' . '/topthink/think-helper/src', 1 => __DIR__ . '/..' . '/topthink/think-template/src',
2 => __DIR__ . '/..' . '/topthink/think-orm/src', 2 => __DIR__ . '/..' . '/topthink/think-orm/src',
3 => __DIR__ . '/..' . '/topthink/think-template/src', 3 => __DIR__ . '/..' . '/topthink/framework/src/think',
), ),
'app\\' => 'app\\' =>
array ( array (
......
...@@ -1441,17 +1441,17 @@ ...@@ -1441,17 +1441,17 @@
}, },
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v6.0.11", "version": "v6.0.12",
"version_normalized": "6.0.11.0", "version_normalized": "6.0.12.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/framework.git", "url": "https://github.com/top-think/framework.git",
"reference": "d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb" "reference": "e478316ac843c1a884a3b3a7a94db17c4001ff5c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb", "url": "https://api.github.com/repos/top-think/framework/zipball/e478316ac843c1a884a3b3a7a94db17c4001ff5c",
"reference": "d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb", "reference": "e478316ac843c1a884a3b3a7a94db17c4001ff5c",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
...@@ -1479,7 +1479,7 @@ ...@@ -1479,7 +1479,7 @@
"mockery/mockery": "^1.2", "mockery/mockery": "^1.2",
"phpunit/phpunit": "^7.0" "phpunit/phpunit": "^7.0"
}, },
"time": "2021-12-31T09:14:28+00:00", "time": "2022-01-21T06:31:07+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -1511,7 +1511,7 @@ ...@@ -1511,7 +1511,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/top-think/framework/issues", "issues": "https://github.com/top-think/framework/issues",
"source": "https://github.com/top-think/framework/tree/v6.0.11" "source": "https://github.com/top-think/framework/tree/v6.0.12"
}, },
"install-path": "../topthink/framework" "install-path": "../topthink/framework"
}, },
...@@ -1623,17 +1623,17 @@ ...@@ -1623,17 +1623,17 @@
}, },
{ {
"name": "topthink/think-orm", "name": "topthink/think-orm",
"version": "v2.0.50", "version": "v2.0.51",
"version_normalized": "2.0.50.0", "version_normalized": "2.0.51.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-orm.git", "url": "https://github.com/top-think/think-orm.git",
"reference": "091ad5e023c15fcce4ceaea2f3814bdf71045cde" "reference": "149d266acdc4b2f07c6a94f1733b6b97d340e0e2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/091ad5e023c15fcce4ceaea2f3814bdf71045cde", "url": "https://api.github.com/repos/top-think/think-orm/zipball/149d266acdc4b2f07c6a94f1733b6b97d340e0e2",
"reference": "091ad5e023c15fcce4ceaea2f3814bdf71045cde", "reference": "149d266acdc4b2f07c6a94f1733b6b97d340e0e2",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
...@@ -1653,7 +1653,7 @@ ...@@ -1653,7 +1653,7 @@
"require-dev": { "require-dev": {
"phpunit/phpunit": "^7|^8|^9.5" "phpunit/phpunit": "^7|^8|^9.5"
}, },
"time": "2022-01-06T02:48:16+00:00", "time": "2022-01-21T06:25:25+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -1681,7 +1681,7 @@ ...@@ -1681,7 +1681,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/top-think/think-orm/issues", "issues": "https://github.com/top-think/think-orm/issues",
"source": "https://github.com/top-think/think-orm/tree/v2.0.50" "source": "https://github.com/top-think/think-orm/tree/v2.0.51"
}, },
"install-path": "../topthink/think-orm" "install-path": "../topthink/think-orm"
}, },
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '5979814ba42ca1796f517662de1e19f6736a1182', 'reference' => '921d28f9ce7fcc47b9b8312f92080643eddfe75a',
'name' => 'shopxo/shopxo', 'name' => 'shopxo/shopxo',
'dev' => true, 'dev' => true,
), ),
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '5979814ba42ca1796f517662de1e19f6736a1182', 'reference' => '921d28f9ce7fcc47b9b8312f92080643eddfe75a',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'symfony/polyfill-mbstring' => array( 'symfony/polyfill-mbstring' => array(
...@@ -200,12 +200,12 @@ ...@@ -200,12 +200,12 @@
'dev_requirement' => true, 'dev_requirement' => true,
), ),
'topthink/framework' => array( 'topthink/framework' => array(
'pretty_version' => 'v6.0.11', 'pretty_version' => 'v6.0.12',
'version' => '6.0.11.0', 'version' => '6.0.12.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../topthink/framework', 'install_path' => __DIR__ . '/../topthink/framework',
'aliases' => array(), 'aliases' => array(),
'reference' => 'd9cadb6971ae92ff85ba5f2be77a40b0ad5718fb', 'reference' => 'e478316ac843c1a884a3b3a7a94db17c4001ff5c',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'topthink/think-helper' => array( 'topthink/think-helper' => array(
...@@ -227,12 +227,12 @@ ...@@ -227,12 +227,12 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'topthink/think-orm' => array( 'topthink/think-orm' => array(
'pretty_version' => 'v2.0.50', 'pretty_version' => 'v2.0.51',
'version' => '2.0.50.0', 'version' => '2.0.51.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-orm', 'install_path' => __DIR__ . '/../topthink/think-orm',
'aliases' => array(), 'aliases' => array(),
'reference' => '091ad5e023c15fcce4ceaea2f3814bdf71045cde', 'reference' => '149d266acdc4b2f07c6a94f1733b6b97d340e0e2',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'topthink/think-template' => array( 'topthink/think-template' => array(
......
<?php <?php
// This file is automatically generated at:2022-01-10 18:17:36 // This file is automatically generated at:2022-01-24 15:08:07
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',
......
...@@ -39,7 +39,7 @@ use think\initializer\RegisterService; ...@@ -39,7 +39,7 @@ use think\initializer\RegisterService;
*/ */
class App extends Container class App extends Container
{ {
const VERSION = '6.0.10LTS'; const VERSION = '6.0.12LTS';
/** /**
* 应用调试模式 * 应用调试模式
......
...@@ -188,7 +188,7 @@ class Env implements ArrayAccess ...@@ -188,7 +188,7 @@ class Env implements ArrayAccess
} }
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function offsetUnset($name) public function offsetUnset($name): void
{ {
throw new Exception('not support: unset'); throw new Exception('not support: unset');
} }
......
...@@ -249,7 +249,7 @@ abstract class Driver implements CacheInterface, CacheHandlerInterface ...@@ -249,7 +249,7 @@ abstract class Driver implements CacheInterface, CacheHandlerInterface
* @param string $data 缓存数据 * @param string $data 缓存数据
* @return mixed * @return mixed
*/ */
protected function unserialize(string $data) protected function unserialize($data)
{ {
if (is_numeric($data)) { if (is_numeric($data)) {
return $data; return $data;
......
...@@ -18,7 +18,7 @@ namespace think\console\input; ...@@ -18,7 +18,7 @@ namespace think\console\input;
class Option class Option
{ {
// 无需传值 // 无需传值
const VALUE_NONE = 1; const VALUE_NONE = 1;
// 必须传值 // 必须传值
const VALUE_REQUIRED = 2; const VALUE_REQUIRED = 2;
// 可选传值 // 可选传值
...@@ -30,13 +30,13 @@ class Option ...@@ -30,13 +30,13 @@ class Option
* 选项名 * 选项名
* @var string * @var string
*/ */
private $name; private $name = '';
/** /**
* 选项短名称 * 选项短名称
* @var string * @var string
*/ */
private $shortcut; private $shortcut = '';
/** /**
* 选项类型 * 选项类型
...@@ -54,7 +54,7 @@ class Option ...@@ -54,7 +54,7 @@ class Option
* 选项描述 * 选项描述
* @var string * @var string
*/ */
private $description; private $description = '';
/** /**
* 构造方法 * 构造方法
...@@ -76,10 +76,10 @@ class Option ...@@ -76,10 +76,10 @@ class Option
} }
if (empty($shortcut)) { if (empty($shortcut)) {
$shortcut = null; $shortcut = '';
} }
if (null !== $shortcut) { if ('' !== $shortcut) {
if (is_array($shortcut)) { if (is_array($shortcut)) {
$shortcut = implode('|', $shortcut); $shortcut = implode('|', $shortcut);
} }
...@@ -114,7 +114,7 @@ class Option ...@@ -114,7 +114,7 @@ class Option
* 获取短名称 * 获取短名称
* @return string * @return string
*/ */
public function getShortcut() public function getShortcut(): string
{ {
return $this->shortcut; return $this->shortcut;
} }
...@@ -123,7 +123,7 @@ class Option ...@@ -123,7 +123,7 @@ class Option
* 获取选项名 * 获取选项名
* @return string * @return string
*/ */
public function getName() public function getName(): string
{ {
return $this->name; return $this->name;
} }
...@@ -132,7 +132,7 @@ class Option ...@@ -132,7 +132,7 @@ class Option
* 是否可以设置值 * 是否可以设置值
* @return bool 类型不是 self::VALUE_NONE 的时候返回true,其他均返回false * @return bool 类型不是 self::VALUE_NONE 的时候返回true,其他均返回false
*/ */
public function acceptValue() public function acceptValue(): bool
{ {
return $this->isValueRequired() || $this->isValueOptional(); return $this->isValueRequired() || $this->isValueOptional();
} }
...@@ -141,7 +141,7 @@ class Option ...@@ -141,7 +141,7 @@ class Option
* 是否必须 * 是否必须
* @return bool 类型是 self::VALUE_REQUIRED 的时候返回true,其他均返回false * @return bool 类型是 self::VALUE_REQUIRED 的时候返回true,其他均返回false
*/ */
public function isValueRequired() public function isValueRequired(): bool
{ {
return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode); return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
} }
...@@ -150,7 +150,7 @@ class Option ...@@ -150,7 +150,7 @@ class Option
* 是否可选 * 是否可选
* @return bool 类型是 self::VALUE_OPTIONAL 的时候返回true,其他均返回false * @return bool 类型是 self::VALUE_OPTIONAL 的时候返回true,其他均返回false
*/ */
public function isValueOptional() public function isValueOptional(): bool
{ {
return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode); return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
} }
...@@ -159,7 +159,7 @@ class Option ...@@ -159,7 +159,7 @@ class Option
* 选项值是否接受数组 * 选项值是否接受数组
* @return bool 类型是 self::VALUE_IS_ARRAY 的时候返回true,其他均返回false * @return bool 类型是 self::VALUE_IS_ARRAY 的时候返回true,其他均返回false
*/ */
public function isArray() public function isArray(): bool
{ {
return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode); return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
} }
...@@ -199,7 +199,7 @@ class Option ...@@ -199,7 +199,7 @@ class Option
* 获取描述文字 * 获取描述文字
* @return string * @return string
*/ */
public function getDescription() public function getDescription(): string
{ {
return $this->description; return $this->description;
} }
...@@ -209,7 +209,7 @@ class Option ...@@ -209,7 +209,7 @@ class Option
* @param Option $option * @param Option $option
* @return bool * @return bool
*/ */
public function equals(Option $option) public function equals(Option $option): bool
{ {
return $option->getName() === $this->getName() return $option->getName() === $this->getName()
&& $option->getShortcut() === $this->getShortcut() && $option->getShortcut() === $this->getShortcut()
......
...@@ -213,7 +213,7 @@ class Resource extends RuleGroup ...@@ -213,7 +213,7 @@ class Resource extends RuleGroup
} }
/** /**
* 绑定资源模型 * 绑定资源中间件
* @access public * @access public
* @param array|string $name 资源类型或者中间件定义 * @param array|string $name 资源类型或者中间件定义
* @param array|string $middleware 中间件定义 * @param array|string $middleware 中间件定义
......
...@@ -532,6 +532,17 @@ abstract class Rule ...@@ -532,6 +532,17 @@ abstract class Rule
return $this->setOption('view', $view); return $this->setOption('view', $view);
} }
/**
* 通过闭包检查路由是否匹配
* @access public
* @param callable $match 闭包
* @return $this
*/
public function match(callable $match)
{
return $this->setOption('match', $match);
}
/** /**
* 设置路由完整匹配 * 设置路由完整匹配
* @access public * @access public
...@@ -694,6 +705,13 @@ abstract class Rule ...@@ -694,6 +705,13 @@ abstract class Rule
*/ */
protected function checkOption(array $option, Request $request): bool protected function checkOption(array $option, Request $request): bool
{ {
// 检查当前路由是否匹配
if (isset($option['match']) && is_callable($option['match'])) {
if (false === $option['match']($this, $request)) {
return false;
}
}
// 请求类型检测 // 请求类型检测
if (!empty($option['method'])) { if (!empty($option['method'])) {
if (is_string($option['method']) && false === stripos($option['method'], $request->method())) { if (is_string($option['method']) && false === stripos($option['method'], $request->method())) {
......
...@@ -196,7 +196,7 @@ class RuleItem extends Rule ...@@ -196,7 +196,7 @@ class RuleItem extends Rule
$url = $this->urlSuffixCheck($request, $url, $option); $url = $this->urlSuffixCheck($request, $url, $option);
if (is_null($match)) { if (is_null($match)) {
$match = $this->match($url, $option, $pattern, $completeMatch); $match = $this->checkMatch($url, $option, $pattern, $completeMatch);
} }
if (false !== $match) { if (false !== $match) {
...@@ -252,7 +252,7 @@ class RuleItem extends Rule ...@@ -252,7 +252,7 @@ class RuleItem extends Rule
* @param bool $completeMatch 是否完全匹配 * @param bool $completeMatch 是否完全匹配
* @return array|false * @return array|false
*/ */
private function match(string $url, array $option, array $pattern, bool $completeMatch) private function checkMatch(string $url, array $option, array $pattern, bool $completeMatch)
{ {
if (isset($option['complete_match'])) { if (isset($option['complete_match'])) {
$completeMatch = $option['complete_match']; $completeMatch = $option['complete_match'];
......
...@@ -421,10 +421,8 @@ class Fetch ...@@ -421,10 +421,8 @@ class Fetch
if (!empty($options['group'])) { if (!empty($options['group'])) {
// 支持GROUP // 支持GROUP
$bind = $this->query->getBind(); $subSql = $this->query->field('count(' . $field . ') AS think_count')->buildSql();
$subSql = $this->query->options($options)->field('count(' . $field . ') AS think_count')->bind($bind)->buildSql(); $query = $this->query->newQuery()->table([$subSql => '_group_count_']);
$query = $this->query->newQuery()->table([$subSql => '_group_count_']);
return $query->fetchsql()->aggregate('COUNT', '*'); return $query->fetchsql()->aggregate('COUNT', '*');
} else { } else {
......
...@@ -24,8 +24,8 @@ class Sqlite extends Builder ...@@ -24,8 +24,8 @@ class Sqlite extends Builder
/** /**
* limit * limit
* @access public * @access public
* @param Query $query 查询对象 * @param Query $query 查询对象
* @param mixed $limit * @param mixed $limit
* @return string * @return string
*/ */
public function parseLimit(Query $query, string $limit): string public function parseLimit(Query $query, string $limit): string
...@@ -47,7 +47,7 @@ class Sqlite extends Builder ...@@ -47,7 +47,7 @@ class Sqlite extends Builder
/** /**
* 随机排序 * 随机排序
* @access protected * @access protected
* @param Query $query 查询对象 * @param Query $query 查询对象
* @return string * @return string
*/ */
protected function parseRand(Query $query): string protected function parseRand(Query $query): string
...@@ -58,9 +58,9 @@ class Sqlite extends Builder ...@@ -58,9 +58,9 @@ class Sqlite extends Builder
/** /**
* 字段和表名处理 * 字段和表名处理
* @access public * @access public
* @param Query $query 查询对象 * @param Query $query 查询对象
* @param mixed $key 字段名 * @param mixed $key 字段名
* @param bool $strict 严格检测 * @param bool $strict 严格检测
* @return string * @return string
*/ */
public function parseKey(Query $query, $key, bool $strict = false): string public function parseKey(Query $query, $key, bool $strict = false): string
...@@ -73,7 +73,7 @@ class Sqlite extends Builder ...@@ -73,7 +73,7 @@ class Sqlite extends Builder
$key = trim($key); $key = trim($key);
if (strpos($key, '.')) { if (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
[$table, $key] = explode('.', $key, 2); [$table, $key] = explode('.', $key, 2);
$alias = $query->getOptions('alias'); $alias = $query->getOptions('alias');
...@@ -88,8 +88,12 @@ class Sqlite extends Builder ...@@ -88,8 +88,12 @@ class Sqlite extends Builder
} }
} }
if ('*' != $key && !preg_match('/[,\'\"\*\(\)`.\s]/', $key)) {
$key = '`' . $key . '`';
}
if (isset($table)) { if (isset($table)) {
$key = $table . '.' . $key; $key = '`' . $table . '`.' . $key;
} }
return $key; return $key;
...@@ -98,8 +102,8 @@ class Sqlite extends Builder ...@@ -98,8 +102,8 @@ class Sqlite extends Builder
/** /**
* 设置锁机制 * 设置锁机制
* @access protected * @access protected
* @param Query $query 查询对象 * @param Query $query 查询对象
* @param bool|string $lock * @param bool|string $lock
* @return string * @return string
*/ */
protected function parseLock(Query $query, $lock = false): string protected function parseLock(Query $query, $lock = false): string
......
...@@ -42,7 +42,7 @@ class Sqlite extends PDOConnection ...@@ -42,7 +42,7 @@ class Sqlite extends PDOConnection
public function getFields(string $tableName): array public function getFields(string $tableName): array
{ {
[$tableName] = explode(' ', $tableName); [$tableName] = explode(' ', $tableName);
$sql = 'PRAGMA table_info( ' . $tableName . ' )'; $sql = 'PRAGMA table_info( \'' . $tableName . '\' )';
$pdo = $this->getPDOStatement($sql); $pdo = $this->getPDOStatement($sql);
$result = $pdo->fetchAll(PDO::FETCH_ASSOC); $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
......
...@@ -382,6 +382,9 @@ trait Attribute ...@@ -382,6 +382,9 @@ trait Attribute
} elseif (isset($this->type[$name])) { } elseif (isset($this->type[$name])) {
// 类型转换 // 类型转换
$value = $this->writeTransform($value, $this->type[$name]); $value = $this->writeTransform($value, $this->type[$name]);
} elseif (is_object($value) && method_exists($value, '__toString')) {
// 对象类型
$value = $value->__toString();
} }
// 设置数据对象属性 // 设置数据对象属性
......
...@@ -236,12 +236,11 @@ class BelongsTo extends OneToOne ...@@ -236,12 +236,11 @@ class BelongsTo extends OneToOne
$relationModel->exists(true); $relationModel->exists(true);
} }
// 设置关联属性
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) { if (!empty($this->bindAttr)) {
// 绑定关联属性 // 绑定关联属性
$this->bindAttr($result, $relationModel); $this->bindAttr($result, $relationModel);
} else {
// 设置关联属性
$result->setRelation($relation, $relationModel);
} }
} }
} }
...@@ -277,12 +276,12 @@ class BelongsTo extends OneToOne ...@@ -277,12 +276,12 @@ class BelongsTo extends OneToOne
$relationModel->exists(true); $relationModel->exists(true);
} }
// 设置关联属性
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) { if (!empty($this->bindAttr)) {
// 绑定关联属性 // 绑定关联属性
$this->bindAttr($result, $relationModel); $this->bindAttr($result, $relationModel);
} else {
// 设置关联属性
$result->setRelation($relation, $relationModel);
} }
} }
......
...@@ -137,6 +137,30 @@ class BelongsToMany extends Relation ...@@ -137,6 +137,30 @@ class BelongsToMany extends Relation
->setParent(clone $this->parent); ->setParent(clone $this->parent);
} }
/**
* 组装Pivot模型
* @access public
* @param Model $result 模型对象
* @return array
*/
protected function matchPivot(Model $result): array
{
$pivot = [];
foreach ($result->getData() as $key => $val) {
if (strpos($key, '__')) {
[$name, $attr] = explode('__', $key, 2);
if ('pivot' == $name) {
$pivot[$attr] = $val;
unset($result->$key);
}
}
}
$result->setRelation($this->pivotDataName, $this->newPivot($pivot));
return $pivot;
}
/** /**
* 根据关联条件查询当前模型 * 根据关联条件查询当前模型
* @access public * @access public
...@@ -326,24 +350,13 @@ class BelongsToMany extends Relation ...@@ -326,24 +350,13 @@ class BelongsToMany extends Relation
// 组装模型数据 // 组装模型数据
$data = []; $data = [];
foreach ($list as $set) { foreach ($list as $set) {
$pivot = []; $pivot = $this->matchPivot($set);
foreach ($set->getData() as $key => $val) { $key = $pivot[$this->localKey];
if (strpos($key, '__')) {
[$name, $attr] = explode('__', $key, 2);
if ('pivot' == $name) {
$pivot[$attr] = $val;
unset($set->$key);
}
}
}
$key = $pivot[$this->localKey];
if ($this->withLimit && isset($data[$key]) && count($data[$key]) >= $this->withLimit) { if ($this->withLimit && isset($data[$key]) && count($data[$key]) >= $this->withLimit) {
continue; continue;
} }
$set->setRelation($this->pivotDataName, $this->newPivot($pivot));
$data[$key][] = $set; $data[$key][] = $set;
} }
...@@ -594,21 +607,8 @@ class BelongsToMany extends Relation ...@@ -594,21 +607,8 @@ class BelongsToMany extends Relation
$foreignKey = $this->foreignKey; $foreignKey = $this->foreignKey;
$localKey = $this->localKey; $localKey = $this->localKey;
$this->query->getModel()->filter(function ($result, $options) { $this->query->filter(function ($result, $options) {
$pivot = []; $this->matchPivot($result);
foreach ($result->getData() as $key => $val) {
if (strpos($key, '__')) {
[$name, $attr] = explode('__', $key, 2);
if ('pivot' == $name) {
$pivot[$attr] = $val;
unset($result->$key);
}
}
}
$result->setRelation($this->pivotDataName, $this->newPivot($pivot));
}); });
// 关联查询 // 关联查询
......
...@@ -258,8 +258,14 @@ class HasManyThrough extends Relation ...@@ -258,8 +258,14 @@ class HasManyThrough extends Relation
$closure($this->getClosureType($closure)); $closure($this->getClosureType($closure));
} }
$throughKey = $this->throughKey;
if ($this->baseQuery) {
$throughKey = Str::snake(class_basename($this->model)) . "." . $this->throughKey;
}
$list = $this->query $list = $this->query
->where($this->throughKey, 'in', $keys) ->where($throughKey, 'in', $keys)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null) ->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->select(); ->select();
......
...@@ -234,13 +234,12 @@ class HasOne extends OneToOne ...@@ -234,13 +234,12 @@ class HasOne extends OneToOne
$relationModel->setParent(clone $result); $relationModel->setParent(clone $result);
$relationModel->exists(true); $relationModel->exists(true);
} }
// 设置关联属性
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) { if (!empty($this->bindAttr)) {
// 绑定关联属性 // 绑定关联属性
$this->bindAttr($result, $relationModel); $this->bindAttr($result, $relationModel);
} else {
// 设置关联属性
$result->setRelation($relation, $relationModel);
} }
} }
} }
...@@ -276,11 +275,12 @@ class HasOne extends OneToOne ...@@ -276,11 +275,12 @@ class HasOne extends OneToOne
$relationModel->exists(true); $relationModel->exists(true);
} }
// 设置关联属性
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) { if (!empty($this->bindAttr)) {
// 绑定关联属性 // 绑定关联属性
$this->bindAttr($result, $relationModel); $this->bindAttr($result, $relationModel);
} else {
$result->setRelation($relation, $relationModel);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册