取消vendor文件夹的排除

This commit is contained in:
win7 committed 2019-12-24 09:42:21 +08:00
1 parent 55d4d7b9c8
commit 1eafa8f5c9
1279 files changed
+277858 -1

No files matched your search

+250
View File
@@ -0,0 +1,250 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\model;
use think\Collection as BaseCollection;
use think\Model;
use think\Paginator;
/**
* 模型数据集类
*/
class Collection extends BaseCollection
{
/**
* 延迟预载入关联查询
* @access public
* @param array|string $relation 关联
* @param mixed $cache 关联缓存
* @return $this
*/
public function load($relation, $cache = false)
{
if (!$this->isEmpty()) {
$item = current($this->items);
$item->eagerlyResultSet($this->items, (array) $relation, [], false, $cache);
}
return $this;
}
/**
* 删除数据集的数据
* @access public
* @return bool
*/
public function delete(): bool
{
$this->each(function (Model $model) {
$model->delete();
});
return true;
}
/**
* 更新数据
* @access public
* @param array $data 数据数组
* @param array $allowField 允许字段
* @return bool
*/
public function update(array $data, array $allowField = []): bool
{
$this->each(function (Model $model) use ($data, $allowField) {
if (!empty($allowField)) {
$model->allowField($allowField);
}
$model->save($data);
});
return true;
}
/**
* 设置需要隐藏的输出属性
* @access public
* @param array $hidden 属性列表
* @return $this
*/
public function hidden(array $hidden)
{
$this->each(function (Model $model) use ($hidden) {
$model->hidden($hidden);
});
return $this;
}
/**
* 设置需要输出的属性
* @access public
* @param array $visible
* @return $this
*/
public function visible(array $visible)
{
$this->each(function (Model $model) use ($visible) {
$model->visible($visible);
});
return $this;
}
/**
* 设置需要追加的输出属性
* @access public
* @param array $append 属性列表
* @return $this
*/
public function append(array $append)
{
$this->each(function (Model $model) use ($append) {
$model->append($append);
});
return $this;
}
/**
* 设置父模型
* @access public
* @param Model $parent 父模型
* @return $this
*/
public function setParent(Model $parent)
{
$this->each(function (Model $model) use ($parent) {
$model->setParent($parent);
});
return $this;
}
/**
* 设置数据字段获取器
* @access public
* @param string|array $name 字段名
* @param callable $callback 闭包获取器
* @return $this
*/
public function withAttr($name, $callback = null)
{
$this->each(function (Model $model) use ($name, $callback) {
$model->withAttribute($name, $callback);
});
return $this;
}
/**
* 绑定(一对一)关联属性到当前模型
* @access protected
* @param string $relation 关联名称
* @param array $attrs 绑定属性
* @return $this
* @throws Exception
*/
public function bindAttr(string $relation, array $attrs = [])
{
$this->each(function (Model $model) use ($relation, $attrs) {
$model->bindAttr($relation, $attrs);
});
return $this;
}
/**
* 按指定键整理数据
*
* @access public
* @param mixed $items 数据
* @param string $indexKey 键名
* @return array
*/
public function dictionary($items = null, string &$indexKey = null)
{
if ($items instanceof self || $items instanceof Paginator) {
$items = $items->all();
}
$items = is_null($items) ? $this->items : $items;
if ($items && empty($indexKey)) {
$indexKey = $items[0]->getPk();
}
if (isset($indexKey) && is_string($indexKey)) {
return array_column($items, null, $indexKey);
}
return $items;
}
/**
* 比较数据集,返回差集
*
* @access public
* @param mixed $items 数据
* @param string $indexKey 指定比较的键名
* @return static
*/
public function diff($items, string $indexKey = null)
{
if ($this->isEmpty()) {
return new static($items);
}
$diff = [];
$dictionary = $this->dictionary($items, $indexKey);
if (is_string($indexKey)) {
foreach ($this->items as $item) {
if (!isset($dictionary[$item[$indexKey]])) {
$diff[] = $item;
}
}
}
return new static($diff);
}
/**
* 比较数据集,返回交集
*
* @access public
* @param mixed $items 数据
* @param string $indexKey 指定比较的键名
* @return static
*/
public function intersect($items, string $indexKey = null)
{
if ($this->isEmpty()) {
return new static([]);
}
$intersect = [];
$dictionary = $this->dictionary($items, $indexKey);
if (is_string($indexKey)) {
foreach ($this->items as $item) {
if (isset($dictionary[$item[$indexKey]])) {
$intersect[] = $item;
}
}
}
return new static($intersect);
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\model;
use think\Model;
/**
* 多对多中间表模型类
*/
class Pivot extends Model
{
/**
* 父模型
* @var Model
*/
public $parent;
/**
* 是否时间自动写入
* @var bool
*/
protected $autoWriteTimestamp = false;
/**
* 架构函数
* @access public
* @param array $data 数据
* @param Model $parent 上级模型
* @param string $table 中间数据表名
*/
public function __construct(array $data = [], Model $parent = null, string $table = '')
{
$this->parent = $parent;
if (is_null($this->name)) {
$this->name = $table;
}
parent::__construct($data);
}
}
+258
View File
@@ -0,0 +1,258 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace think\model;
use Closure;
use ReflectionFunction;
use think\db\BaseQuery as Query;
use think\db\exception\DbException as Exception;
use think\Model;
/**
* 模型关联基础类
* @package think\model
* @mixin Query
*/
abstract class Relation
{
/**
* 父模型对象
* @var Model
*/
protected $parent;
/**
* 当前关联的模型类名
* @var string
*/
protected $model;
/**
* 关联模型查询对象
* @var Query
*/
protected $query;
/**
* 关联表外键
* @var string
*/
protected $foreignKey;
/**
* 关联表主键
* @var string
*/
protected $localKey;
/**
* 是否执行关联基础查询
* @var bool
*/
protected $baseQuery;
/**
* 是否为自关联
* @var bool
*/
protected $selfRelation = false;
/**
* 关联数据数量限制
* @var int
*/
protected $withLimit;
/**
* 关联数据字段限制
* @var array
*/
protected $withField;
/**
* 获取关联的所属模型
* @access public
* @return Model
*/
public function getParent(): Model
{
return $this->parent;
}
/**
* 获取当前的关联模型类的Query实例
* @access public
* @return Query
*/
public function getQuery()
{
return $this->query;
}
/**
* 获取当前的关联模型类的实例
* @access public
* @return Model
*/
public function getModel(): Model
{
return $this->query->getModel();
}
/**
* 当前关联是否为自关联
* @access public
* @return bool
*/
public function isSelfRelation(): bool
{
return $this->selfRelation;
}
/**
* 封装关联数据集
* @access public
* @param array $resultSet 数据集
* @param Model $parent 父模型
* @return mixed
*/
protected function resultSetBuild(array $resultSet, Model $parent = null)
{
return (new $this->model)->toCollection($resultSet)->setParent($parent);
}
protected function getQueryFields(string $model)
{
$fields = $this->query->getOptions('field');
return $this->getRelationQueryFields($fields, $model);
}
protected function getRelationQueryFields($fields, string $model)
{
if (empty($fields) || '*' == $fields) {
return $model . '.*';
}
if (is_string($fields)) {
$fields = explode(',', $fields);
}
foreach ($fields as &$field) {
if (false === strpos($field, '.')) {
$field = $model . '.' . $field;
}
}
return $fields;
}
protected function getQueryWhere(array &$where, string $relation): void
{
foreach ($where as $key => &$val) {
if (is_string($key)) {
$where[] = [false === strpos($key, '.') ? $relation . '.' . $key : $key, '=', $val];
unset($where[$key]);
} elseif (isset($val[0]) && false === strpos($val[0], '.')) {
$val[0] = $relation . '.' . $val[0];
}
}
}
/**
* 更新数据
* @access public
* @param array $data 更新数据
* @return integer
*/
public function update(array $data = []): int
{
return $this->query->update($data);
}
/**
* 删除记录
* @access public
* @param mixed $data 表达式 true 表示强制删除
* @return int
* @throws Exception
* @throws PDOException
*/
public function delete($data = null): int
{
return $this->query->delete($data);
}
/**
* 限制关联数据的数量
* @access public
* @param int $limit 关联数量限制
* @return $this
*/
public function withLimit(int $limit)
{
$this->withLimit = $limit;
return $this;
}
/**
* 限制关联数据的字段
* @access public
* @param array $field 关联字段限制
* @return $this
*/
public function withField(array $field)
{
$this->withField = $field;
return $this;
}
/**
* 判断闭包的参数类型
* @access protected
* @return mixed
*/
protected function getClosureType(Closure $closure)
{
$reflect = new ReflectionFunction($closure);
$params = $reflect->getParameters();
if (!empty($params)) {
$type = $params[0]->getType();
return Relation::class == $type || is_null($type) ? $this : $this->query;
}
return $this;
}
/**
* 执行基础查询(仅执行一次)
* @access protected
* @return void
*/
protected function baseQuery(): void
{}
public function __call($method, $args)
{
if ($this->query) {
// 执行基础查询
$this->baseQuery();
$result = call_user_func_array([$this->query, $method], $args);
return $result === $this->query ? $this : $result;
}
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
}
}
Loaded 3 of 1279 files, more files were not shown because too many files have changed in this diff. Show more