mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
修正Model类和Config类
This commit is contained in:
@@ -62,7 +62,7 @@ class Config
|
|||||||
APP_DEBUG && Log::record('[ CONFIG ] ' . $file, 'info');
|
APP_DEBUG && Log::record('[ CONFIG ] ' . $file, 'info');
|
||||||
$type = pathinfo($file, PATHINFO_EXTENSION);
|
$type = pathinfo($file, PATHINFO_EXTENSION);
|
||||||
if ('php' != $type) {
|
if ('php' != $type) {
|
||||||
return self::parse($config, $type, $name, $range);
|
return self::parse($file, $type, $name, $range);
|
||||||
} else {
|
} else {
|
||||||
return self::set(include $file, $name, $range);
|
return self::set(include $file, $name, $range);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,8 +90,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* 架构函数
|
* 架构函数
|
||||||
* @access public
|
* @access public
|
||||||
* @param array|object $data 数据
|
* @param array|object $data 数据
|
||||||
|
* @param bool $init 是否需要初始化
|
||||||
*/
|
*/
|
||||||
public function __construct($data = [])
|
public function __construct($data = [], $init = true)
|
||||||
{
|
{
|
||||||
if (is_object($data)) {
|
if (is_object($data)) {
|
||||||
$this->data = get_object_vars($data);
|
$this->data = get_object_vars($data);
|
||||||
@@ -101,11 +102,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (empty($this->name)) {
|
if (empty($this->name)) {
|
||||||
$this->name = basename(str_replace('\\', '/', get_class($this)));
|
$this->name = basename(str_replace('\\', '/', get_class($this)));
|
||||||
}
|
}
|
||||||
|
if ($init) {
|
||||||
// 获取字段类型信息并缓存
|
// 获取字段类型信息并缓存
|
||||||
$this->fieldType = self::db()->getTableInfo('', 'type');
|
$this->fieldType = self::db()->getTableInfo('', 'type');
|
||||||
$this->initialize();
|
$this->initialize();
|
||||||
$this->relation = new Relation($this);
|
$this->relation = new Relation($this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化模型
|
* 初始化模型
|
||||||
@@ -256,7 +259,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
// 数据对象赋值
|
// 数据对象赋值
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
$this->__set($key, $value, $data);
|
$this->__set($key, $value);
|
||||||
}
|
}
|
||||||
if (!empty($where)) {
|
if (!empty($where)) {
|
||||||
$this->isUpdate = true;
|
$this->isUpdate = true;
|
||||||
@@ -869,7 +872,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$model = get_called_class();
|
$model = get_called_class();
|
||||||
|
|
||||||
if (!isset(self::$links[$model])) {
|
if (!isset(self::$links[$model])) {
|
||||||
$class = new static;
|
$class = new static([], false);
|
||||||
self::$links[$model] = Db::connect($class->connection);
|
self::$links[$model] = Db::connect($class->connection);
|
||||||
self::$instance[$model] = $class;
|
self::$instance[$model] = $class;
|
||||||
} else {
|
} else {
|
||||||
@@ -914,10 +917,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string $name 名称
|
* @param string $name 名称
|
||||||
* @param mixed $value 值
|
* @param mixed $value 值
|
||||||
* @param array $data 数据信息
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __set($name, $value, $data = [])
|
public function __set($name, $value)
|
||||||
{
|
{
|
||||||
if (is_null($value) && in_array($name, $this->autoTimeField)) {
|
if (is_null($value) && in_array($name, $this->autoTimeField)) {
|
||||||
// 自动写入的时间戳字段
|
// 自动写入的时间戳字段
|
||||||
@@ -944,7 +946,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
// 检测修改器
|
// 检测修改器
|
||||||
$method = 'set' . Loader::parseName($name, 1) . 'Attr';
|
$method = 'set' . Loader::parseName($name, 1) . 'Attr';
|
||||||
if (method_exists($this, $method)) {
|
if (method_exists($this, $method)) {
|
||||||
$value = $this->$method($value, array_merge($data, $this->data));
|
$value = $this->$method($value, $this->data);
|
||||||
} elseif (isset($this->type[$name])) {
|
} elseif (isset($this->type[$name])) {
|
||||||
// 类型转换
|
// 类型转换
|
||||||
$type = $this->type[$name];
|
$type = $this->type[$name];
|
||||||
|
|||||||
Reference in New Issue
Block a user