vr-shopxo-source/thinkphp/library/think/Model.php

1073 lines
25 KiB
PHP
Raw Normal View History

2019-11-11 12:57:06 +00:00
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think;
use InvalidArgumentException;
use think\db\Query;
/**
* Class Model
* @package think
* @mixin Query
* @method \think\Model withAttr(array $name,\Closure $closure) 动态定义获取器
*/
abstract class Model implements \JsonSerializable, \ArrayAccess
{
use model\concern\Attribute;
use model\concern\RelationShip;
use model\concern\ModelEvent;
use model\concern\TimeStamp;
use model\concern\Conversion;
/**
* 是否存在数据
* @var bool
*/
private $exists = false;
/**
* 是否Replace
* @var bool
*/
private $replace = false;
/**
* 是否强制更新所有数据
* @var bool
*/
private $force = false;
/**
* 更新条件
* @var array
*/
private $updateWhere;
/**
* 数据库配置信息
* @var array|string
*/
protected $connection = [];
/**
* 数据库查询对象类名
* @var string
*/
protected $query;
/**
* 模型名称
* @var string
*/
protected $name;
/**
* 数据表名称
* @var string
*/
protected $table;
/**
* 写入自动完成定义
* @var array
*/
protected $auto = [];
/**
* 新增自动完成定义
* @var array
*/
protected $insert = [];
/**
* 更新自动完成定义
* @var array
*/
protected $update = [];
/**
* 初始化过的模型.
* @var array
*/
protected static $initialized = [];
/**
* 是否从主库读取(主从分布式有效)
* @var array
*/
protected static $readMaster;
/**
* 查询对象实例
* @var Query
*/
protected $queryInstance;
/**
* 错误信息
* @var mixed
*/
protected $error;
/**
* 软删除字段默认值
* @var mixed
*/
protected $defaultSoftDelete;
/**
* 全局查询范围
* @var array
*/
protected $globalScope = [];
/**
* 架构函数
* @access public
* @param array|object $data 数据
*/
public function __construct($data = [])
{
if (is_object($data)) {
$this->data = get_object_vars($data);
} else {
$this->data = $data;
}
if ($this->disuse) {
// 废弃字段
foreach ((array) $this->disuse as $key) {